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 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 85 | static int intel_set_mode(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 86 | struct drm_atomic_state *state); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 87 | static int intel_framebuffer_init(struct drm_device *dev, |
| 88 | struct intel_framebuffer *ifb, |
| 89 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 90 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 91 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 92 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 93 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 94 | struct intel_link_m_n *m_n, |
| 95 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 96 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 97 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
| 98 | static void intel_set_pipe_csc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 99 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 100 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 101 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 102 | const struct intel_crtc_state *pipe_config); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 103 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
| 104 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 105 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 106 | struct intel_crtc_state *crtc_state); |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 107 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 108 | int num_connectors); |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 109 | static void intel_crtc_enable_planes(struct drm_crtc *crtc); |
| 110 | static void intel_crtc_disable_planes(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 111 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 112 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
| 113 | { |
| 114 | if (!connector->mst_port) |
| 115 | return connector->encoder; |
| 116 | else |
| 117 | return &connector->mst_port->mst_encoders[pipe]->base; |
| 118 | } |
| 119 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 120 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 121 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 122 | } intel_range_t; |
| 123 | |
| 124 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 125 | int dot_limit; |
| 126 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 127 | } intel_p2_t; |
| 128 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 129 | typedef struct intel_limit intel_limit_t; |
| 130 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 131 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 132 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 133 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 134 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 135 | int |
| 136 | intel_pch_rawclk(struct drm_device *dev) |
| 137 | { |
| 138 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 139 | |
| 140 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 141 | |
| 142 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 143 | } |
| 144 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 145 | static inline u32 /* units of 100MHz */ |
| 146 | intel_fdi_link_freq(struct drm_device *dev) |
| 147 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 148 | if (IS_GEN5(dev)) { |
| 149 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 150 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 151 | } else |
| 152 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 155 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 156 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 157 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 158 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 159 | .m = { .min = 96, .max = 140 }, |
| 160 | .m1 = { .min = 18, .max = 26 }, |
| 161 | .m2 = { .min = 6, .max = 16 }, |
| 162 | .p = { .min = 4, .max = 128 }, |
| 163 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 164 | .p2 = { .dot_limit = 165000, |
| 165 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 168 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 169 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 170 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 171 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 172 | .m = { .min = 96, .max = 140 }, |
| 173 | .m1 = { .min = 18, .max = 26 }, |
| 174 | .m2 = { .min = 6, .max = 16 }, |
| 175 | .p = { .min = 4, .max = 128 }, |
| 176 | .p1 = { .min = 2, .max = 33 }, |
| 177 | .p2 = { .dot_limit = 165000, |
| 178 | .p2_slow = 4, .p2_fast = 4 }, |
| 179 | }; |
| 180 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 181 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 182 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 183 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 184 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 185 | .m = { .min = 96, .max = 140 }, |
| 186 | .m1 = { .min = 18, .max = 26 }, |
| 187 | .m2 = { .min = 6, .max = 16 }, |
| 188 | .p = { .min = 4, .max = 128 }, |
| 189 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 190 | .p2 = { .dot_limit = 165000, |
| 191 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 192 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 193 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 194 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 195 | .dot = { .min = 20000, .max = 400000 }, |
| 196 | .vco = { .min = 1400000, .max = 2800000 }, |
| 197 | .n = { .min = 1, .max = 6 }, |
| 198 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 199 | .m1 = { .min = 8, .max = 18 }, |
| 200 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 201 | .p = { .min = 5, .max = 80 }, |
| 202 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 203 | .p2 = { .dot_limit = 200000, |
| 204 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 208 | .dot = { .min = 20000, .max = 400000 }, |
| 209 | .vco = { .min = 1400000, .max = 2800000 }, |
| 210 | .n = { .min = 1, .max = 6 }, |
| 211 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 212 | .m1 = { .min = 8, .max = 18 }, |
| 213 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 214 | .p = { .min = 7, .max = 98 }, |
| 215 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 216 | .p2 = { .dot_limit = 112000, |
| 217 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 220 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 221 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 222 | .dot = { .min = 25000, .max = 270000 }, |
| 223 | .vco = { .min = 1750000, .max = 3500000}, |
| 224 | .n = { .min = 1, .max = 4 }, |
| 225 | .m = { .min = 104, .max = 138 }, |
| 226 | .m1 = { .min = 17, .max = 23 }, |
| 227 | .m2 = { .min = 5, .max = 11 }, |
| 228 | .p = { .min = 10, .max = 30 }, |
| 229 | .p1 = { .min = 1, .max = 3}, |
| 230 | .p2 = { .dot_limit = 270000, |
| 231 | .p2_slow = 10, |
| 232 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 233 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 237 | .dot = { .min = 22000, .max = 400000 }, |
| 238 | .vco = { .min = 1750000, .max = 3500000}, |
| 239 | .n = { .min = 1, .max = 4 }, |
| 240 | .m = { .min = 104, .max = 138 }, |
| 241 | .m1 = { .min = 16, .max = 23 }, |
| 242 | .m2 = { .min = 5, .max = 11 }, |
| 243 | .p = { .min = 5, .max = 80 }, |
| 244 | .p1 = { .min = 1, .max = 8}, |
| 245 | .p2 = { .dot_limit = 165000, |
| 246 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 250 | .dot = { .min = 20000, .max = 115000 }, |
| 251 | .vco = { .min = 1750000, .max = 3500000 }, |
| 252 | .n = { .min = 1, .max = 3 }, |
| 253 | .m = { .min = 104, .max = 138 }, |
| 254 | .m1 = { .min = 17, .max = 23 }, |
| 255 | .m2 = { .min = 5, .max = 11 }, |
| 256 | .p = { .min = 28, .max = 112 }, |
| 257 | .p1 = { .min = 2, .max = 8 }, |
| 258 | .p2 = { .dot_limit = 0, |
| 259 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 260 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 264 | .dot = { .min = 80000, .max = 224000 }, |
| 265 | .vco = { .min = 1750000, .max = 3500000 }, |
| 266 | .n = { .min = 1, .max = 3 }, |
| 267 | .m = { .min = 104, .max = 138 }, |
| 268 | .m1 = { .min = 17, .max = 23 }, |
| 269 | .m2 = { .min = 5, .max = 11 }, |
| 270 | .p = { .min = 14, .max = 42 }, |
| 271 | .p1 = { .min = 2, .max = 6 }, |
| 272 | .p2 = { .dot_limit = 0, |
| 273 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 274 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 277 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 278 | .dot = { .min = 20000, .max = 400000}, |
| 279 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 280 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 281 | .n = { .min = 3, .max = 6 }, |
| 282 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 283 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 284 | .m1 = { .min = 0, .max = 0 }, |
| 285 | .m2 = { .min = 0, .max = 254 }, |
| 286 | .p = { .min = 5, .max = 80 }, |
| 287 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 288 | .p2 = { .dot_limit = 200000, |
| 289 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 290 | }; |
| 291 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 292 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 293 | .dot = { .min = 20000, .max = 400000 }, |
| 294 | .vco = { .min = 1700000, .max = 3500000 }, |
| 295 | .n = { .min = 3, .max = 6 }, |
| 296 | .m = { .min = 2, .max = 256 }, |
| 297 | .m1 = { .min = 0, .max = 0 }, |
| 298 | .m2 = { .min = 0, .max = 254 }, |
| 299 | .p = { .min = 7, .max = 112 }, |
| 300 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 301 | .p2 = { .dot_limit = 112000, |
| 302 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 303 | }; |
| 304 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 305 | /* Ironlake / Sandybridge |
| 306 | * |
| 307 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 308 | * the range value for them is (actual_value - 2). |
| 309 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 310 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 311 | .dot = { .min = 25000, .max = 350000 }, |
| 312 | .vco = { .min = 1760000, .max = 3510000 }, |
| 313 | .n = { .min = 1, .max = 5 }, |
| 314 | .m = { .min = 79, .max = 127 }, |
| 315 | .m1 = { .min = 12, .max = 22 }, |
| 316 | .m2 = { .min = 5, .max = 9 }, |
| 317 | .p = { .min = 5, .max = 80 }, |
| 318 | .p1 = { .min = 1, .max = 8 }, |
| 319 | .p2 = { .dot_limit = 225000, |
| 320 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 323 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 324 | .dot = { .min = 25000, .max = 350000 }, |
| 325 | .vco = { .min = 1760000, .max = 3510000 }, |
| 326 | .n = { .min = 1, .max = 3 }, |
| 327 | .m = { .min = 79, .max = 118 }, |
| 328 | .m1 = { .min = 12, .max = 22 }, |
| 329 | .m2 = { .min = 5, .max = 9 }, |
| 330 | .p = { .min = 28, .max = 112 }, |
| 331 | .p1 = { .min = 2, .max = 8 }, |
| 332 | .p2 = { .dot_limit = 225000, |
| 333 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 337 | .dot = { .min = 25000, .max = 350000 }, |
| 338 | .vco = { .min = 1760000, .max = 3510000 }, |
| 339 | .n = { .min = 1, .max = 3 }, |
| 340 | .m = { .min = 79, .max = 127 }, |
| 341 | .m1 = { .min = 12, .max = 22 }, |
| 342 | .m2 = { .min = 5, .max = 9 }, |
| 343 | .p = { .min = 14, .max = 56 }, |
| 344 | .p1 = { .min = 2, .max = 8 }, |
| 345 | .p2 = { .dot_limit = 225000, |
| 346 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 347 | }; |
| 348 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 349 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 350 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 351 | .dot = { .min = 25000, .max = 350000 }, |
| 352 | .vco = { .min = 1760000, .max = 3510000 }, |
| 353 | .n = { .min = 1, .max = 2 }, |
| 354 | .m = { .min = 79, .max = 126 }, |
| 355 | .m1 = { .min = 12, .max = 22 }, |
| 356 | .m2 = { .min = 5, .max = 9 }, |
| 357 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 358 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 359 | .p2 = { .dot_limit = 225000, |
| 360 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 364 | .dot = { .min = 25000, .max = 350000 }, |
| 365 | .vco = { .min = 1760000, .max = 3510000 }, |
| 366 | .n = { .min = 1, .max = 3 }, |
| 367 | .m = { .min = 79, .max = 126 }, |
| 368 | .m1 = { .min = 12, .max = 22 }, |
| 369 | .m2 = { .min = 5, .max = 9 }, |
| 370 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 371 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 372 | .p2 = { .dot_limit = 225000, |
| 373 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 374 | }; |
| 375 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 376 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 377 | /* |
| 378 | * These are the data rate limits (measured in fast clocks) |
| 379 | * since those are the strictest limits we have. The fast |
| 380 | * clock and actual rate limits are more relaxed, so checking |
| 381 | * them would make no difference. |
| 382 | */ |
| 383 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 384 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 385 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 386 | .m1 = { .min = 2, .max = 3 }, |
| 387 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 388 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 389 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 390 | }; |
| 391 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 392 | static const intel_limit_t intel_limits_chv = { |
| 393 | /* |
| 394 | * These are the data rate limits (measured in fast clocks) |
| 395 | * since those are the strictest limits we have. The fast |
| 396 | * clock and actual rate limits are more relaxed, so checking |
| 397 | * them would make no difference. |
| 398 | */ |
| 399 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 400 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 401 | .n = { .min = 1, .max = 1 }, |
| 402 | .m1 = { .min = 2, .max = 2 }, |
| 403 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 404 | .p1 = { .min = 2, .max = 4 }, |
| 405 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 406 | }; |
| 407 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 408 | static const intel_limit_t intel_limits_bxt = { |
| 409 | /* FIXME: find real dot limits */ |
| 410 | .dot = { .min = 0, .max = INT_MAX }, |
| 411 | .vco = { .min = 4800000, .max = 6480000 }, |
| 412 | .n = { .min = 1, .max = 1 }, |
| 413 | .m1 = { .min = 2, .max = 2 }, |
| 414 | /* FIXME: find real m2 limits */ |
| 415 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 416 | .p1 = { .min = 2, .max = 4 }, |
| 417 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 418 | }; |
| 419 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 420 | static void vlv_clock(int refclk, intel_clock_t *clock) |
| 421 | { |
| 422 | clock->m = clock->m1 * clock->m2; |
| 423 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 424 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 425 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 426 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 427 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 428 | } |
| 429 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 430 | /** |
| 431 | * Returns whether any output on the specified pipe is of the specified type |
| 432 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 433 | 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] | 434 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 435 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 436 | struct intel_encoder *encoder; |
| 437 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 438 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 439 | if (encoder->type == type) |
| 440 | return true; |
| 441 | |
| 442 | return false; |
| 443 | } |
| 444 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 445 | /** |
| 446 | * Returns whether any output on the specified pipe will have the specified |
| 447 | * type after a staged modeset is complete, i.e., the same as |
| 448 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 449 | * encoder->crtc. |
| 450 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 451 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 452 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 453 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 454 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 455 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 456 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 457 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 458 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 459 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 460 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 461 | if (connector_state->crtc != crtc_state->base.crtc) |
| 462 | continue; |
| 463 | |
| 464 | num_connectors++; |
| 465 | |
| 466 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 467 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 468 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 472 | |
| 473 | return false; |
| 474 | } |
| 475 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 476 | static const intel_limit_t * |
| 477 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 478 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 479 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 480 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 481 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 482 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 483 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 484 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 485 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 486 | else |
| 487 | limit = &intel_limits_ironlake_dual_lvds; |
| 488 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 489 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 490 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 491 | else |
| 492 | limit = &intel_limits_ironlake_single_lvds; |
| 493 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 494 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 495 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 496 | |
| 497 | return limit; |
| 498 | } |
| 499 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 500 | static const intel_limit_t * |
| 501 | intel_g4x_limit(struct intel_crtc_state *crtc_state) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 502 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 503 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 504 | const intel_limit_t *limit; |
| 505 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 506 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 507 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 508 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 509 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 510 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 511 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 512 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 513 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 514 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 515 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 516 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 517 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 518 | |
| 519 | return limit; |
| 520 | } |
| 521 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 522 | static const intel_limit_t * |
| 523 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 524 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 525 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 526 | const intel_limit_t *limit; |
| 527 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 528 | if (IS_BROXTON(dev)) |
| 529 | limit = &intel_limits_bxt; |
| 530 | else if (HAS_PCH_SPLIT(dev)) |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 531 | limit = intel_ironlake_limit(crtc_state, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 532 | else if (IS_G4X(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 533 | limit = intel_g4x_limit(crtc_state); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 534 | } else if (IS_PINEVIEW(dev)) { |
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)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 536 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 537 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 538 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 539 | } else if (IS_CHERRYVIEW(dev)) { |
| 540 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 541 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 542 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 543 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 544 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 545 | limit = &intel_limits_i9xx_lvds; |
| 546 | else |
| 547 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 548 | } else { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 549 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 550 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 551 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 552 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 553 | else |
| 554 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 555 | } |
| 556 | return limit; |
| 557 | } |
| 558 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 559 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 560 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 561 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 562 | clock->m = clock->m2 + 2; |
| 563 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 564 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 565 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 566 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 567 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 568 | } |
| 569 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 570 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 571 | { |
| 572 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 573 | } |
| 574 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 575 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 576 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 577 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 578 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 579 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
| 580 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 581 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 582 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 585 | static void chv_clock(int refclk, intel_clock_t *clock) |
| 586 | { |
| 587 | clock->m = clock->m1 * clock->m2; |
| 588 | clock->p = clock->p1 * clock->p2; |
| 589 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 590 | return; |
| 591 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 592 | clock->n << 22); |
| 593 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
| 594 | } |
| 595 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 596 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | /** |
| 598 | * Returns whether the given set of divisors are valid for a given refclk with |
| 599 | * the given connectors. |
| 600 | */ |
| 601 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 602 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 603 | const intel_limit_t *limit, |
| 604 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 605 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 606 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 607 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 608 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 609 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 611 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 613 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 614 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 615 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 616 | if (clock->m1 <= clock->m2) |
| 617 | INTELPllInvalid("m1 <= m2\n"); |
| 618 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 619 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 620 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 621 | INTELPllInvalid("p out of range\n"); |
| 622 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 623 | INTELPllInvalid("m out of range\n"); |
| 624 | } |
| 625 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 626 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 627 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 628 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 629 | * connector, etc., rather than just a single range. |
| 630 | */ |
| 631 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 632 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 633 | |
| 634 | return true; |
| 635 | } |
| 636 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 637 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 638 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 639 | struct intel_crtc_state *crtc_state, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 640 | int target, int refclk, intel_clock_t *match_clock, |
| 641 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 642 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 643 | 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] | 644 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 645 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 646 | int err = target; |
| 647 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 648 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 649 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 650 | * For LVDS just rely on its current settings for dual-channel. |
| 651 | * We haven't figured out how to reliably set up different |
| 652 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 653 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 654 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 655 | clock.p2 = limit->p2.p2_fast; |
| 656 | else |
| 657 | clock.p2 = limit->p2.p2_slow; |
| 658 | } else { |
| 659 | if (target < limit->p2.dot_limit) |
| 660 | clock.p2 = limit->p2.p2_slow; |
| 661 | else |
| 662 | clock.p2 = limit->p2.p2_fast; |
| 663 | } |
| 664 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 665 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 666 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 667 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 668 | clock.m1++) { |
| 669 | for (clock.m2 = limit->m2.min; |
| 670 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 671 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 672 | break; |
| 673 | for (clock.n = limit->n.min; |
| 674 | clock.n <= limit->n.max; clock.n++) { |
| 675 | for (clock.p1 = limit->p1.min; |
| 676 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 677 | int this_err; |
| 678 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 679 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 680 | if (!intel_PLL_is_valid(dev, limit, |
| 681 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 682 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 683 | if (match_clock && |
| 684 | clock.p != match_clock->p) |
| 685 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 686 | |
| 687 | this_err = abs(clock.dot - target); |
| 688 | if (this_err < err) { |
| 689 | *best_clock = clock; |
| 690 | err = this_err; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return (err != target); |
| 698 | } |
| 699 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 700 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 701 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 702 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 703 | int target, int refclk, intel_clock_t *match_clock, |
| 704 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 705 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 706 | 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] | 707 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 708 | intel_clock_t clock; |
| 709 | int err = target; |
| 710 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 711 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 712 | /* |
| 713 | * For LVDS just rely on its current settings for dual-channel. |
| 714 | * We haven't figured out how to reliably set up different |
| 715 | * single/dual channel state, if we even can. |
| 716 | */ |
| 717 | if (intel_is_dual_link_lvds(dev)) |
| 718 | clock.p2 = limit->p2.p2_fast; |
| 719 | else |
| 720 | clock.p2 = limit->p2.p2_slow; |
| 721 | } else { |
| 722 | if (target < limit->p2.dot_limit) |
| 723 | clock.p2 = limit->p2.p2_slow; |
| 724 | else |
| 725 | clock.p2 = limit->p2.p2_fast; |
| 726 | } |
| 727 | |
| 728 | memset(best_clock, 0, sizeof(*best_clock)); |
| 729 | |
| 730 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 731 | clock.m1++) { |
| 732 | for (clock.m2 = limit->m2.min; |
| 733 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 734 | for (clock.n = limit->n.min; |
| 735 | clock.n <= limit->n.max; clock.n++) { |
| 736 | for (clock.p1 = limit->p1.min; |
| 737 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 738 | int this_err; |
| 739 | |
| 740 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 741 | if (!intel_PLL_is_valid(dev, limit, |
| 742 | &clock)) |
| 743 | continue; |
| 744 | if (match_clock && |
| 745 | clock.p != match_clock->p) |
| 746 | continue; |
| 747 | |
| 748 | this_err = abs(clock.dot - target); |
| 749 | if (this_err < err) { |
| 750 | *best_clock = clock; |
| 751 | err = this_err; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | return (err != target); |
| 759 | } |
| 760 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 761 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 762 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 763 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 764 | int target, int refclk, intel_clock_t *match_clock, |
| 765 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 766 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 767 | 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] | 768 | struct drm_device *dev = crtc->base.dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 769 | intel_clock_t clock; |
| 770 | int max_n; |
| 771 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 772 | /* approximately equals target * 0.00585 */ |
| 773 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 774 | found = false; |
| 775 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 776 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 777 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 778 | clock.p2 = limit->p2.p2_fast; |
| 779 | else |
| 780 | clock.p2 = limit->p2.p2_slow; |
| 781 | } else { |
| 782 | if (target < limit->p2.dot_limit) |
| 783 | clock.p2 = limit->p2.p2_slow; |
| 784 | else |
| 785 | clock.p2 = limit->p2.p2_fast; |
| 786 | } |
| 787 | |
| 788 | memset(best_clock, 0, sizeof(*best_clock)); |
| 789 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 790 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 791 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 792 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 793 | for (clock.m1 = limit->m1.max; |
| 794 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 795 | for (clock.m2 = limit->m2.max; |
| 796 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 797 | for (clock.p1 = limit->p1.max; |
| 798 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 799 | int this_err; |
| 800 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 801 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 802 | if (!intel_PLL_is_valid(dev, limit, |
| 803 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 804 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 805 | |
| 806 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 807 | if (this_err < err_most) { |
| 808 | *best_clock = clock; |
| 809 | err_most = this_err; |
| 810 | max_n = clock.n; |
| 811 | found = true; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 817 | return found; |
| 818 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 819 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 820 | /* |
| 821 | * Check if the calculated PLL configuration is more optimal compared to the |
| 822 | * best configuration and error found so far. Return the calculated error. |
| 823 | */ |
| 824 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 825 | const intel_clock_t *calculated_clock, |
| 826 | const intel_clock_t *best_clock, |
| 827 | unsigned int best_error_ppm, |
| 828 | unsigned int *error_ppm) |
| 829 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 830 | /* |
| 831 | * For CHV ignore the error and consider only the P value. |
| 832 | * Prefer a bigger P value based on HW requirements. |
| 833 | */ |
| 834 | if (IS_CHERRYVIEW(dev)) { |
| 835 | *error_ppm = 0; |
| 836 | |
| 837 | return calculated_clock->p > best_clock->p; |
| 838 | } |
| 839 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 840 | if (WARN_ON_ONCE(!target_freq)) |
| 841 | return false; |
| 842 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 843 | *error_ppm = div_u64(1000000ULL * |
| 844 | abs(target_freq - calculated_clock->dot), |
| 845 | target_freq); |
| 846 | /* |
| 847 | * Prefer a better P value over a better (smaller) error if the error |
| 848 | * is small. Ensure this preference for future configurations too by |
| 849 | * setting the error to 0. |
| 850 | */ |
| 851 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 852 | *error_ppm = 0; |
| 853 | |
| 854 | return true; |
| 855 | } |
| 856 | |
| 857 | return *error_ppm + 10 < best_error_ppm; |
| 858 | } |
| 859 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 860 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 861 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 862 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 863 | int target, int refclk, intel_clock_t *match_clock, |
| 864 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 865 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 866 | 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] | 867 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 868 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 869 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 870 | /* min update 19.2 MHz */ |
| 871 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 872 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 873 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 874 | target *= 5; /* fast clock */ |
| 875 | |
| 876 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 877 | |
| 878 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 879 | 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] | 880 | 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] | 881 | 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] | 882 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 883 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 884 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 885 | 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] | 886 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 887 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 888 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 889 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 890 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 891 | vlv_clock(refclk, &clock); |
| 892 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 893 | if (!intel_PLL_is_valid(dev, limit, |
| 894 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 895 | continue; |
| 896 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 897 | if (!vlv_PLL_is_optimal(dev, target, |
| 898 | &clock, |
| 899 | best_clock, |
| 900 | bestppm, &ppm)) |
| 901 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 902 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 903 | *best_clock = clock; |
| 904 | bestppm = ppm; |
| 905 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | } |
| 909 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 910 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 911 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 912 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 913 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 914 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 915 | chv_find_best_dpll(const intel_limit_t *limit, |
| 916 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 917 | int target, int refclk, intel_clock_t *match_clock, |
| 918 | intel_clock_t *best_clock) |
| 919 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 920 | 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] | 921 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 922 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 923 | intel_clock_t clock; |
| 924 | uint64_t m2; |
| 925 | int found = false; |
| 926 | |
| 927 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 928 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 929 | |
| 930 | /* |
| 931 | * Based on hardware doc, the n always set to 1, and m1 always |
| 932 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 933 | * revisit this because n may not 1 anymore. |
| 934 | */ |
| 935 | clock.n = 1, clock.m1 = 2; |
| 936 | target *= 5; /* fast clock */ |
| 937 | |
| 938 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 939 | for (clock.p2 = limit->p2.p2_fast; |
| 940 | clock.p2 >= limit->p2.p2_slow; |
| 941 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 942 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 943 | |
| 944 | clock.p = clock.p1 * clock.p2; |
| 945 | |
| 946 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 947 | clock.n) << 22, refclk * clock.m1); |
| 948 | |
| 949 | if (m2 > INT_MAX/clock.m1) |
| 950 | continue; |
| 951 | |
| 952 | clock.m2 = m2; |
| 953 | |
| 954 | chv_clock(refclk, &clock); |
| 955 | |
| 956 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 957 | continue; |
| 958 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 959 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 960 | best_error_ppm, &error_ppm)) |
| 961 | continue; |
| 962 | |
| 963 | *best_clock = clock; |
| 964 | best_error_ppm = error_ppm; |
| 965 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | return found; |
| 970 | } |
| 971 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 972 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
| 973 | intel_clock_t *best_clock) |
| 974 | { |
| 975 | int refclk = i9xx_get_refclk(crtc_state, 0); |
| 976 | |
| 977 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, |
| 978 | target_clock, refclk, NULL, best_clock); |
| 979 | } |
| 980 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 981 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 982 | { |
| 983 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 984 | |
| 985 | /* Be paranoid as we can arrive here with only partial |
| 986 | * state retrieved from the hardware during setup. |
| 987 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 988 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 989 | * as Haswell has gained clock readout/fastboot support. |
| 990 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 991 | * 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] | 992 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 993 | * |
| 994 | * FIXME: The intel_crtc->active here should be switched to |
| 995 | * crtc->state->active once we have proper CRTC states wired up |
| 996 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 997 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 998 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 999 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1000 | } |
| 1001 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1002 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1003 | enum pipe pipe) |
| 1004 | { |
| 1005 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1006 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1007 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1008 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1009 | } |
| 1010 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1011 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 1012 | { |
| 1013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1014 | u32 reg = PIPEDSL(pipe); |
| 1015 | u32 line1, line2; |
| 1016 | u32 line_mask; |
| 1017 | |
| 1018 | if (IS_GEN2(dev)) |
| 1019 | line_mask = DSL_LINEMASK_GEN2; |
| 1020 | else |
| 1021 | line_mask = DSL_LINEMASK_GEN3; |
| 1022 | |
| 1023 | line1 = I915_READ(reg) & line_mask; |
| 1024 | mdelay(5); |
| 1025 | line2 = I915_READ(reg) & line_mask; |
| 1026 | |
| 1027 | return line1 == line2; |
| 1028 | } |
| 1029 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1030 | /* |
| 1031 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1032 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1033 | * |
| 1034 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1035 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1036 | * see an interrupt when the pipe is disabled. |
| 1037 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1038 | * On Gen4 and above: |
| 1039 | * wait for the pipe register state bit to turn off |
| 1040 | * |
| 1041 | * Otherwise: |
| 1042 | * wait for the display line value to settle (it usually |
| 1043 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1044 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1045 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1046 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1047 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1048 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1049 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1050 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1051 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1052 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1053 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1054 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1055 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1056 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1057 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1058 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1059 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1060 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1061 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1062 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1063 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1064 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1067 | /* |
| 1068 | * ibx_digital_port_connected - is the specified port connected? |
| 1069 | * @dev_priv: i915 private structure |
| 1070 | * @port: the port to test |
| 1071 | * |
| 1072 | * Returns true if @port is connected, false otherwise. |
| 1073 | */ |
| 1074 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 1075 | struct intel_digital_port *port) |
| 1076 | { |
| 1077 | u32 bit; |
| 1078 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1079 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1080 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1081 | case PORT_B: |
| 1082 | bit = SDE_PORTB_HOTPLUG; |
| 1083 | break; |
| 1084 | case PORT_C: |
| 1085 | bit = SDE_PORTC_HOTPLUG; |
| 1086 | break; |
| 1087 | case PORT_D: |
| 1088 | bit = SDE_PORTD_HOTPLUG; |
| 1089 | break; |
| 1090 | default: |
| 1091 | return true; |
| 1092 | } |
| 1093 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1094 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1095 | case PORT_B: |
| 1096 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1097 | break; |
| 1098 | case PORT_C: |
| 1099 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1100 | break; |
| 1101 | case PORT_D: |
| 1102 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1103 | break; |
| 1104 | default: |
| 1105 | return true; |
| 1106 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | return I915_READ(SDEISR) & bit; |
| 1110 | } |
| 1111 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1112 | static const char *state_string(bool enabled) |
| 1113 | { |
| 1114 | return enabled ? "on" : "off"; |
| 1115 | } |
| 1116 | |
| 1117 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1118 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1119 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1120 | { |
| 1121 | int reg; |
| 1122 | u32 val; |
| 1123 | bool cur_state; |
| 1124 | |
| 1125 | reg = DPLL(pipe); |
| 1126 | val = I915_READ(reg); |
| 1127 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1128 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1129 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1130 | state_string(state), state_string(cur_state)); |
| 1131 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1132 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1133 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1134 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1135 | { |
| 1136 | u32 val; |
| 1137 | bool cur_state; |
| 1138 | |
| 1139 | mutex_lock(&dev_priv->dpio_lock); |
| 1140 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1141 | mutex_unlock(&dev_priv->dpio_lock); |
| 1142 | |
| 1143 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1144 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1145 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1146 | state_string(state), state_string(cur_state)); |
| 1147 | } |
| 1148 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1149 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1150 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1151 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1152 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1153 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1154 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1155 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1156 | if (crtc->config->shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1157 | return NULL; |
| 1158 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1159 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1162 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1163 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1164 | struct intel_shared_dpll *pll, |
| 1165 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1166 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1167 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1168 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1169 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1170 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1171 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1172 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1173 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1174 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1175 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1176 | "%s assertion failure (expected %s, current %s)\n", |
| 1177 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1178 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1179 | |
| 1180 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1181 | enum pipe pipe, bool state) |
| 1182 | { |
| 1183 | int reg; |
| 1184 | u32 val; |
| 1185 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1186 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1187 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1188 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1189 | if (HAS_DDI(dev_priv->dev)) { |
| 1190 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1191 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1192 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1193 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1194 | } else { |
| 1195 | reg = FDI_TX_CTL(pipe); |
| 1196 | val = I915_READ(reg); |
| 1197 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1198 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1199 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1200 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1201 | state_string(state), state_string(cur_state)); |
| 1202 | } |
| 1203 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1204 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1205 | |
| 1206 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1207 | enum pipe pipe, bool state) |
| 1208 | { |
| 1209 | int reg; |
| 1210 | u32 val; |
| 1211 | bool cur_state; |
| 1212 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1213 | reg = FDI_RX_CTL(pipe); |
| 1214 | val = I915_READ(reg); |
| 1215 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1216 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1217 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1218 | state_string(state), state_string(cur_state)); |
| 1219 | } |
| 1220 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1221 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1222 | |
| 1223 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1224 | enum pipe pipe) |
| 1225 | { |
| 1226 | int reg; |
| 1227 | u32 val; |
| 1228 | |
| 1229 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1230 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1231 | return; |
| 1232 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1233 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1234 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1235 | return; |
| 1236 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1237 | reg = FDI_TX_CTL(pipe); |
| 1238 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1239 | 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] | 1240 | } |
| 1241 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1242 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1243 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1244 | { |
| 1245 | int reg; |
| 1246 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1247 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1248 | |
| 1249 | reg = FDI_RX_CTL(pipe); |
| 1250 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1251 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1252 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1253 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1254 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1257 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1258 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1259 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1260 | struct drm_device *dev = dev_priv->dev; |
| 1261 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1262 | u32 val; |
| 1263 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1264 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1265 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1266 | if (WARN_ON(HAS_DDI(dev))) |
| 1267 | return; |
| 1268 | |
| 1269 | if (HAS_PCH_SPLIT(dev)) { |
| 1270 | u32 port_sel; |
| 1271 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1272 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1273 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1274 | |
| 1275 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1276 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1277 | panel_pipe = PIPE_B; |
| 1278 | /* XXX: else fix for eDP */ |
| 1279 | } else if (IS_VALLEYVIEW(dev)) { |
| 1280 | /* presumably write lock depends on pipe, not port select */ |
| 1281 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1282 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1283 | } else { |
| 1284 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1285 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1286 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | val = I915_READ(pp_reg); |
| 1290 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1291 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1292 | locked = false; |
| 1293 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1294 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1295 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1296 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1299 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1300 | enum pipe pipe, bool state) |
| 1301 | { |
| 1302 | struct drm_device *dev = dev_priv->dev; |
| 1303 | bool cur_state; |
| 1304 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1305 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1306 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1307 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1308 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1309 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1310 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1311 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1312 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1313 | } |
| 1314 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1315 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1316 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1317 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1318 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1319 | { |
| 1320 | int reg; |
| 1321 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1322 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1323 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1324 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1325 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1326 | /* if we need the pipe quirk it must be always on */ |
| 1327 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1328 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1329 | state = true; |
| 1330 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1331 | if (!intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1332 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1333 | cur_state = false; |
| 1334 | } else { |
| 1335 | reg = PIPECONF(cpu_transcoder); |
| 1336 | val = I915_READ(reg); |
| 1337 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1338 | } |
| 1339 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1340 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1341 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1342 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1343 | } |
| 1344 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1345 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1346 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1347 | { |
| 1348 | int reg; |
| 1349 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1350 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1351 | |
| 1352 | reg = DSPCNTR(plane); |
| 1353 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1354 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1355 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1356 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1357 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1360 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1361 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1362 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1363 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1364 | enum pipe pipe) |
| 1365 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1366 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1367 | int reg, i; |
| 1368 | u32 val; |
| 1369 | int cur_pipe; |
| 1370 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1371 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1372 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1373 | reg = DSPCNTR(pipe); |
| 1374 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1375 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1376 | "plane %c assertion failure, should be disabled but not\n", |
| 1377 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1378 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1379 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1380 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1381 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1382 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1383 | reg = DSPCNTR(i); |
| 1384 | val = I915_READ(reg); |
| 1385 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1386 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1387 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1388 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1389 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1393 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1394 | enum pipe pipe) |
| 1395 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1396 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1397 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1398 | u32 val; |
| 1399 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1400 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1401 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1402 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1403 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1404 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1405 | sprite, pipe_name(pipe)); |
| 1406 | } |
| 1407 | } else if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1408 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1409 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1410 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1411 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1412 | "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] | 1413 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1414 | } |
| 1415 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1416 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1417 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1418 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1419 | "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] | 1420 | plane_name(pipe), pipe_name(pipe)); |
| 1421 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1422 | reg = DVSCNTR(pipe); |
| 1423 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1424 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1425 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1426 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1430 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1431 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1432 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1433 | drm_crtc_vblank_put(crtc); |
| 1434 | } |
| 1435 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1436 | 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] | 1437 | { |
| 1438 | u32 val; |
| 1439 | bool enabled; |
| 1440 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1441 | 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] | 1442 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1443 | val = I915_READ(PCH_DREF_CONTROL); |
| 1444 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1445 | DREF_SUPERSPREAD_SOURCE_MASK)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1446 | 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] | 1447 | } |
| 1448 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1449 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1450 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1451 | { |
| 1452 | int reg; |
| 1453 | u32 val; |
| 1454 | bool enabled; |
| 1455 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1456 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1457 | val = I915_READ(reg); |
| 1458 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1459 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1460 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1461 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1464 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1465 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1466 | { |
| 1467 | if ((val & DP_PORT_EN) == 0) |
| 1468 | return false; |
| 1469 | |
| 1470 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1471 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1472 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1473 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1474 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1475 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1476 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1477 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1478 | } else { |
| 1479 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1480 | return false; |
| 1481 | } |
| 1482 | return true; |
| 1483 | } |
| 1484 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1485 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1486 | enum pipe pipe, u32 val) |
| 1487 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1488 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1489 | return false; |
| 1490 | |
| 1491 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1492 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1493 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1494 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1495 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1496 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1497 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1498 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1499 | return false; |
| 1500 | } |
| 1501 | return true; |
| 1502 | } |
| 1503 | |
| 1504 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1505 | enum pipe pipe, u32 val) |
| 1506 | { |
| 1507 | if ((val & LVDS_PORT_EN) == 0) |
| 1508 | return false; |
| 1509 | |
| 1510 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1511 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1512 | return false; |
| 1513 | } else { |
| 1514 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1515 | return false; |
| 1516 | } |
| 1517 | return true; |
| 1518 | } |
| 1519 | |
| 1520 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1521 | enum pipe pipe, u32 val) |
| 1522 | { |
| 1523 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1524 | return false; |
| 1525 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1526 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1527 | return false; |
| 1528 | } else { |
| 1529 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1530 | return false; |
| 1531 | } |
| 1532 | return true; |
| 1533 | } |
| 1534 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1535 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1536 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1537 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1538 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1539 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1540 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1541 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1542 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1543 | 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] | 1544 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1545 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1549 | enum pipe pipe, int reg) |
| 1550 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1551 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1552 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1553 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1554 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1555 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1556 | 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] | 1557 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1558 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1562 | enum pipe pipe) |
| 1563 | { |
| 1564 | int reg; |
| 1565 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1566 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1567 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1568 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1569 | 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] | 1570 | |
| 1571 | reg = PCH_ADPA; |
| 1572 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1573 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1574 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1575 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1576 | |
| 1577 | reg = PCH_LVDS; |
| 1578 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1579 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1580 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1581 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1582 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1583 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1584 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1585 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1588 | static void intel_init_dpio(struct drm_device *dev) |
| 1589 | { |
| 1590 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1591 | |
| 1592 | if (!IS_VALLEYVIEW(dev)) |
| 1593 | return; |
| 1594 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1595 | /* |
| 1596 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1597 | * CHV x1 PHY (DP/HDMI D) |
| 1598 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1599 | */ |
| 1600 | if (IS_CHERRYVIEW(dev)) { |
| 1601 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1602 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1603 | } else { |
| 1604 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1605 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1606 | } |
| 1607 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1608 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1609 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1610 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1611 | struct drm_device *dev = crtc->base.dev; |
| 1612 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1613 | int reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1614 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1615 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1616 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1617 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1618 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1619 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1620 | |
| 1621 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1622 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1623 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1624 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1625 | I915_WRITE(reg, dpll); |
| 1626 | POSTING_READ(reg); |
| 1627 | udelay(150); |
| 1628 | |
| 1629 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1630 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1631 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1632 | 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] | 1633 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1634 | |
| 1635 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1636 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1637 | POSTING_READ(reg); |
| 1638 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1639 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1640 | POSTING_READ(reg); |
| 1641 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1642 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1643 | POSTING_READ(reg); |
| 1644 | udelay(150); /* wait for warmup */ |
| 1645 | } |
| 1646 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1647 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1648 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1649 | { |
| 1650 | struct drm_device *dev = crtc->base.dev; |
| 1651 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1652 | int pipe = crtc->pipe; |
| 1653 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1654 | u32 tmp; |
| 1655 | |
| 1656 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1657 | |
| 1658 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1659 | |
| 1660 | mutex_lock(&dev_priv->dpio_lock); |
| 1661 | |
| 1662 | /* Enable back the 10bit clock to display controller */ |
| 1663 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1664 | tmp |= DPIO_DCLKP_EN; |
| 1665 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1666 | |
| 1667 | /* |
| 1668 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1669 | */ |
| 1670 | udelay(1); |
| 1671 | |
| 1672 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1673 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1674 | |
| 1675 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1676 | 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] | 1677 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1678 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1679 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1680 | 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] | 1681 | POSTING_READ(DPLL_MD(pipe)); |
| 1682 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1683 | mutex_unlock(&dev_priv->dpio_lock); |
| 1684 | } |
| 1685 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1686 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1687 | { |
| 1688 | struct intel_crtc *crtc; |
| 1689 | int count = 0; |
| 1690 | |
| 1691 | for_each_intel_crtc(dev, crtc) |
| 1692 | count += crtc->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1693 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1694 | |
| 1695 | return count; |
| 1696 | } |
| 1697 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1698 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1699 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1700 | struct drm_device *dev = crtc->base.dev; |
| 1701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1702 | int reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1703 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1704 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1705 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1706 | |
| 1707 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1708 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1709 | |
| 1710 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1711 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1712 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1713 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1714 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1715 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1716 | /* |
| 1717 | * It appears to be important that we don't enable this |
| 1718 | * for the current pipe before otherwise configuring the |
| 1719 | * PLL. No idea how this should be handled if multiple |
| 1720 | * DVO outputs are enabled simultaneosly. |
| 1721 | */ |
| 1722 | dpll |= DPLL_DVO_2X_MODE; |
| 1723 | I915_WRITE(DPLL(!crtc->pipe), |
| 1724 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1725 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1726 | |
| 1727 | /* Wait for the clocks to stabilize. */ |
| 1728 | POSTING_READ(reg); |
| 1729 | udelay(150); |
| 1730 | |
| 1731 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1732 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1733 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1734 | } else { |
| 1735 | /* The pixel multiplier can only be updated once the |
| 1736 | * DPLL is enabled and the clocks are stable. |
| 1737 | * |
| 1738 | * So write it again. |
| 1739 | */ |
| 1740 | I915_WRITE(reg, dpll); |
| 1741 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1742 | |
| 1743 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1744 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1745 | POSTING_READ(reg); |
| 1746 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1747 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1748 | POSTING_READ(reg); |
| 1749 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1750 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1751 | POSTING_READ(reg); |
| 1752 | udelay(150); /* wait for warmup */ |
| 1753 | } |
| 1754 | |
| 1755 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1756 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1757 | * @dev_priv: i915 private structure |
| 1758 | * @pipe: pipe PLL to disable |
| 1759 | * |
| 1760 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1761 | * |
| 1762 | * Note! This is for pre-ILK only. |
| 1763 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1764 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1765 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1766 | struct drm_device *dev = crtc->base.dev; |
| 1767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1768 | enum pipe pipe = crtc->pipe; |
| 1769 | |
| 1770 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1771 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1772 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1773 | intel_num_dvo_pipes(dev) == 1) { |
| 1774 | I915_WRITE(DPLL(PIPE_B), |
| 1775 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1776 | I915_WRITE(DPLL(PIPE_A), |
| 1777 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1778 | } |
| 1779 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1780 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1781 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1782 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1783 | return; |
| 1784 | |
| 1785 | /* Make sure the pipe isn't still relying on us */ |
| 1786 | assert_pipe_disabled(dev_priv, pipe); |
| 1787 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1788 | I915_WRITE(DPLL(pipe), 0); |
| 1789 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1790 | } |
| 1791 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1792 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1793 | { |
| 1794 | u32 val = 0; |
| 1795 | |
| 1796 | /* Make sure the pipe isn't still relying on us */ |
| 1797 | assert_pipe_disabled(dev_priv, pipe); |
| 1798 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1799 | /* |
| 1800 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1801 | * The latter is needed for VGA hotplug / manual detection. |
| 1802 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1803 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1804 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1805 | I915_WRITE(DPLL(pipe), val); |
| 1806 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1807 | |
| 1808 | } |
| 1809 | |
| 1810 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1811 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1812 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1813 | u32 val; |
| 1814 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1815 | /* Make sure the pipe isn't still relying on us */ |
| 1816 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1817 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1818 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1819 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1820 | if (pipe != PIPE_A) |
| 1821 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1822 | I915_WRITE(DPLL(pipe), val); |
| 1823 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1824 | |
| 1825 | mutex_lock(&dev_priv->dpio_lock); |
| 1826 | |
| 1827 | /* Disable 10bit clock to display controller */ |
| 1828 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1829 | val &= ~DPIO_DCLKP_EN; |
| 1830 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1831 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1832 | /* disable left/right clock distribution */ |
| 1833 | if (pipe != PIPE_B) { |
| 1834 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1835 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1836 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1837 | } else { |
| 1838 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1839 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1840 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1841 | } |
| 1842 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1843 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1846 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1847 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1848 | { |
| 1849 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1850 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1851 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1852 | switch (dport->port) { |
| 1853 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1854 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1855 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1856 | break; |
| 1857 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1858 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1859 | dpll_reg = DPLL(0); |
| 1860 | break; |
| 1861 | case PORT_D: |
| 1862 | port_mask = DPLL_PORTD_READY_MASK; |
| 1863 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1864 | break; |
| 1865 | default: |
| 1866 | BUG(); |
| 1867 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1868 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1869 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1870 | 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] | 1871 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1874 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1875 | { |
| 1876 | struct drm_device *dev = crtc->base.dev; |
| 1877 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1878 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1879 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1880 | if (WARN_ON(pll == NULL)) |
| 1881 | return; |
| 1882 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1883 | WARN_ON(!pll->config.crtc_mask); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1884 | if (pll->active == 0) { |
| 1885 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1886 | WARN_ON(pll->on); |
| 1887 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1888 | |
| 1889 | pll->mode_set(dev_priv, pll); |
| 1890 | } |
| 1891 | } |
| 1892 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1893 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1894 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1895 | * @dev_priv: i915 private structure |
| 1896 | * @pipe: pipe PLL to enable |
| 1897 | * |
| 1898 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1899 | * drives the transcoder clock. |
| 1900 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1901 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1902 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1903 | struct drm_device *dev = crtc->base.dev; |
| 1904 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1905 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1906 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1907 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1908 | return; |
| 1909 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1910 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1911 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1912 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1913 | 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] | 1914 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1915 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1916 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1917 | if (pll->active++) { |
| 1918 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1919 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1920 | return; |
| 1921 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1922 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1923 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1924 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1925 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1926 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1927 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1928 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1931 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1932 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1933 | struct drm_device *dev = crtc->base.dev; |
| 1934 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1935 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1936 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1937 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1938 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1939 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1940 | return; |
| 1941 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1942 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1943 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1944 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1945 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1946 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1947 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1948 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1949 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1950 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1951 | return; |
| 1952 | } |
| 1953 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1954 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1955 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1956 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1957 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1958 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1959 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1960 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1961 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1962 | |
| 1963 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1964 | } |
| 1965 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1966 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1967 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1968 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1969 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1970 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1971 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1972 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1973 | |
| 1974 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1975 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1976 | |
| 1977 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1978 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1979 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1980 | |
| 1981 | /* FDI must be feeding us bits for PCH ports */ |
| 1982 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1983 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1984 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1985 | if (HAS_PCH_CPT(dev)) { |
| 1986 | /* Workaround: Set the timing override bit before enabling the |
| 1987 | * pch transcoder. */ |
| 1988 | reg = TRANS_CHICKEN2(pipe); |
| 1989 | val = I915_READ(reg); |
| 1990 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1991 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1992 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1993 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1994 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1995 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1996 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1997 | |
| 1998 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1999 | /* |
| 2000 | * make the BPC in transcoder be consistent with |
| 2001 | * that in pipeconf reg. |
| 2002 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2003 | val &= ~PIPECONF_BPC_MASK; |
| 2004 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 2005 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 2006 | |
| 2007 | val &= ~TRANS_INTERLACE_MASK; |
| 2008 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 2009 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2010 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 2011 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 2012 | else |
| 2013 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 2014 | else |
| 2015 | val |= TRANS_PROGRESSIVE; |
| 2016 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2017 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 2018 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2019 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2020 | } |
| 2021 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2022 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2023 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2024 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2025 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2026 | |
| 2027 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 2028 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2029 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2030 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2031 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2032 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2033 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2034 | /* Workaround: set timing override bit. */ |
| 2035 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2036 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2037 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 2038 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 2039 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2040 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2041 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 2042 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 2043 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 2044 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2045 | else |
| 2046 | val |= TRANS_PROGRESSIVE; |
| 2047 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2048 | I915_WRITE(LPT_TRANSCONF, val); |
| 2049 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2050 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 2053 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 2054 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2055 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2056 | struct drm_device *dev = dev_priv->dev; |
| 2057 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2058 | |
| 2059 | /* FDI relies on the transcoder */ |
| 2060 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 2061 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 2062 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 2063 | /* Ports must be off as well */ |
| 2064 | assert_pch_ports_disabled(dev_priv, pipe); |
| 2065 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2066 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2067 | val = I915_READ(reg); |
| 2068 | val &= ~TRANS_ENABLE; |
| 2069 | I915_WRITE(reg, val); |
| 2070 | /* wait for PCH transcoder off, transcoder state */ |
| 2071 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2072 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2073 | |
| 2074 | if (!HAS_PCH_IBX(dev)) { |
| 2075 | /* Workaround: Clear the timing override chicken bit again. */ |
| 2076 | reg = TRANS_CHICKEN2(pipe); |
| 2077 | val = I915_READ(reg); |
| 2078 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 2079 | I915_WRITE(reg, val); |
| 2080 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2081 | } |
| 2082 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 2083 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2084 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2085 | u32 val; |
| 2086 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2087 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2088 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2089 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2090 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2091 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 2092 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2093 | |
| 2094 | /* Workaround: clear timing override bit. */ |
| 2095 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2096 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2097 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2101 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2102 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2103 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2104 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2105 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2106 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 2107 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2108 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2109 | struct drm_device *dev = crtc->base.dev; |
| 2110 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2111 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2112 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 2113 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2114 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2115 | int reg; |
| 2116 | u32 val; |
| 2117 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2118 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2119 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2120 | assert_sprites_disabled(dev_priv, pipe); |
| 2121 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2122 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2123 | pch_transcoder = TRANSCODER_A; |
| 2124 | else |
| 2125 | pch_transcoder = pipe; |
| 2126 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2127 | /* |
| 2128 | * A pipe without a PLL won't actually be able to drive bits from |
| 2129 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2130 | * need the check. |
| 2131 | */ |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 2132 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2133 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2134 | assert_dsi_pll_enabled(dev_priv); |
| 2135 | else |
| 2136 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2137 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2138 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2139 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2140 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2141 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2142 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2143 | } |
| 2144 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2145 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2146 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2147 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2148 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2149 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2150 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2151 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2152 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2153 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2154 | |
| 2155 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2156 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2160 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2161 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2162 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2163 | * Disable the pipe of @crtc, making sure that various hardware |
| 2164 | * specific requirements are met, if applicable, e.g. plane |
| 2165 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2166 | * |
| 2167 | * Will wait until the pipe has shut down before returning. |
| 2168 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2169 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2170 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2171 | 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] | 2172 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2173 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2174 | int reg; |
| 2175 | u32 val; |
| 2176 | |
| 2177 | /* |
| 2178 | * Make sure planes won't keep trying to pump pixels to us, |
| 2179 | * or we might hang the display. |
| 2180 | */ |
| 2181 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2182 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2183 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2184 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2185 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2186 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2187 | if ((val & PIPECONF_ENABLE) == 0) |
| 2188 | return; |
| 2189 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2190 | /* |
| 2191 | * Double wide has implications for planes |
| 2192 | * so best keep it disabled when not needed. |
| 2193 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2194 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2195 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2196 | |
| 2197 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2198 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2199 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2200 | val &= ~PIPECONF_ENABLE; |
| 2201 | |
| 2202 | I915_WRITE(reg, val); |
| 2203 | if ((val & PIPECONF_ENABLE) == 0) |
| 2204 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2207 | /* |
| 2208 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2209 | * trigger in order to latch. The display address reg provides this. |
| 2210 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2211 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2212 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2213 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2214 | struct drm_device *dev = dev_priv->dev; |
| 2215 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2216 | |
| 2217 | I915_WRITE(reg, I915_READ(reg)); |
| 2218 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2221 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2222 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2223 | * @plane: plane to be enabled |
| 2224 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2225 | * |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2226 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2227 | */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2228 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2229 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2230 | { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2231 | struct drm_device *dev = plane->dev; |
| 2232 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2233 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2234 | |
| 2235 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2236 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2237 | to_intel_plane_state(plane->state)->visible = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2238 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2239 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2240 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2241 | } |
| 2242 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2243 | static bool need_vtd_wa(struct drm_device *dev) |
| 2244 | { |
| 2245 | #ifdef CONFIG_INTEL_IOMMU |
| 2246 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2247 | return true; |
| 2248 | #endif |
| 2249 | return false; |
| 2250 | } |
| 2251 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2252 | unsigned int |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2253 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
| 2254 | uint64_t fb_format_modifier) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2255 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2256 | unsigned int tile_height; |
| 2257 | uint32_t pixel_bytes; |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2258 | |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2259 | switch (fb_format_modifier) { |
| 2260 | case DRM_FORMAT_MOD_NONE: |
| 2261 | tile_height = 1; |
| 2262 | break; |
| 2263 | case I915_FORMAT_MOD_X_TILED: |
| 2264 | tile_height = IS_GEN2(dev) ? 16 : 8; |
| 2265 | break; |
| 2266 | case I915_FORMAT_MOD_Y_TILED: |
| 2267 | tile_height = 32; |
| 2268 | break; |
| 2269 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2270 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
| 2271 | switch (pixel_bytes) { |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2272 | default: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2273 | case 1: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2274 | tile_height = 64; |
| 2275 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2276 | case 2: |
| 2277 | case 4: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2278 | tile_height = 32; |
| 2279 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2280 | case 8: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2281 | tile_height = 16; |
| 2282 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2283 | case 16: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2284 | WARN_ONCE(1, |
| 2285 | "128-bit pixels are not supported for display!"); |
| 2286 | tile_height = 16; |
| 2287 | break; |
| 2288 | } |
| 2289 | break; |
| 2290 | default: |
| 2291 | MISSING_CASE(fb_format_modifier); |
| 2292 | tile_height = 1; |
| 2293 | break; |
| 2294 | } |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 2295 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2296 | return tile_height; |
| 2297 | } |
| 2298 | |
| 2299 | unsigned int |
| 2300 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
| 2301 | uint32_t pixel_format, uint64_t fb_format_modifier) |
| 2302 | { |
| 2303 | return ALIGN(height, intel_tile_height(dev, pixel_format, |
| 2304 | fb_format_modifier)); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2305 | } |
| 2306 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2307 | static int |
| 2308 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, |
| 2309 | const struct drm_plane_state *plane_state) |
| 2310 | { |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2311 | struct intel_rotation_info *info = &view->rotation_info; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2312 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2313 | *view = i915_ggtt_view_normal; |
| 2314 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2315 | if (!plane_state) |
| 2316 | return 0; |
| 2317 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2318 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2319 | return 0; |
| 2320 | |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2321 | *view = i915_ggtt_view_rotated; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2322 | |
| 2323 | info->height = fb->height; |
| 2324 | info->pixel_format = fb->pixel_format; |
| 2325 | info->pitch = fb->pitches[0]; |
| 2326 | info->fb_modifier = fb->modifier[0]; |
| 2327 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2328 | return 0; |
| 2329 | } |
| 2330 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2331 | int |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2332 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
| 2333 | struct drm_framebuffer *fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2334 | const struct drm_plane_state *plane_state, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2335 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2336 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2337 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2338 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2339 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2340 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2341 | u32 alignment; |
| 2342 | int ret; |
| 2343 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2344 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2345 | |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2346 | switch (fb->modifier[0]) { |
| 2347 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2348 | if (INTEL_INFO(dev)->gen >= 9) |
| 2349 | alignment = 256 * 1024; |
| 2350 | else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2351 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2352 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2353 | alignment = 4 * 1024; |
| 2354 | else |
| 2355 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2356 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2357 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2358 | if (INTEL_INFO(dev)->gen >= 9) |
| 2359 | alignment = 256 * 1024; |
| 2360 | else { |
| 2361 | /* pin() will align the object as required by fence */ |
| 2362 | alignment = 0; |
| 2363 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2364 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2365 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | 1327b9a | 2015-02-27 11:15:20 +0000 | [diff] [blame] | 2366 | case I915_FORMAT_MOD_Yf_TILED: |
| 2367 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, |
| 2368 | "Y tiling bo slipped through, driver bug!\n")) |
| 2369 | return -EINVAL; |
| 2370 | alignment = 1 * 1024 * 1024; |
| 2371 | break; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2372 | default: |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2373 | MISSING_CASE(fb->modifier[0]); |
| 2374 | return -EINVAL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2375 | } |
| 2376 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2377 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2378 | if (ret) |
| 2379 | return ret; |
| 2380 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2381 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2382 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2383 | * we should always have valid PTE following the scanout preventing |
| 2384 | * the VT-d warning. |
| 2385 | */ |
| 2386 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2387 | alignment = 256 * 1024; |
| 2388 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2389 | /* |
| 2390 | * Global gtt pte registers are special registers which actually forward |
| 2391 | * writes to a chunk of system memory. Which means that there is no risk |
| 2392 | * that the register values disappear as soon as we call |
| 2393 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2394 | * pin/unpin/fence and not more. |
| 2395 | */ |
| 2396 | intel_runtime_pm_get(dev_priv); |
| 2397 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2398 | dev_priv->mm.interruptible = false; |
Tvrtko Ursulin | e661733 | 2015-03-23 11:10:33 +0000 | [diff] [blame] | 2399 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2400 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2401 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2402 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2403 | |
| 2404 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2405 | * fence, whereas 965+ only requires a fence if using |
| 2406 | * framebuffer compression. For simplicity, we always install |
| 2407 | * a fence as the cost is not that onerous. |
| 2408 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2409 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2410 | if (ret) |
| 2411 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2412 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2413 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2414 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2415 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2416 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2417 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2418 | |
| 2419 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2420 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2421 | err_interruptible: |
| 2422 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2423 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2424 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2425 | } |
| 2426 | |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2427 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
| 2428 | const struct drm_plane_state *plane_state) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2429 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2430 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2431 | struct i915_ggtt_view view; |
| 2432 | int ret; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2433 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2434 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2435 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2436 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2437 | WARN_ONCE(ret, "Couldn't get view from plane state!"); |
| 2438 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2439 | i915_gem_object_unpin_fence(obj); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2440 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2441 | } |
| 2442 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2443 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2444 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2445 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 2446 | unsigned int tiling_mode, |
| 2447 | unsigned int cpp, |
| 2448 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2449 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2450 | if (tiling_mode != I915_TILING_NONE) { |
| 2451 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2452 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2453 | tile_rows = *y / 8; |
| 2454 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2455 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2456 | tiles = *x / (512/cpp); |
| 2457 | *x %= 512/cpp; |
| 2458 | |
| 2459 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2460 | } else { |
| 2461 | unsigned int offset; |
| 2462 | |
| 2463 | offset = *y * pitch + *x * cpp; |
| 2464 | *y = 0; |
| 2465 | *x = (offset & 4095) / cpp; |
| 2466 | return offset & -4096; |
| 2467 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2468 | } |
| 2469 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2470 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2471 | { |
| 2472 | switch (format) { |
| 2473 | case DISPPLANE_8BPP: |
| 2474 | return DRM_FORMAT_C8; |
| 2475 | case DISPPLANE_BGRX555: |
| 2476 | return DRM_FORMAT_XRGB1555; |
| 2477 | case DISPPLANE_BGRX565: |
| 2478 | return DRM_FORMAT_RGB565; |
| 2479 | default: |
| 2480 | case DISPPLANE_BGRX888: |
| 2481 | return DRM_FORMAT_XRGB8888; |
| 2482 | case DISPPLANE_RGBX888: |
| 2483 | return DRM_FORMAT_XBGR8888; |
| 2484 | case DISPPLANE_BGRX101010: |
| 2485 | return DRM_FORMAT_XRGB2101010; |
| 2486 | case DISPPLANE_RGBX101010: |
| 2487 | return DRM_FORMAT_XBGR2101010; |
| 2488 | } |
| 2489 | } |
| 2490 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2491 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2492 | { |
| 2493 | switch (format) { |
| 2494 | case PLANE_CTL_FORMAT_RGB_565: |
| 2495 | return DRM_FORMAT_RGB565; |
| 2496 | default: |
| 2497 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2498 | if (rgb_order) { |
| 2499 | if (alpha) |
| 2500 | return DRM_FORMAT_ABGR8888; |
| 2501 | else |
| 2502 | return DRM_FORMAT_XBGR8888; |
| 2503 | } else { |
| 2504 | if (alpha) |
| 2505 | return DRM_FORMAT_ARGB8888; |
| 2506 | else |
| 2507 | return DRM_FORMAT_XRGB8888; |
| 2508 | } |
| 2509 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2510 | if (rgb_order) |
| 2511 | return DRM_FORMAT_XBGR2101010; |
| 2512 | else |
| 2513 | return DRM_FORMAT_XRGB2101010; |
| 2514 | } |
| 2515 | } |
| 2516 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2517 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2518 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2519 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2520 | { |
| 2521 | struct drm_device *dev = crtc->base.dev; |
| 2522 | struct drm_i915_gem_object *obj = NULL; |
| 2523 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2524 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2525 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2526 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2527 | PAGE_SIZE); |
| 2528 | |
| 2529 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2530 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2531 | if (plane_config->size == 0) |
| 2532 | return false; |
| 2533 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2534 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2535 | base_aligned, |
| 2536 | base_aligned, |
| 2537 | size_aligned); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2538 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2539 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2540 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2541 | obj->tiling_mode = plane_config->tiling; |
| 2542 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2543 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2544 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2545 | mode_cmd.pixel_format = fb->pixel_format; |
| 2546 | mode_cmd.width = fb->width; |
| 2547 | mode_cmd.height = fb->height; |
| 2548 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2549 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2550 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2551 | |
| 2552 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2553 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2554 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2555 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2556 | goto out_unref_obj; |
| 2557 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2558 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2559 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2560 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2561 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2562 | |
| 2563 | out_unref_obj: |
| 2564 | drm_gem_object_unreference(&obj->base); |
| 2565 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2566 | return false; |
| 2567 | } |
| 2568 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2569 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2570 | static void |
| 2571 | update_state_fb(struct drm_plane *plane) |
| 2572 | { |
| 2573 | if (plane->fb == plane->state->fb) |
| 2574 | return; |
| 2575 | |
| 2576 | if (plane->state->fb) |
| 2577 | drm_framebuffer_unreference(plane->state->fb); |
| 2578 | plane->state->fb = plane->fb; |
| 2579 | if (plane->state->fb) |
| 2580 | drm_framebuffer_reference(plane->state->fb); |
| 2581 | } |
| 2582 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2583 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2584 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2585 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2586 | { |
| 2587 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2588 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2589 | struct drm_crtc *c; |
| 2590 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2591 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2592 | struct drm_plane *primary = intel_crtc->base.primary; |
| 2593 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2594 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2595 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2596 | return; |
| 2597 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2598 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2599 | fb = &plane_config->fb->base; |
| 2600 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2601 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2602 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2603 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2604 | |
| 2605 | /* |
| 2606 | * Failed to alloc the obj, check to see if we should share |
| 2607 | * an fb with another CRTC instead |
| 2608 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2609 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2610 | i = to_intel_crtc(c); |
| 2611 | |
| 2612 | if (c == &intel_crtc->base) |
| 2613 | continue; |
| 2614 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2615 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2616 | continue; |
| 2617 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2618 | fb = c->primary->fb; |
| 2619 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2620 | continue; |
| 2621 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2622 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2623 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2624 | drm_framebuffer_reference(fb); |
| 2625 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2626 | } |
| 2627 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2628 | |
| 2629 | return; |
| 2630 | |
| 2631 | valid_fb: |
| 2632 | obj = intel_fb_obj(fb); |
| 2633 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2634 | dev_priv->preserve_bios_swizzle = true; |
| 2635 | |
| 2636 | primary->fb = fb; |
| 2637 | primary->state->crtc = &intel_crtc->base; |
| 2638 | primary->crtc = &intel_crtc->base; |
| 2639 | update_state_fb(primary); |
| 2640 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2641 | } |
| 2642 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2643 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2644 | struct drm_framebuffer *fb, |
| 2645 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2646 | { |
| 2647 | struct drm_device *dev = crtc->dev; |
| 2648 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2649 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2650 | struct drm_plane *primary = crtc->primary; |
| 2651 | bool visible = to_intel_plane_state(primary->state)->visible; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2652 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2653 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2654 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2655 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2656 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2657 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2658 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2659 | if (!visible || !fb) { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2660 | I915_WRITE(reg, 0); |
| 2661 | if (INTEL_INFO(dev)->gen >= 4) |
| 2662 | I915_WRITE(DSPSURF(plane), 0); |
| 2663 | else |
| 2664 | I915_WRITE(DSPADDR(plane), 0); |
| 2665 | POSTING_READ(reg); |
| 2666 | return; |
| 2667 | } |
| 2668 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2669 | obj = intel_fb_obj(fb); |
| 2670 | if (WARN_ON(obj == NULL)) |
| 2671 | return; |
| 2672 | |
| 2673 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2674 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2675 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2676 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2677 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2678 | |
| 2679 | if (INTEL_INFO(dev)->gen < 4) { |
| 2680 | if (intel_crtc->pipe == PIPE_B) |
| 2681 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2682 | |
| 2683 | /* pipesrc and dspsize control the size that is scaled from, |
| 2684 | * which should always be the user's requested size. |
| 2685 | */ |
| 2686 | I915_WRITE(DSPSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2687 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2688 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2689 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2690 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2691 | I915_WRITE(PRIMSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2692 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2693 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2694 | I915_WRITE(PRIMPOS(plane), 0); |
| 2695 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2696 | } |
| 2697 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2698 | switch (fb->pixel_format) { |
| 2699 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2700 | dspcntr |= DISPPLANE_8BPP; |
| 2701 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2702 | case DRM_FORMAT_XRGB1555: |
| 2703 | case DRM_FORMAT_ARGB1555: |
| 2704 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2705 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2706 | case DRM_FORMAT_RGB565: |
| 2707 | dspcntr |= DISPPLANE_BGRX565; |
| 2708 | break; |
| 2709 | case DRM_FORMAT_XRGB8888: |
| 2710 | case DRM_FORMAT_ARGB8888: |
| 2711 | dspcntr |= DISPPLANE_BGRX888; |
| 2712 | break; |
| 2713 | case DRM_FORMAT_XBGR8888: |
| 2714 | case DRM_FORMAT_ABGR8888: |
| 2715 | dspcntr |= DISPPLANE_RGBX888; |
| 2716 | break; |
| 2717 | case DRM_FORMAT_XRGB2101010: |
| 2718 | case DRM_FORMAT_ARGB2101010: |
| 2719 | dspcntr |= DISPPLANE_BGRX101010; |
| 2720 | break; |
| 2721 | case DRM_FORMAT_XBGR2101010: |
| 2722 | case DRM_FORMAT_ABGR2101010: |
| 2723 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2724 | break; |
| 2725 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2726 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2727 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2728 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2729 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2730 | obj->tiling_mode != I915_TILING_NONE) |
| 2731 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2732 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2733 | if (IS_G4X(dev)) |
| 2734 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2735 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2736 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2737 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2738 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2739 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2740 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2741 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2742 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2743 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2744 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2745 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2746 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2747 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2748 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2749 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2750 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2751 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2752 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2753 | |
| 2754 | /* Finding the last pixel of the last line of the display |
| 2755 | data and adding to linear_offset*/ |
| 2756 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2757 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2758 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | I915_WRITE(reg, dspcntr); |
| 2762 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2763 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2764 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2765 | I915_WRITE(DSPSURF(plane), |
| 2766 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2767 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2768 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2769 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2770 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2771 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2774 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2775 | struct drm_framebuffer *fb, |
| 2776 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2777 | { |
| 2778 | struct drm_device *dev = crtc->dev; |
| 2779 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2780 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2781 | struct drm_plane *primary = crtc->primary; |
| 2782 | bool visible = to_intel_plane_state(primary->state)->visible; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2783 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2784 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2785 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2786 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2787 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2788 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2789 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2790 | if (!visible || !fb) { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2791 | I915_WRITE(reg, 0); |
| 2792 | I915_WRITE(DSPSURF(plane), 0); |
| 2793 | POSTING_READ(reg); |
| 2794 | return; |
| 2795 | } |
| 2796 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2797 | obj = intel_fb_obj(fb); |
| 2798 | if (WARN_ON(obj == NULL)) |
| 2799 | return; |
| 2800 | |
| 2801 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2802 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2803 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2804 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2805 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2806 | |
| 2807 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2808 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2809 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2810 | switch (fb->pixel_format) { |
| 2811 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2812 | dspcntr |= DISPPLANE_8BPP; |
| 2813 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2814 | case DRM_FORMAT_RGB565: |
| 2815 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2816 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2817 | case DRM_FORMAT_XRGB8888: |
| 2818 | case DRM_FORMAT_ARGB8888: |
| 2819 | dspcntr |= DISPPLANE_BGRX888; |
| 2820 | break; |
| 2821 | case DRM_FORMAT_XBGR8888: |
| 2822 | case DRM_FORMAT_ABGR8888: |
| 2823 | dspcntr |= DISPPLANE_RGBX888; |
| 2824 | break; |
| 2825 | case DRM_FORMAT_XRGB2101010: |
| 2826 | case DRM_FORMAT_ARGB2101010: |
| 2827 | dspcntr |= DISPPLANE_BGRX101010; |
| 2828 | break; |
| 2829 | case DRM_FORMAT_XBGR2101010: |
| 2830 | case DRM_FORMAT_ABGR2101010: |
| 2831 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2832 | break; |
| 2833 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2834 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2838 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2839 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2840 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2841 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2842 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2843 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2844 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2845 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2846 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2847 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2848 | linear_offset -= intel_crtc->dspaddr_offset; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2849 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2850 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2851 | |
| 2852 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2853 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2854 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2855 | |
| 2856 | /* Finding the last pixel of the last line of the display |
| 2857 | data and adding to linear_offset*/ |
| 2858 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2859 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2860 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2865 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2866 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2867 | I915_WRITE(DSPSURF(plane), |
| 2868 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2869 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2870 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2871 | } else { |
| 2872 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2873 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2874 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2875 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2878 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
| 2879 | uint32_t pixel_format) |
| 2880 | { |
| 2881 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; |
| 2882 | |
| 2883 | /* |
| 2884 | * The stride is either expressed as a multiple of 64 bytes |
| 2885 | * chunks for linear buffers or in number of tiles for tiled |
| 2886 | * buffers. |
| 2887 | */ |
| 2888 | switch (fb_modifier) { |
| 2889 | case DRM_FORMAT_MOD_NONE: |
| 2890 | return 64; |
| 2891 | case I915_FORMAT_MOD_X_TILED: |
| 2892 | if (INTEL_INFO(dev)->gen == 2) |
| 2893 | return 128; |
| 2894 | return 512; |
| 2895 | case I915_FORMAT_MOD_Y_TILED: |
| 2896 | /* No need to check for old gens and Y tiling since this is |
| 2897 | * about the display engine and those will be blocked before |
| 2898 | * we get here. |
| 2899 | */ |
| 2900 | return 128; |
| 2901 | case I915_FORMAT_MOD_Yf_TILED: |
| 2902 | if (bits_per_pixel == 8) |
| 2903 | return 64; |
| 2904 | else |
| 2905 | return 128; |
| 2906 | default: |
| 2907 | MISSING_CASE(fb_modifier); |
| 2908 | return 64; |
| 2909 | } |
| 2910 | } |
| 2911 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2912 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2913 | struct drm_i915_gem_object *obj) |
| 2914 | { |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2915 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2916 | |
| 2917 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2918 | view = &i915_ggtt_view_rotated; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2919 | |
| 2920 | return i915_gem_obj_ggtt_offset_view(obj, view); |
| 2921 | } |
| 2922 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2923 | /* |
| 2924 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 2925 | */ |
| 2926 | void skl_detach_scalers(struct intel_crtc *intel_crtc) |
| 2927 | { |
| 2928 | struct drm_device *dev; |
| 2929 | struct drm_i915_private *dev_priv; |
| 2930 | struct intel_crtc_scaler_state *scaler_state; |
| 2931 | int i; |
| 2932 | |
| 2933 | if (!intel_crtc || !intel_crtc->config) |
| 2934 | return; |
| 2935 | |
| 2936 | dev = intel_crtc->base.dev; |
| 2937 | dev_priv = dev->dev_private; |
| 2938 | scaler_state = &intel_crtc->config->scaler_state; |
| 2939 | |
| 2940 | /* loop through and disable scalers that aren't in use */ |
| 2941 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 2942 | if (!scaler_state->scalers[i].in_use) { |
| 2943 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, i), 0); |
| 2944 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, i), 0); |
| 2945 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, i), 0); |
| 2946 | DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n", |
| 2947 | intel_crtc->base.base.id, intel_crtc->pipe, i); |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2952 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 2953 | { |
| 2954 | u32 plane_ctl_format = 0; |
| 2955 | switch (pixel_format) { |
| 2956 | case DRM_FORMAT_RGB565: |
| 2957 | plane_ctl_format = PLANE_CTL_FORMAT_RGB_565; |
| 2958 | break; |
| 2959 | case DRM_FORMAT_XBGR8888: |
| 2960 | plane_ctl_format = PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
| 2961 | break; |
| 2962 | case DRM_FORMAT_XRGB8888: |
| 2963 | plane_ctl_format = PLANE_CTL_FORMAT_XRGB_8888; |
| 2964 | break; |
| 2965 | /* |
| 2966 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 2967 | * to be already pre-multiplied. We need to add a knob (or a different |
| 2968 | * DRM_FORMAT) for user-space to configure that. |
| 2969 | */ |
| 2970 | case DRM_FORMAT_ABGR8888: |
| 2971 | plane_ctl_format = PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
| 2972 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2973 | break; |
| 2974 | case DRM_FORMAT_ARGB8888: |
| 2975 | plane_ctl_format = PLANE_CTL_FORMAT_XRGB_8888 | |
| 2976 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2977 | break; |
| 2978 | case DRM_FORMAT_XRGB2101010: |
| 2979 | plane_ctl_format = PLANE_CTL_FORMAT_XRGB_2101010; |
| 2980 | break; |
| 2981 | case DRM_FORMAT_XBGR2101010: |
| 2982 | plane_ctl_format = PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
| 2983 | break; |
| 2984 | case DRM_FORMAT_YUYV: |
| 2985 | plane_ctl_format = PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
| 2986 | break; |
| 2987 | case DRM_FORMAT_YVYU: |
| 2988 | plane_ctl_format = PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
| 2989 | break; |
| 2990 | case DRM_FORMAT_UYVY: |
| 2991 | plane_ctl_format = PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
| 2992 | break; |
| 2993 | case DRM_FORMAT_VYUY: |
| 2994 | plane_ctl_format = PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
| 2995 | break; |
| 2996 | default: |
| 2997 | BUG(); |
| 2998 | } |
| 2999 | return plane_ctl_format; |
| 3000 | } |
| 3001 | |
| 3002 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 3003 | { |
| 3004 | u32 plane_ctl_tiling = 0; |
| 3005 | switch (fb_modifier) { |
| 3006 | case DRM_FORMAT_MOD_NONE: |
| 3007 | break; |
| 3008 | case I915_FORMAT_MOD_X_TILED: |
| 3009 | plane_ctl_tiling = PLANE_CTL_TILED_X; |
| 3010 | break; |
| 3011 | case I915_FORMAT_MOD_Y_TILED: |
| 3012 | plane_ctl_tiling = PLANE_CTL_TILED_Y; |
| 3013 | break; |
| 3014 | case I915_FORMAT_MOD_Yf_TILED: |
| 3015 | plane_ctl_tiling = PLANE_CTL_TILED_YF; |
| 3016 | break; |
| 3017 | default: |
| 3018 | MISSING_CASE(fb_modifier); |
| 3019 | } |
| 3020 | return plane_ctl_tiling; |
| 3021 | } |
| 3022 | |
| 3023 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 3024 | { |
| 3025 | u32 plane_ctl_rotation = 0; |
| 3026 | switch (rotation) { |
| 3027 | case BIT(DRM_ROTATE_0): |
| 3028 | break; |
| 3029 | case BIT(DRM_ROTATE_90): |
| 3030 | plane_ctl_rotation = PLANE_CTL_ROTATE_90; |
| 3031 | break; |
| 3032 | case BIT(DRM_ROTATE_180): |
| 3033 | plane_ctl_rotation = PLANE_CTL_ROTATE_180; |
| 3034 | break; |
| 3035 | case BIT(DRM_ROTATE_270): |
| 3036 | plane_ctl_rotation = PLANE_CTL_ROTATE_270; |
| 3037 | break; |
| 3038 | default: |
| 3039 | MISSING_CASE(rotation); |
| 3040 | } |
| 3041 | |
| 3042 | return plane_ctl_rotation; |
| 3043 | } |
| 3044 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3045 | static void skylake_update_primary_plane(struct drm_crtc *crtc, |
| 3046 | struct drm_framebuffer *fb, |
| 3047 | int x, int y) |
| 3048 | { |
| 3049 | struct drm_device *dev = crtc->dev; |
| 3050 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3051 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 3052 | struct drm_plane *plane = crtc->primary; |
| 3053 | bool visible = to_intel_plane_state(plane->state)->visible; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3054 | struct drm_i915_gem_object *obj; |
| 3055 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3056 | u32 plane_ctl, stride_div, stride; |
| 3057 | u32 tile_height, plane_offset, plane_size; |
| 3058 | unsigned int rotation; |
| 3059 | int x_offset, y_offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3060 | unsigned long surf_addr; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3061 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
| 3062 | struct intel_plane_state *plane_state; |
| 3063 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; |
| 3064 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; |
| 3065 | int scaler_id = -1; |
| 3066 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3067 | plane_state = to_intel_plane_state(plane->state); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3068 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 3069 | if (!visible || !fb) { |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3070 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 3071 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 3072 | POSTING_READ(PLANE_CTL(pipe, 0)); |
| 3073 | return; |
| 3074 | } |
| 3075 | |
| 3076 | plane_ctl = PLANE_CTL_ENABLE | |
| 3077 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3078 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 3079 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3080 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
| 3081 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3082 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3083 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3084 | rotation = plane->state->rotation; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3085 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3086 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3087 | obj = intel_fb_obj(fb); |
| 3088 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 3089 | fb->pixel_format); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3090 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
| 3091 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3092 | /* |
| 3093 | * FIXME: intel_plane_state->src, dst aren't set when transitional |
| 3094 | * update_plane helpers are called from legacy paths. |
| 3095 | * Once full atomic crtc is available, below check can be avoided. |
| 3096 | */ |
| 3097 | if (drm_rect_width(&plane_state->src)) { |
| 3098 | scaler_id = plane_state->scaler_id; |
| 3099 | src_x = plane_state->src.x1 >> 16; |
| 3100 | src_y = plane_state->src.y1 >> 16; |
| 3101 | src_w = drm_rect_width(&plane_state->src) >> 16; |
| 3102 | src_h = drm_rect_height(&plane_state->src) >> 16; |
| 3103 | dst_x = plane_state->dst.x1; |
| 3104 | dst_y = plane_state->dst.y1; |
| 3105 | dst_w = drm_rect_width(&plane_state->dst); |
| 3106 | dst_h = drm_rect_height(&plane_state->dst); |
| 3107 | |
| 3108 | WARN_ON(x != src_x || y != src_y); |
| 3109 | } else { |
| 3110 | src_w = intel_crtc->config->pipe_src_w; |
| 3111 | src_h = intel_crtc->config->pipe_src_h; |
| 3112 | } |
| 3113 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3114 | if (intel_rotation_90_or_270(rotation)) { |
| 3115 | /* stride = Surface height in tiles */ |
| 3116 | tile_height = intel_tile_height(dev, fb->bits_per_pixel, |
| 3117 | fb->modifier[0]); |
| 3118 | stride = DIV_ROUND_UP(fb->height, tile_height); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3119 | x_offset = stride * tile_height - y - src_h; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3120 | y_offset = x; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3121 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3122 | } else { |
| 3123 | stride = fb->pitches[0] / stride_div; |
| 3124 | x_offset = x; |
| 3125 | y_offset = y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3126 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3127 | } |
| 3128 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3129 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3130 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3131 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3132 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3133 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3134 | |
| 3135 | if (scaler_id >= 0) { |
| 3136 | uint32_t ps_ctrl = 0; |
| 3137 | |
| 3138 | WARN_ON(!dst_w || !dst_h); |
| 3139 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | |
| 3140 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3141 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3142 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3143 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3144 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
| 3145 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3146 | } else { |
| 3147 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); |
| 3148 | } |
| 3149 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3150 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3151 | |
| 3152 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3153 | } |
| 3154 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3155 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3156 | static int |
| 3157 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3158 | int x, int y, enum mode_set_atomic state) |
| 3159 | { |
| 3160 | struct drm_device *dev = crtc->dev; |
| 3161 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3162 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 3163 | if (dev_priv->display.disable_fbc) |
| 3164 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3165 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 3166 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 3167 | |
| 3168 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3171 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3172 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3173 | struct drm_crtc *crtc; |
| 3174 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3175 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3176 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3177 | enum plane plane = intel_crtc->plane; |
| 3178 | |
| 3179 | intel_prepare_page_flip(dev, plane); |
| 3180 | intel_finish_page_flip_plane(dev, plane); |
| 3181 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3185 | { |
| 3186 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3187 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3188 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3189 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3191 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3192 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3193 | /* |
| 3194 | * FIXME: Once we have proper support for primary planes (and |
| 3195 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3196 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3197 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 3198 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3199 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3200 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3201 | crtc->x, |
| 3202 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3203 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 3207 | void intel_crtc_reset(struct intel_crtc *crtc) |
| 3208 | { |
| 3209 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3210 | |
| 3211 | if (!crtc->active) |
| 3212 | return; |
| 3213 | |
| 3214 | intel_crtc_disable_planes(&crtc->base); |
| 3215 | dev_priv->display.crtc_disable(&crtc->base); |
| 3216 | dev_priv->display.crtc_enable(&crtc->base); |
| 3217 | intel_crtc_enable_planes(&crtc->base); |
| 3218 | } |
| 3219 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3220 | void intel_prepare_reset(struct drm_device *dev) |
| 3221 | { |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3222 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3223 | struct intel_crtc *crtc; |
| 3224 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3225 | /* no reset support for gen2 */ |
| 3226 | if (IS_GEN2(dev)) |
| 3227 | return; |
| 3228 | |
| 3229 | /* reset doesn't touch the display */ |
| 3230 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3231 | return; |
| 3232 | |
| 3233 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3234 | |
| 3235 | /* |
| 3236 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3237 | * g33 docs say we should at least disable all the planes. |
| 3238 | */ |
| 3239 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 3240 | if (!crtc->active) |
| 3241 | continue; |
| 3242 | |
| 3243 | intel_crtc_disable_planes(&crtc->base); |
| 3244 | dev_priv->display.crtc_disable(&crtc->base); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3245 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | void intel_finish_reset(struct drm_device *dev) |
| 3249 | { |
| 3250 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3251 | |
| 3252 | /* |
| 3253 | * Flips in the rings will be nuked by the reset, |
| 3254 | * so complete all pending flips so that user space |
| 3255 | * will get its events and not get stuck. |
| 3256 | */ |
| 3257 | intel_complete_page_flips(dev); |
| 3258 | |
| 3259 | /* no reset support for gen2 */ |
| 3260 | if (IS_GEN2(dev)) |
| 3261 | return; |
| 3262 | |
| 3263 | /* reset doesn't touch the display */ |
| 3264 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3265 | /* |
| 3266 | * Flips in the rings have been nuked by the reset, |
| 3267 | * so update the base address of all primary |
| 3268 | * planes to the the last fb to make sure we're |
| 3269 | * showing the correct fb after a reset. |
| 3270 | */ |
| 3271 | intel_update_primary_planes(dev); |
| 3272 | return; |
| 3273 | } |
| 3274 | |
| 3275 | /* |
| 3276 | * The display has been reset as well, |
| 3277 | * so need a full re-initialization. |
| 3278 | */ |
| 3279 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3280 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3281 | |
| 3282 | intel_modeset_init_hw(dev); |
| 3283 | |
| 3284 | spin_lock_irq(&dev_priv->irq_lock); |
| 3285 | if (dev_priv->display.hpd_irq_setup) |
| 3286 | dev_priv->display.hpd_irq_setup(dev); |
| 3287 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3288 | |
| 3289 | intel_modeset_setup_hw_state(dev, true); |
| 3290 | |
| 3291 | intel_hpd_init(dev_priv); |
| 3292 | |
| 3293 | drm_modeset_unlock_all(dev); |
| 3294 | } |
| 3295 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 3296 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3297 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 3298 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 3299 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3300 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 3301 | bool was_interruptible = dev_priv->mm.interruptible; |
| 3302 | int ret; |
| 3303 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3304 | /* Big Hammer, we also need to ensure that any pending |
| 3305 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 3306 | * current scanout is retired before unpinning the old |
| 3307 | * framebuffer. |
| 3308 | * |
| 3309 | * This should only fail upon a hung GPU, in which case we |
| 3310 | * can safely continue. |
| 3311 | */ |
| 3312 | dev_priv->mm.interruptible = false; |
| 3313 | ret = i915_gem_object_finish_gpu(obj); |
| 3314 | dev_priv->mm.interruptible = was_interruptible; |
| 3315 | |
| 3316 | return ret; |
| 3317 | } |
| 3318 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3319 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3320 | { |
| 3321 | struct drm_device *dev = crtc->dev; |
| 3322 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3323 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3324 | bool pending; |
| 3325 | |
| 3326 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3327 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3328 | return false; |
| 3329 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3330 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3331 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3332 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3333 | |
| 3334 | return pending; |
| 3335 | } |
| 3336 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3337 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 3338 | { |
| 3339 | struct drm_device *dev = crtc->base.dev; |
| 3340 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3341 | const struct drm_display_mode *adjusted_mode; |
| 3342 | |
| 3343 | if (!i915.fastboot) |
| 3344 | return; |
| 3345 | |
| 3346 | /* |
| 3347 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3348 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3349 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3350 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3351 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3352 | * sized surface. |
| 3353 | * |
| 3354 | * To fix this properly, we need to hoist the checks up into |
| 3355 | * compute_mode_changes (or above), check the actual pfit state and |
| 3356 | * whether the platform allows pfit disable with pipe active, and only |
| 3357 | * then update the pipesrc and pfit state, even on the flip path. |
| 3358 | */ |
| 3359 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3360 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3361 | |
| 3362 | I915_WRITE(PIPESRC(crtc->pipe), |
| 3363 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 3364 | (adjusted_mode->crtc_vdisplay - 1)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3365 | if (!crtc->config->pch_pfit.enabled && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 3366 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3367 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3368 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 3369 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 3370 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 3371 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3372 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 3373 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3374 | } |
| 3375 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3376 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3377 | { |
| 3378 | struct drm_device *dev = crtc->dev; |
| 3379 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3380 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3381 | int pipe = intel_crtc->pipe; |
| 3382 | u32 reg, temp; |
| 3383 | |
| 3384 | /* enable normal train */ |
| 3385 | reg = FDI_TX_CTL(pipe); |
| 3386 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3387 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3388 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3389 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3390 | } else { |
| 3391 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3392 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3393 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3394 | I915_WRITE(reg, temp); |
| 3395 | |
| 3396 | reg = FDI_RX_CTL(pipe); |
| 3397 | temp = I915_READ(reg); |
| 3398 | if (HAS_PCH_CPT(dev)) { |
| 3399 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3400 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3401 | } else { |
| 3402 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3403 | temp |= FDI_LINK_TRAIN_NONE; |
| 3404 | } |
| 3405 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3406 | |
| 3407 | /* wait one idle pattern time */ |
| 3408 | POSTING_READ(reg); |
| 3409 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3410 | |
| 3411 | /* IVB wants error correction enabled */ |
| 3412 | if (IS_IVYBRIDGE(dev)) |
| 3413 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3414 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3415 | } |
| 3416 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3417 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3418 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3419 | { |
| 3420 | struct drm_device *dev = crtc->dev; |
| 3421 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3422 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3423 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3424 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3425 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3426 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3427 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3428 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3429 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3430 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3431 | reg = FDI_RX_IMR(pipe); |
| 3432 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3433 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3434 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3435 | I915_WRITE(reg, temp); |
| 3436 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3437 | udelay(150); |
| 3438 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3439 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3440 | reg = FDI_TX_CTL(pipe); |
| 3441 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3442 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3443 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3444 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3445 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3446 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3447 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3448 | reg = FDI_RX_CTL(pipe); |
| 3449 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3450 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3451 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3452 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3453 | |
| 3454 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3455 | udelay(150); |
| 3456 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3457 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3458 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3459 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3460 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3461 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3462 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3463 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3464 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3465 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3466 | |
| 3467 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3468 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3469 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3470 | break; |
| 3471 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3472 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3473 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3474 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3475 | |
| 3476 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3477 | reg = FDI_TX_CTL(pipe); |
| 3478 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3479 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3480 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3481 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3482 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3483 | reg = FDI_RX_CTL(pipe); |
| 3484 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3485 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3486 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3487 | I915_WRITE(reg, temp); |
| 3488 | |
| 3489 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3490 | udelay(150); |
| 3491 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3492 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3493 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3494 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3495 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3496 | |
| 3497 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3498 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3499 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3500 | break; |
| 3501 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3502 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3503 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3504 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3505 | |
| 3506 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3507 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3508 | } |
| 3509 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3510 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3511 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3512 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3513 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3514 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3515 | }; |
| 3516 | |
| 3517 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3518 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3519 | { |
| 3520 | struct drm_device *dev = crtc->dev; |
| 3521 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3522 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3523 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3524 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3525 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3526 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3527 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3528 | reg = FDI_RX_IMR(pipe); |
| 3529 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3530 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3531 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3532 | I915_WRITE(reg, temp); |
| 3533 | |
| 3534 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3535 | udelay(150); |
| 3536 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3537 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3538 | reg = FDI_TX_CTL(pipe); |
| 3539 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3540 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3541 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3542 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3543 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3544 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3545 | /* SNB-B */ |
| 3546 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3547 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3548 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3549 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3550 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3551 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3552 | reg = FDI_RX_CTL(pipe); |
| 3553 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3554 | if (HAS_PCH_CPT(dev)) { |
| 3555 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3556 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3557 | } else { |
| 3558 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3559 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3560 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3561 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3562 | |
| 3563 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3564 | udelay(150); |
| 3565 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3566 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3567 | reg = FDI_TX_CTL(pipe); |
| 3568 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3569 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3570 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3571 | I915_WRITE(reg, temp); |
| 3572 | |
| 3573 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3574 | udelay(500); |
| 3575 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3576 | for (retry = 0; retry < 5; retry++) { |
| 3577 | reg = FDI_RX_IIR(pipe); |
| 3578 | temp = I915_READ(reg); |
| 3579 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3580 | if (temp & FDI_RX_BIT_LOCK) { |
| 3581 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3582 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3583 | break; |
| 3584 | } |
| 3585 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3586 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3587 | if (retry < 5) |
| 3588 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3589 | } |
| 3590 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3591 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3592 | |
| 3593 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3594 | reg = FDI_TX_CTL(pipe); |
| 3595 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3596 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3597 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3598 | if (IS_GEN6(dev)) { |
| 3599 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3600 | /* SNB-B */ |
| 3601 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3602 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3603 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3604 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3605 | reg = FDI_RX_CTL(pipe); |
| 3606 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3607 | if (HAS_PCH_CPT(dev)) { |
| 3608 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3609 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3610 | } else { |
| 3611 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3612 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3613 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3614 | I915_WRITE(reg, temp); |
| 3615 | |
| 3616 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3617 | udelay(150); |
| 3618 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3619 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3620 | reg = FDI_TX_CTL(pipe); |
| 3621 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3622 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3623 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3624 | I915_WRITE(reg, temp); |
| 3625 | |
| 3626 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3627 | udelay(500); |
| 3628 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3629 | for (retry = 0; retry < 5; retry++) { |
| 3630 | reg = FDI_RX_IIR(pipe); |
| 3631 | temp = I915_READ(reg); |
| 3632 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3633 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3634 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3635 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3636 | break; |
| 3637 | } |
| 3638 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3639 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3640 | if (retry < 5) |
| 3641 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3642 | } |
| 3643 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3644 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3645 | |
| 3646 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3647 | } |
| 3648 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3649 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3650 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3651 | { |
| 3652 | struct drm_device *dev = crtc->dev; |
| 3653 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3654 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3655 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3656 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3657 | |
| 3658 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3659 | for train result */ |
| 3660 | reg = FDI_RX_IMR(pipe); |
| 3661 | temp = I915_READ(reg); |
| 3662 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3663 | temp &= ~FDI_RX_BIT_LOCK; |
| 3664 | I915_WRITE(reg, temp); |
| 3665 | |
| 3666 | POSTING_READ(reg); |
| 3667 | udelay(150); |
| 3668 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3669 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3670 | I915_READ(FDI_RX_IIR(pipe))); |
| 3671 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3672 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3673 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3674 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3675 | reg = FDI_TX_CTL(pipe); |
| 3676 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3677 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3678 | temp &= ~FDI_TX_ENABLE; |
| 3679 | I915_WRITE(reg, temp); |
| 3680 | |
| 3681 | reg = FDI_RX_CTL(pipe); |
| 3682 | temp = I915_READ(reg); |
| 3683 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3684 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3685 | temp &= ~FDI_RX_ENABLE; |
| 3686 | I915_WRITE(reg, temp); |
| 3687 | |
| 3688 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3689 | reg = FDI_TX_CTL(pipe); |
| 3690 | temp = I915_READ(reg); |
| 3691 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3692 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3693 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3694 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3695 | temp |= snb_b_fdi_train_param[j/2]; |
| 3696 | temp |= FDI_COMPOSITE_SYNC; |
| 3697 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3698 | |
| 3699 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3700 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3701 | |
| 3702 | reg = FDI_RX_CTL(pipe); |
| 3703 | temp = I915_READ(reg); |
| 3704 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3705 | temp |= FDI_COMPOSITE_SYNC; |
| 3706 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3707 | |
| 3708 | POSTING_READ(reg); |
| 3709 | udelay(1); /* should be 0.5us */ |
| 3710 | |
| 3711 | for (i = 0; i < 4; i++) { |
| 3712 | reg = FDI_RX_IIR(pipe); |
| 3713 | temp = I915_READ(reg); |
| 3714 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3715 | |
| 3716 | if (temp & FDI_RX_BIT_LOCK || |
| 3717 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3718 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3719 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3720 | i); |
| 3721 | break; |
| 3722 | } |
| 3723 | udelay(1); /* should be 0.5us */ |
| 3724 | } |
| 3725 | if (i == 4) { |
| 3726 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3727 | continue; |
| 3728 | } |
| 3729 | |
| 3730 | /* Train 2 */ |
| 3731 | reg = FDI_TX_CTL(pipe); |
| 3732 | temp = I915_READ(reg); |
| 3733 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3734 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3735 | I915_WRITE(reg, temp); |
| 3736 | |
| 3737 | reg = FDI_RX_CTL(pipe); |
| 3738 | temp = I915_READ(reg); |
| 3739 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3740 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3741 | I915_WRITE(reg, temp); |
| 3742 | |
| 3743 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3744 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3745 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3746 | for (i = 0; i < 4; i++) { |
| 3747 | reg = FDI_RX_IIR(pipe); |
| 3748 | temp = I915_READ(reg); |
| 3749 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3750 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3751 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3752 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3753 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3754 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3755 | i); |
| 3756 | goto train_done; |
| 3757 | } |
| 3758 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3759 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3760 | if (i == 4) |
| 3761 | 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] | 3762 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3763 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3764 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3765 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3766 | } |
| 3767 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3768 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3769 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3770 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3771 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3772 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3773 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3774 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3775 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3776 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3777 | reg = FDI_RX_CTL(pipe); |
| 3778 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3779 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3780 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3781 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3782 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3783 | |
| 3784 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3785 | udelay(200); |
| 3786 | |
| 3787 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3788 | temp = I915_READ(reg); |
| 3789 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3790 | |
| 3791 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3792 | udelay(200); |
| 3793 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3794 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3795 | reg = FDI_TX_CTL(pipe); |
| 3796 | temp = I915_READ(reg); |
| 3797 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3798 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3799 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3800 | POSTING_READ(reg); |
| 3801 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3805 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3806 | { |
| 3807 | struct drm_device *dev = intel_crtc->base.dev; |
| 3808 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3809 | int pipe = intel_crtc->pipe; |
| 3810 | u32 reg, temp; |
| 3811 | |
| 3812 | /* Switch from PCDclk to Rawclk */ |
| 3813 | reg = FDI_RX_CTL(pipe); |
| 3814 | temp = I915_READ(reg); |
| 3815 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3816 | |
| 3817 | /* Disable CPU FDI TX PLL */ |
| 3818 | reg = FDI_TX_CTL(pipe); |
| 3819 | temp = I915_READ(reg); |
| 3820 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3821 | |
| 3822 | POSTING_READ(reg); |
| 3823 | udelay(100); |
| 3824 | |
| 3825 | reg = FDI_RX_CTL(pipe); |
| 3826 | temp = I915_READ(reg); |
| 3827 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3828 | |
| 3829 | /* Wait for the clocks to turn off. */ |
| 3830 | POSTING_READ(reg); |
| 3831 | udelay(100); |
| 3832 | } |
| 3833 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3834 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3835 | { |
| 3836 | struct drm_device *dev = crtc->dev; |
| 3837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3838 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3839 | int pipe = intel_crtc->pipe; |
| 3840 | u32 reg, temp; |
| 3841 | |
| 3842 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3843 | reg = FDI_TX_CTL(pipe); |
| 3844 | temp = I915_READ(reg); |
| 3845 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3846 | POSTING_READ(reg); |
| 3847 | |
| 3848 | reg = FDI_RX_CTL(pipe); |
| 3849 | temp = I915_READ(reg); |
| 3850 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3851 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3852 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3853 | |
| 3854 | POSTING_READ(reg); |
| 3855 | udelay(100); |
| 3856 | |
| 3857 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3858 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3859 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3860 | |
| 3861 | /* still set train pattern 1 */ |
| 3862 | reg = FDI_TX_CTL(pipe); |
| 3863 | temp = I915_READ(reg); |
| 3864 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3865 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3866 | I915_WRITE(reg, temp); |
| 3867 | |
| 3868 | reg = FDI_RX_CTL(pipe); |
| 3869 | temp = I915_READ(reg); |
| 3870 | if (HAS_PCH_CPT(dev)) { |
| 3871 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3872 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3873 | } else { |
| 3874 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3875 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3876 | } |
| 3877 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3878 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3879 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3880 | I915_WRITE(reg, temp); |
| 3881 | |
| 3882 | POSTING_READ(reg); |
| 3883 | udelay(100); |
| 3884 | } |
| 3885 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3886 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3887 | { |
| 3888 | struct intel_crtc *crtc; |
| 3889 | |
| 3890 | /* Note that we don't need to be called with mode_config.lock here |
| 3891 | * as our list of CRTC objects is static for the lifetime of the |
| 3892 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3893 | * happily treat the predicates as racy, atomic checks as userspace |
| 3894 | * cannot claim and pin a new fb without at least acquring the |
| 3895 | * struct_mutex and so serialising with us. |
| 3896 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3897 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3898 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3899 | continue; |
| 3900 | |
| 3901 | if (crtc->unpin_work) |
| 3902 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3903 | |
| 3904 | return true; |
| 3905 | } |
| 3906 | |
| 3907 | return false; |
| 3908 | } |
| 3909 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3910 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3911 | { |
| 3912 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3913 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3914 | |
| 3915 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3916 | smp_rmb(); |
| 3917 | intel_crtc->unpin_work = NULL; |
| 3918 | |
| 3919 | if (work->event) |
| 3920 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3921 | intel_crtc->pipe, |
| 3922 | work->event); |
| 3923 | |
| 3924 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3925 | |
| 3926 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3927 | queue_work(dev_priv->wq, &work->work); |
| 3928 | |
| 3929 | trace_i915_flip_complete(intel_crtc->plane, |
| 3930 | work->pending_flip_obj); |
| 3931 | } |
| 3932 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3933 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3934 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3935 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3936 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3937 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3938 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3939 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3940 | !intel_crtc_has_pending_flip(crtc), |
| 3941 | 60*HZ) == 0)) { |
| 3942 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3943 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3944 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3945 | if (intel_crtc->unpin_work) { |
| 3946 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3947 | page_flip_completed(intel_crtc); |
| 3948 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3949 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3950 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3951 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3952 | if (crtc->primary->fb) { |
| 3953 | mutex_lock(&dev->struct_mutex); |
| 3954 | intel_finish_fb(crtc->primary->fb); |
| 3955 | mutex_unlock(&dev->struct_mutex); |
| 3956 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3957 | } |
| 3958 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3959 | /* Program iCLKIP clock to the desired frequency */ |
| 3960 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3961 | { |
| 3962 | struct drm_device *dev = crtc->dev; |
| 3963 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3964 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3965 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3966 | u32 temp; |
| 3967 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3968 | mutex_lock(&dev_priv->dpio_lock); |
| 3969 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3970 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3971 | * the divisors, and gate it back when it is done. |
| 3972 | */ |
| 3973 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3974 | |
| 3975 | /* Disable SSCCTL */ |
| 3976 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3977 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3978 | SBI_SSCCTL_DISABLE, |
| 3979 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3980 | |
| 3981 | /* 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] | 3982 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3983 | auxdiv = 1; |
| 3984 | divsel = 0x41; |
| 3985 | phaseinc = 0x20; |
| 3986 | } else { |
| 3987 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3988 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3989 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3990 | * convert the virtual clock precision to KHz here for higher |
| 3991 | * precision. |
| 3992 | */ |
| 3993 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3994 | u32 iclk_pi_range = 64; |
| 3995 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3996 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3997 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3998 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3999 | pi_value = desired_divisor % iclk_pi_range; |
| 4000 | |
| 4001 | auxdiv = 0; |
| 4002 | divsel = msb_divisor_value - 2; |
| 4003 | phaseinc = pi_value; |
| 4004 | } |
| 4005 | |
| 4006 | /* This should not happen with any sane values */ |
| 4007 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4008 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4009 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4010 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4011 | |
| 4012 | 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] | 4013 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4014 | auxdiv, |
| 4015 | divsel, |
| 4016 | phasedir, |
| 4017 | phaseinc); |
| 4018 | |
| 4019 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4020 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4021 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4022 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4023 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4024 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4025 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4026 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4027 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4028 | |
| 4029 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4030 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4031 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4032 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4033 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4034 | |
| 4035 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4036 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4037 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4038 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4039 | |
| 4040 | /* Wait for initialization time */ |
| 4041 | udelay(24); |
| 4042 | |
| 4043 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 4044 | |
| 4045 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4046 | } |
| 4047 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4048 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 4049 | enum pipe pch_transcoder) |
| 4050 | { |
| 4051 | struct drm_device *dev = crtc->base.dev; |
| 4052 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4053 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4054 | |
| 4055 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4056 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4057 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4058 | I915_READ(HBLANK(cpu_transcoder))); |
| 4059 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4060 | I915_READ(HSYNC(cpu_transcoder))); |
| 4061 | |
| 4062 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4063 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4064 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4065 | I915_READ(VBLANK(cpu_transcoder))); |
| 4066 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4067 | I915_READ(VSYNC(cpu_transcoder))); |
| 4068 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4069 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4070 | } |
| 4071 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4072 | 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] | 4073 | { |
| 4074 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4075 | uint32_t temp; |
| 4076 | |
| 4077 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4078 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4079 | return; |
| 4080 | |
| 4081 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4082 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4083 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4084 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4085 | if (enable) |
| 4086 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4087 | |
| 4088 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4089 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4090 | POSTING_READ(SOUTH_CHICKEN1); |
| 4091 | } |
| 4092 | |
| 4093 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4094 | { |
| 4095 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4096 | |
| 4097 | switch (intel_crtc->pipe) { |
| 4098 | case PIPE_A: |
| 4099 | break; |
| 4100 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4101 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4102 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4103 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4104 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4105 | |
| 4106 | break; |
| 4107 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4108 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4109 | |
| 4110 | break; |
| 4111 | default: |
| 4112 | BUG(); |
| 4113 | } |
| 4114 | } |
| 4115 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4116 | /* |
| 4117 | * Enable PCH resources required for PCH ports: |
| 4118 | * - PCH PLLs |
| 4119 | * - FDI training & RX/TX |
| 4120 | * - update transcoder timings |
| 4121 | * - DP transcoding bits |
| 4122 | * - transcoder |
| 4123 | */ |
| 4124 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4125 | { |
| 4126 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4127 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4128 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4129 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4130 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4131 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4132 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4133 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4134 | if (IS_IVYBRIDGE(dev)) |
| 4135 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4136 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4137 | /* Write the TU size bits before fdi link training, so that error |
| 4138 | * detection works. */ |
| 4139 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4140 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4141 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4142 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4143 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4144 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4145 | /* We need to program the right clock selection before writing the pixel |
| 4146 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4147 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4148 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4149 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4150 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4151 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4152 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4153 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4154 | temp |= sel; |
| 4155 | else |
| 4156 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4157 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4158 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4159 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4160 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4161 | * transcoder, and we actually should do this to not upset any PCH |
| 4162 | * transcoder that already use the clock when we share it. |
| 4163 | * |
| 4164 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4165 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4166 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4167 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4168 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4169 | /* set transcoder timing, panel must allow it */ |
| 4170 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4171 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4172 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4173 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4174 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4175 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4176 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4177 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4178 | reg = TRANS_DP_CTL(pipe); |
| 4179 | temp = I915_READ(reg); |
| 4180 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4181 | TRANS_DP_SYNC_MASK | |
| 4182 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4183 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 4184 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4185 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4186 | |
| 4187 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4188 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4189 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4190 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4191 | |
| 4192 | switch (intel_trans_dp_port_sel(crtc)) { |
| 4193 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4194 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4195 | break; |
| 4196 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4197 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4198 | break; |
| 4199 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4200 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4201 | break; |
| 4202 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4203 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4206 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4209 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4210 | } |
| 4211 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4212 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4213 | { |
| 4214 | struct drm_device *dev = crtc->dev; |
| 4215 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4216 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4217 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4218 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4219 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4220 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4221 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4222 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4223 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4224 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4225 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4226 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4227 | } |
| 4228 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 4229 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4230 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4231 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4232 | |
| 4233 | if (pll == NULL) |
| 4234 | return; |
| 4235 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4236 | if (!(pll->config.crtc_mask & (1 << crtc->pipe))) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 4237 | WARN(1, "bad %s crtc mask\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4238 | return; |
| 4239 | } |
| 4240 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4241 | pll->config.crtc_mask &= ~(1 << crtc->pipe); |
| 4242 | if (pll->config.crtc_mask == 0) { |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 4243 | WARN_ON(pll->on); |
| 4244 | WARN_ON(pll->active); |
| 4245 | } |
| 4246 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4247 | crtc->config->shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4248 | } |
| 4249 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4250 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
| 4251 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4252 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4253 | 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] | 4254 | struct intel_shared_dpll *pll; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4255 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4256 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4257 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 4258 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 4259 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4260 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4261 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4262 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4263 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4264 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4265 | WARN_ON(pll->new_config->crtc_mask); |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4266 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4267 | goto found; |
| 4268 | } |
| 4269 | |
Satheeshakrishna M | bcddf610 | 2014-08-22 09:49:10 +0530 | [diff] [blame] | 4270 | if (IS_BROXTON(dev_priv->dev)) { |
| 4271 | /* PLL is attached to port in bxt */ |
| 4272 | struct intel_encoder *encoder; |
| 4273 | struct intel_digital_port *intel_dig_port; |
| 4274 | |
| 4275 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); |
| 4276 | if (WARN_ON(!encoder)) |
| 4277 | return NULL; |
| 4278 | |
| 4279 | intel_dig_port = enc_to_dig_port(&encoder->base); |
| 4280 | /* 1:1 mapping between ports and PLLs */ |
| 4281 | i = (enum intel_dpll_id)intel_dig_port->port; |
| 4282 | pll = &dev_priv->shared_dplls[i]; |
| 4283 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4284 | crtc->base.base.id, pll->name); |
| 4285 | WARN_ON(pll->new_config->crtc_mask); |
| 4286 | |
| 4287 | goto found; |
| 4288 | } |
| 4289 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4290 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4291 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4292 | |
| 4293 | /* Only want to check enabled timings first */ |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4294 | if (pll->new_config->crtc_mask == 0) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4295 | continue; |
| 4296 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4297 | if (memcmp(&crtc_state->dpll_hw_state, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4298 | &pll->new_config->hw_state, |
| 4299 | sizeof(pll->new_config->hw_state)) == 0) { |
| 4300 | 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] | 4301 | crtc->base.base.id, pll->name, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4302 | pll->new_config->crtc_mask, |
| 4303 | pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4304 | goto found; |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4309 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4310 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4311 | if (pll->new_config->crtc_mask == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4312 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 4313 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4314 | goto found; |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | return NULL; |
| 4319 | |
| 4320 | found: |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4321 | if (pll->new_config->crtc_mask == 0) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4322 | pll->new_config->hw_state = crtc_state->dpll_hw_state; |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4323 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4324 | crtc_state->shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4325 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 4326 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 4327 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4328 | pll->new_config->crtc_mask |= 1 << crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4329 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4330 | return pll; |
| 4331 | } |
| 4332 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4333 | /** |
| 4334 | * intel_shared_dpll_start_config - start a new PLL staged config |
| 4335 | * @dev_priv: DRM device |
| 4336 | * @clear_pipes: mask of pipes that will have their PLLs freed |
| 4337 | * |
| 4338 | * Starts a new PLL staged config, copying the current config but |
| 4339 | * releasing the references of pipes specified in clear_pipes. |
| 4340 | */ |
| 4341 | static int intel_shared_dpll_start_config(struct drm_i915_private *dev_priv, |
| 4342 | unsigned clear_pipes) |
| 4343 | { |
| 4344 | struct intel_shared_dpll *pll; |
| 4345 | enum intel_dpll_id i; |
| 4346 | |
| 4347 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4348 | pll = &dev_priv->shared_dplls[i]; |
| 4349 | |
| 4350 | pll->new_config = kmemdup(&pll->config, sizeof pll->config, |
| 4351 | GFP_KERNEL); |
| 4352 | if (!pll->new_config) |
| 4353 | goto cleanup; |
| 4354 | |
| 4355 | pll->new_config->crtc_mask &= ~clear_pipes; |
| 4356 | } |
| 4357 | |
| 4358 | return 0; |
| 4359 | |
| 4360 | cleanup: |
| 4361 | while (--i >= 0) { |
| 4362 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | f354d73 | 2014-11-07 14:07:41 +0200 | [diff] [blame] | 4363 | kfree(pll->new_config); |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4364 | pll->new_config = NULL; |
| 4365 | } |
| 4366 | |
| 4367 | return -ENOMEM; |
| 4368 | } |
| 4369 | |
| 4370 | static void intel_shared_dpll_commit(struct drm_i915_private *dev_priv) |
| 4371 | { |
| 4372 | struct intel_shared_dpll *pll; |
| 4373 | enum intel_dpll_id i; |
| 4374 | |
| 4375 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4376 | pll = &dev_priv->shared_dplls[i]; |
| 4377 | |
| 4378 | WARN_ON(pll->new_config == &pll->config); |
| 4379 | |
| 4380 | pll->config = *pll->new_config; |
| 4381 | kfree(pll->new_config); |
| 4382 | pll->new_config = NULL; |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | static void intel_shared_dpll_abort_config(struct drm_i915_private *dev_priv) |
| 4387 | { |
| 4388 | struct intel_shared_dpll *pll; |
| 4389 | enum intel_dpll_id i; |
| 4390 | |
| 4391 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4392 | pll = &dev_priv->shared_dplls[i]; |
| 4393 | |
| 4394 | WARN_ON(pll->new_config == &pll->config); |
| 4395 | |
| 4396 | kfree(pll->new_config); |
| 4397 | pll->new_config = NULL; |
| 4398 | } |
| 4399 | } |
| 4400 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4401 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4402 | { |
| 4403 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 4404 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4405 | u32 temp; |
| 4406 | |
| 4407 | temp = I915_READ(dslreg); |
| 4408 | udelay(500); |
| 4409 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4410 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4411 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4415 | /** |
| 4416 | * skl_update_scaler_users - Stages update to crtc's scaler state |
| 4417 | * @intel_crtc: crtc |
| 4418 | * @crtc_state: crtc_state |
| 4419 | * @plane: plane (NULL indicates crtc is requesting update) |
| 4420 | * @plane_state: plane's state |
| 4421 | * @force_detach: request unconditional detachment of scaler |
| 4422 | * |
| 4423 | * This function updates scaler state for requested plane or crtc. |
| 4424 | * To request scaler usage update for a plane, caller shall pass plane pointer. |
| 4425 | * To request scaler usage update for crtc, caller shall pass plane pointer |
| 4426 | * as NULL. |
| 4427 | * |
| 4428 | * Return |
| 4429 | * 0 - scaler_usage updated successfully |
| 4430 | * error - requested scaling cannot be supported or other error condition |
| 4431 | */ |
| 4432 | int |
| 4433 | skl_update_scaler_users( |
| 4434 | struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state, |
| 4435 | struct intel_plane *intel_plane, struct intel_plane_state *plane_state, |
| 4436 | int force_detach) |
| 4437 | { |
| 4438 | int need_scaling; |
| 4439 | int idx; |
| 4440 | int src_w, src_h, dst_w, dst_h; |
| 4441 | int *scaler_id; |
| 4442 | struct drm_framebuffer *fb; |
| 4443 | struct intel_crtc_scaler_state *scaler_state; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4444 | unsigned int rotation; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4445 | |
| 4446 | if (!intel_crtc || !crtc_state) |
| 4447 | return 0; |
| 4448 | |
| 4449 | scaler_state = &crtc_state->scaler_state; |
| 4450 | |
| 4451 | idx = intel_plane ? drm_plane_index(&intel_plane->base) : SKL_CRTC_INDEX; |
| 4452 | fb = intel_plane ? plane_state->base.fb : NULL; |
| 4453 | |
| 4454 | if (intel_plane) { |
| 4455 | src_w = drm_rect_width(&plane_state->src) >> 16; |
| 4456 | src_h = drm_rect_height(&plane_state->src) >> 16; |
| 4457 | dst_w = drm_rect_width(&plane_state->dst); |
| 4458 | dst_h = drm_rect_height(&plane_state->dst); |
| 4459 | scaler_id = &plane_state->scaler_id; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4460 | rotation = plane_state->base.rotation; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4461 | } else { |
| 4462 | struct drm_display_mode *adjusted_mode = |
| 4463 | &crtc_state->base.adjusted_mode; |
| 4464 | src_w = crtc_state->pipe_src_w; |
| 4465 | src_h = crtc_state->pipe_src_h; |
| 4466 | dst_w = adjusted_mode->hdisplay; |
| 4467 | dst_h = adjusted_mode->vdisplay; |
| 4468 | scaler_id = &scaler_state->scaler_id; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4469 | rotation = DRM_ROTATE_0; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4470 | } |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4471 | |
| 4472 | need_scaling = intel_rotation_90_or_270(rotation) ? |
| 4473 | (src_h != dst_w || src_w != dst_h): |
| 4474 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4475 | |
| 4476 | /* |
| 4477 | * if plane is being disabled or scaler is no more required or force detach |
| 4478 | * - free scaler binded to this plane/crtc |
| 4479 | * - in order to do this, update crtc->scaler_usage |
| 4480 | * |
| 4481 | * Here scaler state in crtc_state is set free so that |
| 4482 | * scaler can be assigned to other user. Actual register |
| 4483 | * update to free the scaler is done in plane/panel-fit programming. |
| 4484 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4485 | */ |
| 4486 | if (force_detach || !need_scaling || (intel_plane && |
| 4487 | (!fb || !plane_state->visible))) { |
| 4488 | if (*scaler_id >= 0) { |
| 4489 | scaler_state->scaler_users &= ~(1 << idx); |
| 4490 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4491 | |
| 4492 | DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d " |
| 4493 | "crtc_state = %p scaler_users = 0x%x\n", |
| 4494 | intel_crtc->pipe, *scaler_id, intel_plane ? "PLANE" : "CRTC", |
| 4495 | intel_plane ? intel_plane->base.base.id : |
| 4496 | intel_crtc->base.base.id, crtc_state, |
| 4497 | scaler_state->scaler_users); |
| 4498 | *scaler_id = -1; |
| 4499 | } |
| 4500 | return 0; |
| 4501 | } |
| 4502 | |
| 4503 | /* range checks */ |
| 4504 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4505 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4506 | |
| 4507 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4508 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
| 4509 | DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u " |
| 4510 | "size is out of scaler range\n", |
| 4511 | intel_plane ? "PLANE" : "CRTC", |
| 4512 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, |
| 4513 | intel_crtc->pipe, idx, src_w, src_h, dst_w, dst_h); |
| 4514 | return -EINVAL; |
| 4515 | } |
| 4516 | |
| 4517 | /* check colorkey */ |
| 4518 | if (intel_plane && intel_plane->ckey.flags != I915_SET_COLORKEY_NONE) { |
| 4519 | DRM_DEBUG_KMS("PLANE:%d scaling with color key not allowed", |
| 4520 | intel_plane->base.base.id); |
| 4521 | return -EINVAL; |
| 4522 | } |
| 4523 | |
| 4524 | /* Check src format */ |
| 4525 | if (intel_plane) { |
| 4526 | switch (fb->pixel_format) { |
| 4527 | case DRM_FORMAT_RGB565: |
| 4528 | case DRM_FORMAT_XBGR8888: |
| 4529 | case DRM_FORMAT_XRGB8888: |
| 4530 | case DRM_FORMAT_ABGR8888: |
| 4531 | case DRM_FORMAT_ARGB8888: |
| 4532 | case DRM_FORMAT_XRGB2101010: |
| 4533 | case DRM_FORMAT_ARGB2101010: |
| 4534 | case DRM_FORMAT_XBGR2101010: |
| 4535 | case DRM_FORMAT_ABGR2101010: |
| 4536 | case DRM_FORMAT_YUYV: |
| 4537 | case DRM_FORMAT_YVYU: |
| 4538 | case DRM_FORMAT_UYVY: |
| 4539 | case DRM_FORMAT_VYUY: |
| 4540 | break; |
| 4541 | default: |
| 4542 | DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n", |
| 4543 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); |
| 4544 | return -EINVAL; |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | /* mark this plane as a scaler user in crtc_state */ |
| 4549 | scaler_state->scaler_users |= (1 << idx); |
| 4550 | DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u " |
| 4551 | "crtc_state = %p scaler_users = 0x%x\n", |
| 4552 | intel_plane ? "PLANE" : "CRTC", |
| 4553 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, |
| 4554 | src_w, src_h, dst_w, dst_h, crtc_state, scaler_state->scaler_users); |
| 4555 | return 0; |
| 4556 | } |
| 4557 | |
| 4558 | static void skylake_pfit_update(struct intel_crtc *crtc, int enable) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4559 | { |
| 4560 | struct drm_device *dev = crtc->base.dev; |
| 4561 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4562 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4563 | struct intel_crtc_scaler_state *scaler_state = |
| 4564 | &crtc->config->scaler_state; |
| 4565 | |
| 4566 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4567 | |
| 4568 | /* To update pfit, first update scaler state */ |
| 4569 | skl_update_scaler_users(crtc, crtc->config, NULL, NULL, !enable); |
| 4570 | intel_atomic_setup_scalers(crtc->base.dev, crtc, crtc->config); |
| 4571 | skl_detach_scalers(crtc); |
| 4572 | if (!enable) |
| 4573 | return; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4574 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4575 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4576 | int id; |
| 4577 | |
| 4578 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4579 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4580 | return; |
| 4581 | } |
| 4582 | |
| 4583 | id = scaler_state->scaler_id; |
| 4584 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4585 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4586 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4587 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4588 | |
| 4589 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4593 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4594 | { |
| 4595 | struct drm_device *dev = crtc->base.dev; |
| 4596 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4597 | int pipe = crtc->pipe; |
| 4598 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4599 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4600 | /* Force use of hard-coded filter coefficients |
| 4601 | * as some pre-programmed values are broken, |
| 4602 | * e.g. x201. |
| 4603 | */ |
| 4604 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4605 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4606 | PF_PIPE_SEL_IVB(pipe)); |
| 4607 | else |
| 4608 | 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] | 4609 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4610 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4611 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4612 | } |
| 4613 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4614 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4615 | { |
| 4616 | struct drm_device *dev = crtc->dev; |
| 4617 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4618 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4619 | struct intel_plane *intel_plane; |
| 4620 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4621 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4622 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4623 | if (intel_plane->pipe == pipe) |
| 4624 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4625 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4626 | } |
| 4627 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4628 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4629 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4630 | struct drm_device *dev = crtc->base.dev; |
| 4631 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4632 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4633 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4634 | return; |
| 4635 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4636 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4637 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4638 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4639 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4640 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4641 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4642 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4643 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4644 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4645 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4646 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4647 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4648 | */ |
| 4649 | } else { |
| 4650 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4651 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4652 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4653 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4654 | * the HW state readout code will complain that the expected |
| 4655 | * IPS_CTL value is not the one we read. */ |
| 4656 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4657 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4658 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4659 | } |
| 4660 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4661 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4662 | { |
| 4663 | struct drm_device *dev = crtc->base.dev; |
| 4664 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4665 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4666 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4667 | return; |
| 4668 | |
| 4669 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4670 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4671 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4672 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4673 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4674 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4675 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4676 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4677 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4678 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4679 | POSTING_READ(IPS_CTL); |
| 4680 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4681 | |
| 4682 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4683 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4684 | } |
| 4685 | |
| 4686 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4687 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4688 | { |
| 4689 | struct drm_device *dev = crtc->dev; |
| 4690 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4691 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4692 | enum pipe pipe = intel_crtc->pipe; |
| 4693 | int palreg = PALETTE(pipe); |
| 4694 | int i; |
| 4695 | bool reenable_ips = false; |
| 4696 | |
| 4697 | /* The clocks have to be on to load the palette. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4698 | if (!crtc->state->enable || !intel_crtc->active) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4699 | return; |
| 4700 | |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 4701 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 4702 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4703 | assert_dsi_pll_enabled(dev_priv); |
| 4704 | else |
| 4705 | assert_pll_enabled(dev_priv, pipe); |
| 4706 | } |
| 4707 | |
| 4708 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 4709 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4710 | palreg = LGC_PALETTE(pipe); |
| 4711 | |
| 4712 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 4713 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 4714 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4715 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4716 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 4717 | GAMMA_MODE_MODE_SPLIT)) { |
| 4718 | hsw_disable_ips(intel_crtc); |
| 4719 | reenable_ips = true; |
| 4720 | } |
| 4721 | |
| 4722 | for (i = 0; i < 256; i++) { |
| 4723 | I915_WRITE(palreg + 4 * i, |
| 4724 | (intel_crtc->lut_r[i] << 16) | |
| 4725 | (intel_crtc->lut_g[i] << 8) | |
| 4726 | intel_crtc->lut_b[i]); |
| 4727 | } |
| 4728 | |
| 4729 | if (reenable_ips) |
| 4730 | hsw_enable_ips(intel_crtc); |
| 4731 | } |
| 4732 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4733 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4734 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4735 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4736 | struct drm_device *dev = intel_crtc->base.dev; |
| 4737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4738 | |
| 4739 | mutex_lock(&dev->struct_mutex); |
| 4740 | dev_priv->mm.interruptible = false; |
| 4741 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4742 | dev_priv->mm.interruptible = true; |
| 4743 | mutex_unlock(&dev->struct_mutex); |
| 4744 | } |
| 4745 | |
| 4746 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4747 | * has to recompute where to put it anyway. |
| 4748 | */ |
| 4749 | } |
| 4750 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4751 | /** |
| 4752 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4753 | * @crtc: the CRTC whose primary plane was just enabled |
| 4754 | * |
| 4755 | * Performs potentially sleeping operations that must be done after the primary |
| 4756 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4757 | * called due to an explicit primary plane update, or due to an implicit |
| 4758 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4759 | * completely hide the primary plane. |
| 4760 | */ |
| 4761 | static void |
| 4762 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4763 | { |
| 4764 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4765 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4766 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4767 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4768 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4769 | /* |
| 4770 | * BDW signals flip done immediately if the plane |
| 4771 | * is disabled, even if the plane enable is already |
| 4772 | * armed to occur at the next vblank :( |
| 4773 | */ |
| 4774 | if (IS_BROADWELL(dev)) |
| 4775 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4776 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4777 | /* |
| 4778 | * FIXME IPS should be fine as long as one plane is |
| 4779 | * enabled, but in practice it seems to have problems |
| 4780 | * when going from primary only to sprite only and vice |
| 4781 | * versa. |
| 4782 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4783 | hsw_enable_ips(intel_crtc); |
| 4784 | |
| 4785 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4786 | intel_fbc_update(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4787 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4788 | |
| 4789 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4790 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4791 | * So don't enable underrun reporting before at least some planes |
| 4792 | * are enabled. |
| 4793 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4794 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4795 | */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4796 | if (IS_GEN2(dev)) |
| 4797 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4798 | |
| 4799 | /* Underruns don't raise interrupts, so check manually. */ |
| 4800 | if (HAS_GMCH_DISPLAY(dev)) |
| 4801 | i9xx_check_fifo_underruns(dev_priv); |
| 4802 | } |
| 4803 | |
| 4804 | /** |
| 4805 | * intel_pre_disable_primary - Perform operations before disabling primary plane |
| 4806 | * @crtc: the CRTC whose primary plane is to be disabled |
| 4807 | * |
| 4808 | * Performs potentially sleeping operations that must be done before the |
| 4809 | * primary plane is disabled, such as updating FBC and IPS. Note that this may |
| 4810 | * be called due to an explicit primary plane update, or due to an implicit |
| 4811 | * disable that is caused when a sprite plane completely hides the primary |
| 4812 | * plane. |
| 4813 | */ |
| 4814 | static void |
| 4815 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4816 | { |
| 4817 | struct drm_device *dev = crtc->dev; |
| 4818 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4819 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4820 | int pipe = intel_crtc->pipe; |
| 4821 | |
| 4822 | /* |
| 4823 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4824 | * So diasble underrun reporting before all the planes get disabled. |
| 4825 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4826 | * but leave the pipe running. |
| 4827 | */ |
| 4828 | if (IS_GEN2(dev)) |
| 4829 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4830 | |
| 4831 | /* |
| 4832 | * Vblank time updates from the shadow to live plane control register |
| 4833 | * are blocked if the memory self-refresh mode is active at that |
| 4834 | * moment. So to make sure the plane gets truly disabled, disable |
| 4835 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4836 | * will be checked/applied by the HW only at the next frame start |
| 4837 | * event which is after the vblank start event, so we need to have a |
| 4838 | * wait-for-vblank between disabling the plane and the pipe. |
| 4839 | */ |
| 4840 | if (HAS_GMCH_DISPLAY(dev)) |
| 4841 | intel_set_memory_cxsr(dev_priv, false); |
| 4842 | |
| 4843 | mutex_lock(&dev->struct_mutex); |
| 4844 | if (dev_priv->fbc.crtc == intel_crtc) |
| 4845 | intel_fbc_disable(dev); |
| 4846 | mutex_unlock(&dev->struct_mutex); |
| 4847 | |
| 4848 | /* |
| 4849 | * FIXME IPS should be fine as long as one plane is |
| 4850 | * enabled, but in practice it seems to have problems |
| 4851 | * when going from primary only to sprite only and vice |
| 4852 | * versa. |
| 4853 | */ |
| 4854 | hsw_disable_ips(intel_crtc); |
| 4855 | } |
| 4856 | |
| 4857 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
| 4858 | { |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4859 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
| 4860 | intel_enable_sprite_planes(crtc); |
| 4861 | intel_crtc_update_cursor(crtc, true); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4862 | |
| 4863 | intel_post_enable_primary(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4866 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4867 | { |
| 4868 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4869 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4870 | struct intel_plane *intel_plane; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4871 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4872 | |
| 4873 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4874 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4875 | intel_pre_disable_primary(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4876 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4877 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4878 | for_each_intel_plane(dev, intel_plane) { |
| 4879 | if (intel_plane->pipe == pipe) { |
| 4880 | struct drm_crtc *from = intel_plane->base.crtc; |
| 4881 | |
| 4882 | intel_plane->disable_plane(&intel_plane->base, |
| 4883 | from ?: crtc, true); |
| 4884 | } |
| 4885 | } |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4886 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4887 | /* |
| 4888 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4889 | * to compute the mask of flip planes precisely. For the time being |
| 4890 | * consider this a flip to a NULL plane. |
| 4891 | */ |
| 4892 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4893 | } |
| 4894 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4895 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4896 | { |
| 4897 | struct drm_device *dev = crtc->dev; |
| 4898 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4899 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4900 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4901 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4902 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4903 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4904 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4905 | if (intel_crtc->active) |
| 4906 | return; |
| 4907 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4908 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4909 | intel_prepare_shared_dpll(intel_crtc); |
| 4910 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4911 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4912 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4913 | |
| 4914 | intel_set_pipe_timings(intel_crtc); |
| 4915 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4916 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4917 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4918 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | ironlake_set_pipeconf(crtc); |
| 4922 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4923 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4924 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4925 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4926 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4927 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4928 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4929 | if (encoder->pre_enable) |
| 4930 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4931 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4932 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4933 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4934 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4935 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4936 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4937 | } else { |
| 4938 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4939 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4940 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4941 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4942 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4943 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4944 | /* |
| 4945 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4946 | * clocks enabled |
| 4947 | */ |
| 4948 | intel_crtc_load_lut(crtc); |
| 4949 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4950 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4951 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4952 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4953 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4954 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4955 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4956 | assert_vblank_disabled(crtc); |
| 4957 | drm_crtc_vblank_on(crtc); |
| 4958 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4959 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4960 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4961 | |
| 4962 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4963 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4964 | } |
| 4965 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4966 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4967 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4968 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4969 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4970 | } |
| 4971 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4972 | /* |
| 4973 | * This implements the workaround described in the "notes" section of the mode |
| 4974 | * set sequence documentation. When going from no pipes or single pipe to |
| 4975 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4976 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4977 | */ |
| 4978 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4979 | { |
| 4980 | struct drm_device *dev = crtc->base.dev; |
| 4981 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4982 | |
| 4983 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4984 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4985 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4986 | if (!crtc_it->active || crtc_it == crtc) |
| 4987 | continue; |
| 4988 | |
| 4989 | if (other_active_crtc) |
| 4990 | return; |
| 4991 | |
| 4992 | other_active_crtc = crtc_it; |
| 4993 | } |
| 4994 | if (!other_active_crtc) |
| 4995 | return; |
| 4996 | |
| 4997 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4998 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4999 | } |
| 5000 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5001 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 5002 | { |
| 5003 | struct drm_device *dev = crtc->dev; |
| 5004 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5005 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5006 | struct intel_encoder *encoder; |
| 5007 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5008 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5009 | WARN_ON(!crtc->state->enable); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5010 | |
| 5011 | if (intel_crtc->active) |
| 5012 | return; |
| 5013 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5014 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 5015 | intel_enable_shared_dpll(intel_crtc); |
| 5016 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5017 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5018 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5019 | |
| 5020 | intel_set_pipe_timings(intel_crtc); |
| 5021 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5022 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
| 5023 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), |
| 5024 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5025 | } |
| 5026 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5027 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5028 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5029 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | haswell_set_pipeconf(crtc); |
| 5033 | |
| 5034 | intel_set_pipe_csc(crtc); |
| 5035 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5036 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5037 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5038 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5039 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5040 | if (encoder->pre_enable) |
| 5041 | encoder->pre_enable(encoder); |
| 5042 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5043 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5044 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5045 | true); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 5046 | dev_priv->display.fdi_link_train(crtc); |
| 5047 | } |
| 5048 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 5049 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5050 | |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5051 | if (INTEL_INFO(dev)->gen == 9) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5052 | skylake_pfit_update(intel_crtc, 1); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5053 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5054 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5055 | else |
| 5056 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5057 | |
| 5058 | /* |
| 5059 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5060 | * clocks enabled |
| 5061 | */ |
| 5062 | intel_crtc_load_lut(crtc); |
| 5063 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 5064 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 5065 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5066 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5067 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5068 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5069 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5070 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 5071 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5072 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5073 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5074 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 5075 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5076 | assert_vblank_disabled(crtc); |
| 5077 | drm_crtc_vblank_on(crtc); |
| 5078 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5079 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5080 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5081 | intel_opregion_notify_encoder(encoder, true); |
| 5082 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5083 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5084 | /* If we change the relative order between pipe/planes enabling, we need |
| 5085 | * to change the workaround. */ |
| 5086 | haswell_mode_set_planes_workaround(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5087 | } |
| 5088 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5089 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 5090 | { |
| 5091 | struct drm_device *dev = crtc->base.dev; |
| 5092 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5093 | int pipe = crtc->pipe; |
| 5094 | |
| 5095 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5096 | * 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] | 5097 | if (crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5098 | I915_WRITE(PF_CTL(pipe), 0); |
| 5099 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5100 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5101 | } |
| 5102 | } |
| 5103 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5104 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 5105 | { |
| 5106 | struct drm_device *dev = crtc->dev; |
| 5107 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5108 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5109 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5110 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5111 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5112 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5113 | if (!intel_crtc->active) |
| 5114 | return; |
| 5115 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5116 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5117 | encoder->disable(encoder); |
| 5118 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5119 | drm_crtc_vblank_off(crtc); |
| 5120 | assert_vblank_disabled(crtc); |
| 5121 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5122 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5123 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5124 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5125 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5126 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5127 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5128 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 5129 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5130 | if (encoder->post_disable) |
| 5131 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5132 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5133 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5134 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5135 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5136 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5137 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5138 | if (HAS_PCH_CPT(dev)) { |
| 5139 | /* disable TRANS_DP_CTL */ |
| 5140 | reg = TRANS_DP_CTL(pipe); |
| 5141 | temp = I915_READ(reg); |
| 5142 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5143 | TRANS_DP_PORT_SEL_MASK); |
| 5144 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5145 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5146 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5147 | /* disable DPLL_SEL */ |
| 5148 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5149 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5150 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5151 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5152 | |
| 5153 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 5154 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5155 | |
| 5156 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5159 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5160 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 5161 | |
| 5162 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 5163 | intel_fbc_update(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 5164 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5167 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 5168 | { |
| 5169 | struct drm_device *dev = crtc->dev; |
| 5170 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5171 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5172 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5173 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5174 | |
| 5175 | if (!intel_crtc->active) |
| 5176 | return; |
| 5177 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5178 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5179 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5180 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5181 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5182 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5183 | drm_crtc_vblank_off(crtc); |
| 5184 | assert_vblank_disabled(crtc); |
| 5185 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5186 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5187 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5188 | false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5189 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5190 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5191 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5192 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5193 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 5194 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5195 | |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5196 | if (INTEL_INFO(dev)->gen == 9) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5197 | skylake_pfit_update(intel_crtc, 0); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5198 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5199 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5200 | else |
| 5201 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5202 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 5203 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5204 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5205 | if (intel_crtc->config->has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 5206 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 5207 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 5208 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5209 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 5210 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5211 | if (encoder->post_disable) |
| 5212 | encoder->post_disable(encoder); |
| 5213 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5214 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5215 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5216 | |
| 5217 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 5218 | intel_fbc_update(dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5219 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5220 | |
| 5221 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 5222 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5223 | } |
| 5224 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5225 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 5226 | { |
| 5227 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 5228 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5229 | } |
| 5230 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 5231 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5232 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5233 | { |
| 5234 | struct drm_device *dev = crtc->base.dev; |
| 5235 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5236 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5237 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5238 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5239 | return; |
| 5240 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5241 | /* |
| 5242 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5243 | * according to register description and PRM. |
| 5244 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5245 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5246 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5247 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5248 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5249 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5250 | |
| 5251 | /* Border color in case we don't scale up to the full screen. Black by |
| 5252 | * default, change to something else for debugging. */ |
| 5253 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5256 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5257 | { |
| 5258 | switch (port) { |
| 5259 | case PORT_A: |
| 5260 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 5261 | case PORT_B: |
| 5262 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 5263 | case PORT_C: |
| 5264 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 5265 | case PORT_D: |
| 5266 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 5267 | default: |
| 5268 | WARN_ON_ONCE(1); |
| 5269 | return POWER_DOMAIN_PORT_OTHER; |
| 5270 | } |
| 5271 | } |
| 5272 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5273 | #define for_each_power_domain(domain, mask) \ |
| 5274 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 5275 | if ((1 << (domain)) & (mask)) |
| 5276 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5277 | enum intel_display_power_domain |
| 5278 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5279 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5280 | struct drm_device *dev = intel_encoder->base.dev; |
| 5281 | struct intel_digital_port *intel_dig_port; |
| 5282 | |
| 5283 | switch (intel_encoder->type) { |
| 5284 | case INTEL_OUTPUT_UNKNOWN: |
| 5285 | /* Only DDI platforms should ever use this output type */ |
| 5286 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5287 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5288 | case INTEL_OUTPUT_HDMI: |
| 5289 | case INTEL_OUTPUT_EDP: |
| 5290 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5291 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5292 | case INTEL_OUTPUT_DP_MST: |
| 5293 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5294 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5295 | case INTEL_OUTPUT_ANALOG: |
| 5296 | return POWER_DOMAIN_PORT_CRT; |
| 5297 | case INTEL_OUTPUT_DSI: |
| 5298 | return POWER_DOMAIN_PORT_DSI; |
| 5299 | default: |
| 5300 | return POWER_DOMAIN_PORT_OTHER; |
| 5301 | } |
| 5302 | } |
| 5303 | |
| 5304 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 5305 | { |
| 5306 | struct drm_device *dev = crtc->dev; |
| 5307 | struct intel_encoder *intel_encoder; |
| 5308 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5309 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5310 | unsigned long mask; |
| 5311 | enum transcoder transcoder; |
| 5312 | |
| 5313 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 5314 | |
| 5315 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5316 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5317 | if (intel_crtc->config->pch_pfit.enabled || |
| 5318 | intel_crtc->config->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5319 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5320 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5321 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5322 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 5323 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5324 | return mask; |
| 5325 | } |
| 5326 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5327 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5328 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5329 | struct drm_device *dev = state->dev; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5330 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5331 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 5332 | struct intel_crtc *crtc; |
| 5333 | |
| 5334 | /* |
| 5335 | * First get all needed power domains, then put all unneeded, to avoid |
| 5336 | * any unnecessary toggling of the power wells. |
| 5337 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5338 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5339 | enum intel_display_power_domain domain; |
| 5340 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5341 | if (!crtc->base.state->enable) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5342 | continue; |
| 5343 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5344 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5345 | |
| 5346 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 5347 | intel_display_power_get(dev_priv, domain); |
| 5348 | } |
| 5349 | |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 5350 | if (dev_priv->display.modeset_global_resources) |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5351 | dev_priv->display.modeset_global_resources(state); |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 5352 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5353 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5354 | enum intel_display_power_domain domain; |
| 5355 | |
| 5356 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 5357 | intel_display_power_put(dev_priv, domain); |
| 5358 | |
| 5359 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 5360 | } |
| 5361 | |
| 5362 | intel_display_set_init_power(dev_priv, false); |
| 5363 | } |
| 5364 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5365 | void broxton_set_cdclk(struct drm_device *dev, int frequency) |
| 5366 | { |
| 5367 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5368 | uint32_t divider; |
| 5369 | uint32_t ratio; |
| 5370 | uint32_t current_freq; |
| 5371 | int ret; |
| 5372 | |
| 5373 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ |
| 5374 | switch (frequency) { |
| 5375 | case 144000: |
| 5376 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
| 5377 | ratio = BXT_DE_PLL_RATIO(60); |
| 5378 | break; |
| 5379 | case 288000: |
| 5380 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
| 5381 | ratio = BXT_DE_PLL_RATIO(60); |
| 5382 | break; |
| 5383 | case 384000: |
| 5384 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
| 5385 | ratio = BXT_DE_PLL_RATIO(60); |
| 5386 | break; |
| 5387 | case 576000: |
| 5388 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5389 | ratio = BXT_DE_PLL_RATIO(60); |
| 5390 | break; |
| 5391 | case 624000: |
| 5392 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5393 | ratio = BXT_DE_PLL_RATIO(65); |
| 5394 | break; |
| 5395 | case 19200: |
| 5396 | /* |
| 5397 | * Bypass frequency with DE PLL disabled. Init ratio, divider |
| 5398 | * to suppress GCC warning. |
| 5399 | */ |
| 5400 | ratio = 0; |
| 5401 | divider = 0; |
| 5402 | break; |
| 5403 | default: |
| 5404 | DRM_ERROR("unsupported CDCLK freq %d", frequency); |
| 5405 | |
| 5406 | return; |
| 5407 | } |
| 5408 | |
| 5409 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5410 | /* Inform power controller of upcoming frequency change */ |
| 5411 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5412 | 0x80000000); |
| 5413 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5414 | |
| 5415 | if (ret) { |
| 5416 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
| 5417 | ret, frequency); |
| 5418 | return; |
| 5419 | } |
| 5420 | |
| 5421 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; |
| 5422 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ |
| 5423 | current_freq = current_freq * 500 + 1000; |
| 5424 | |
| 5425 | /* |
| 5426 | * DE PLL has to be disabled when |
| 5427 | * - setting to 19.2MHz (bypass, PLL isn't used) |
| 5428 | * - before setting to 624MHz (PLL needs toggling) |
| 5429 | * - before setting to any frequency from 624MHz (PLL needs toggling) |
| 5430 | */ |
| 5431 | if (frequency == 19200 || frequency == 624000 || |
| 5432 | current_freq == 624000) { |
| 5433 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); |
| 5434 | /* Timeout 200us */ |
| 5435 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), |
| 5436 | 1)) |
| 5437 | DRM_ERROR("timout waiting for DE PLL unlock\n"); |
| 5438 | } |
| 5439 | |
| 5440 | if (frequency != 19200) { |
| 5441 | uint32_t val; |
| 5442 | |
| 5443 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5444 | val &= ~BXT_DE_PLL_RATIO_MASK; |
| 5445 | val |= ratio; |
| 5446 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5447 | |
| 5448 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5449 | /* Timeout 200us */ |
| 5450 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) |
| 5451 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
| 5452 | |
| 5453 | val = I915_READ(CDCLK_CTL); |
| 5454 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; |
| 5455 | val |= divider; |
| 5456 | /* |
| 5457 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5458 | * enable otherwise. |
| 5459 | */ |
| 5460 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5461 | if (frequency >= 500000) |
| 5462 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5463 | |
| 5464 | val &= ~CDCLK_FREQ_DECIMAL_MASK; |
| 5465 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5466 | val |= (frequency - 1000) / 500; |
| 5467 | I915_WRITE(CDCLK_CTL, val); |
| 5468 | } |
| 5469 | |
| 5470 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5471 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5472 | DIV_ROUND_UP(frequency, 25000)); |
| 5473 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5474 | |
| 5475 | if (ret) { |
| 5476 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
| 5477 | ret, frequency); |
| 5478 | return; |
| 5479 | } |
| 5480 | |
| 5481 | dev_priv->cdclk_freq = frequency; |
| 5482 | } |
| 5483 | |
| 5484 | void broxton_init_cdclk(struct drm_device *dev) |
| 5485 | { |
| 5486 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5487 | uint32_t val; |
| 5488 | |
| 5489 | /* |
| 5490 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT |
| 5491 | * or else the reset will hang because there is no PCH to respond. |
| 5492 | * Move the handshake programming to initialization sequence. |
| 5493 | * Previously was left up to BIOS. |
| 5494 | */ |
| 5495 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 5496 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; |
| 5497 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); |
| 5498 | |
| 5499 | /* Enable PG1 for cdclk */ |
| 5500 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 5501 | |
| 5502 | /* check if cd clock is enabled */ |
| 5503 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { |
| 5504 | DRM_DEBUG_KMS("Display already initialized\n"); |
| 5505 | return; |
| 5506 | } |
| 5507 | |
| 5508 | /* |
| 5509 | * FIXME: |
| 5510 | * - The initial CDCLK needs to be read from VBT. |
| 5511 | * Need to make this change after VBT has changes for BXT. |
| 5512 | * - check if setting the max (or any) cdclk freq is really necessary |
| 5513 | * here, it belongs to modeset time |
| 5514 | */ |
| 5515 | broxton_set_cdclk(dev, 624000); |
| 5516 | |
| 5517 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5518 | POSTING_READ(DBUF_CTL); |
| 5519 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5520 | udelay(10); |
| 5521 | |
| 5522 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5523 | DRM_ERROR("DBuf power enable timeout!\n"); |
| 5524 | } |
| 5525 | |
| 5526 | void broxton_uninit_cdclk(struct drm_device *dev) |
| 5527 | { |
| 5528 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5529 | |
| 5530 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5531 | POSTING_READ(DBUF_CTL); |
| 5532 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5533 | udelay(10); |
| 5534 | |
| 5535 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5536 | DRM_ERROR("DBuf power disable timeout!\n"); |
| 5537 | |
| 5538 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ |
| 5539 | broxton_set_cdclk(dev, 19200); |
| 5540 | |
| 5541 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
| 5542 | } |
| 5543 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5544 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5545 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5546 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5547 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5548 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5549 | /* Obtain SKU information */ |
| 5550 | mutex_lock(&dev_priv->dpio_lock); |
| 5551 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 5552 | CCK_FUSE_HPLL_FREQ_MASK; |
| 5553 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5554 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5555 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5556 | } |
| 5557 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5558 | static void vlv_update_cdclk(struct drm_device *dev) |
| 5559 | { |
| 5560 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5561 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5562 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
Ville Syrjälä | 43dc52c | 2014-10-07 17:41:20 +0300 | [diff] [blame] | 5563 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5564 | dev_priv->cdclk_freq); |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5565 | |
| 5566 | /* |
| 5567 | * Program the gmbus_freq based on the cdclk frequency. |
| 5568 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5569 | * in fact 1MHz is the correct frequency. |
| 5570 | */ |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5571 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5572 | } |
| 5573 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5574 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5575 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5576 | { |
| 5577 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5578 | u32 val, cmd; |
| 5579 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5580 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5581 | != dev_priv->cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5582 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5583 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5584 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5585 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5586 | cmd = 1; |
| 5587 | else |
| 5588 | cmd = 0; |
| 5589 | |
| 5590 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5591 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5592 | val &= ~DSPFREQGUAR_MASK; |
| 5593 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5594 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5595 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5596 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5597 | 50)) { |
| 5598 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5599 | } |
| 5600 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5601 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5602 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5603 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5604 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5605 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5606 | |
| 5607 | mutex_lock(&dev_priv->dpio_lock); |
| 5608 | /* adjust cdclk divider */ |
| 5609 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 5610 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5611 | val |= divider; |
| 5612 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5613 | |
| 5614 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 5615 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5616 | 50)) |
| 5617 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5618 | mutex_unlock(&dev_priv->dpio_lock); |
| 5619 | } |
| 5620 | |
| 5621 | mutex_lock(&dev_priv->dpio_lock); |
| 5622 | /* adjust self-refresh exit latency value */ |
| 5623 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5624 | val &= ~0x7f; |
| 5625 | |
| 5626 | /* |
| 5627 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5628 | * so that the core display fetch happens in time to avoid underruns. |
| 5629 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5630 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5631 | val |= 4500 / 250; /* 4.5 usec */ |
| 5632 | else |
| 5633 | val |= 3000 / 250; /* 3.0 usec */ |
| 5634 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 5635 | mutex_unlock(&dev_priv->dpio_lock); |
| 5636 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5637 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5638 | } |
| 5639 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5640 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5641 | { |
| 5642 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5643 | u32 val, cmd; |
| 5644 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5645 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5646 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5647 | |
| 5648 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5649 | case 333333: |
| 5650 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5651 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5652 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5653 | break; |
| 5654 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5655 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5656 | return; |
| 5657 | } |
| 5658 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5659 | /* |
| 5660 | * Specs are full of misinformation, but testing on actual |
| 5661 | * hardware has shown that we just need to write the desired |
| 5662 | * CCK divider into the Punit register. |
| 5663 | */ |
| 5664 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5665 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5666 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5667 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5668 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5669 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5670 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5671 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5672 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5673 | 50)) { |
| 5674 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5675 | } |
| 5676 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5677 | |
| 5678 | vlv_update_cdclk(dev); |
| 5679 | } |
| 5680 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5681 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5682 | int max_pixclk) |
| 5683 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5684 | 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] | 5685 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5686 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5687 | /* |
| 5688 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5689 | * 200MHz |
| 5690 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5691 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5692 | * 400MHz (VLV only) |
| 5693 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5694 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5695 | * |
| 5696 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5697 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5698 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5699 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5700 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5701 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5702 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5703 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5704 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5705 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5706 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5707 | else |
| 5708 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5709 | } |
| 5710 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5711 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5712 | int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5713 | { |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5714 | /* |
| 5715 | * FIXME: |
| 5716 | * - remove the guardband, it's not needed on BXT |
| 5717 | * - set 19.2MHz bypass frequency if there are no active pipes |
| 5718 | */ |
| 5719 | if (max_pixclk > 576000*9/10) |
| 5720 | return 624000; |
| 5721 | else if (max_pixclk > 384000*9/10) |
| 5722 | return 576000; |
| 5723 | else if (max_pixclk > 288000*9/10) |
| 5724 | return 384000; |
| 5725 | else if (max_pixclk > 144000*9/10) |
| 5726 | return 288000; |
| 5727 | else |
| 5728 | return 144000; |
| 5729 | } |
| 5730 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5731 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
| 5732 | * that's non-NULL, look at current state otherwise. */ |
| 5733 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 5734 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5735 | { |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5736 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5737 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5738 | int max_pixclk = 0; |
| 5739 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5740 | for_each_intel_crtc(dev, intel_crtc) { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5741 | if (state) |
| 5742 | crtc_state = |
| 5743 | intel_atomic_get_crtc_state(state, intel_crtc); |
| 5744 | else |
| 5745 | crtc_state = intel_crtc->config; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5746 | if (IS_ERR(crtc_state)) |
| 5747 | return PTR_ERR(crtc_state); |
| 5748 | |
| 5749 | if (!crtc_state->base.enable) |
| 5750 | continue; |
| 5751 | |
| 5752 | max_pixclk = max(max_pixclk, |
| 5753 | crtc_state->base.adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | return max_pixclk; |
| 5757 | } |
| 5758 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 5759 | static int valleyview_modeset_global_pipes(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5760 | { |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5761 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 5762 | struct drm_crtc *crtc; |
| 5763 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5764 | int max_pixclk = intel_mode_max_pixclk(state->dev, state); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 5765 | int cdclk, i; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5766 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5767 | if (max_pixclk < 0) |
| 5768 | return max_pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5769 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5770 | if (IS_VALLEYVIEW(dev_priv)) |
| 5771 | cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
| 5772 | else |
| 5773 | cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); |
| 5774 | |
| 5775 | if (cdclk == dev_priv->cdclk_freq) |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5776 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5777 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 5778 | /* add all active pipes to the state */ |
| 5779 | for_each_crtc(state->dev, crtc) { |
| 5780 | if (!crtc->state->enable) |
| 5781 | continue; |
| 5782 | |
| 5783 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 5784 | if (IS_ERR(crtc_state)) |
| 5785 | return PTR_ERR(crtc_state); |
| 5786 | } |
| 5787 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5788 | /* disable/enable all currently active pipes while we change cdclk */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 5789 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
| 5790 | if (crtc_state->enable) |
| 5791 | crtc_state->mode_changed = true; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5792 | |
| 5793 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5794 | } |
| 5795 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5796 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5797 | { |
| 5798 | unsigned int credits, default_credits; |
| 5799 | |
| 5800 | if (IS_CHERRYVIEW(dev_priv)) |
| 5801 | default_credits = PFI_CREDIT(12); |
| 5802 | else |
| 5803 | default_credits = PFI_CREDIT(8); |
| 5804 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5805 | if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5806 | /* CHV suggested value is 31 or 63 */ |
| 5807 | if (IS_CHERRYVIEW(dev_priv)) |
| 5808 | credits = PFI_CREDIT_31; |
| 5809 | else |
| 5810 | credits = PFI_CREDIT(15); |
| 5811 | } else { |
| 5812 | credits = default_credits; |
| 5813 | } |
| 5814 | |
| 5815 | /* |
| 5816 | * WA - write default credits before re-programming |
| 5817 | * FIXME: should we also set the resend bit here? |
| 5818 | */ |
| 5819 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5820 | default_credits); |
| 5821 | |
| 5822 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5823 | credits | PFI_CREDIT_RESEND); |
| 5824 | |
| 5825 | /* |
| 5826 | * FIXME is this guaranteed to clear |
| 5827 | * immediately or should we poll for it? |
| 5828 | */ |
| 5829 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 5830 | } |
| 5831 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5832 | static void valleyview_modeset_global_resources(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5833 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5834 | struct drm_device *dev = old_state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5835 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5836 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5837 | int req_cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5838 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5839 | /* The path in intel_mode_max_pixclk() with a NULL atomic state should |
| 5840 | * never fail. */ |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5841 | if (WARN_ON(max_pixclk < 0)) |
| 5842 | return; |
| 5843 | |
| 5844 | req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5845 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5846 | if (req_cdclk != dev_priv->cdclk_freq) { |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5847 | /* |
| 5848 | * FIXME: We can end up here with all power domains off, yet |
| 5849 | * with a CDCLK frequency other than the minimum. To account |
| 5850 | * for this take the PIPE-A power domain, which covers the HW |
| 5851 | * blocks needed for the following programming. This can be |
| 5852 | * removed once it's guaranteed that we get here either with |
| 5853 | * the minimum CDCLK set, or the required power domains |
| 5854 | * enabled. |
| 5855 | */ |
| 5856 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
| 5857 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5858 | if (IS_CHERRYVIEW(dev)) |
| 5859 | cherryview_set_cdclk(dev, req_cdclk); |
| 5860 | else |
| 5861 | valleyview_set_cdclk(dev, req_cdclk); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5862 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5863 | vlv_program_pfi_credits(dev_priv); |
| 5864 | |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5865 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5866 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5869 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 5870 | { |
| 5871 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5872 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5873 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5874 | struct intel_encoder *encoder; |
| 5875 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 5876 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5877 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5878 | WARN_ON(!crtc->state->enable); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5879 | |
| 5880 | if (intel_crtc->active) |
| 5881 | return; |
| 5882 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5883 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 5884 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5885 | if (!is_dsi) { |
| 5886 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5887 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5888 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5889 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5890 | } |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5891 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5892 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5893 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5894 | |
| 5895 | intel_set_pipe_timings(intel_crtc); |
| 5896 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5897 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 5898 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5899 | |
| 5900 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5901 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5902 | } |
| 5903 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5904 | i9xx_set_pipeconf(intel_crtc); |
| 5905 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5906 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5907 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5908 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5909 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5910 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5911 | if (encoder->pre_pll_enable) |
| 5912 | encoder->pre_pll_enable(encoder); |
| 5913 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5914 | if (!is_dsi) { |
| 5915 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5916 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5917 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5918 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5919 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5920 | |
| 5921 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5922 | if (encoder->pre_enable) |
| 5923 | encoder->pre_enable(encoder); |
| 5924 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5925 | i9xx_pfit_enable(intel_crtc); |
| 5926 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5927 | intel_crtc_load_lut(crtc); |
| 5928 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5929 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5930 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5931 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5932 | assert_vblank_disabled(crtc); |
| 5933 | drm_crtc_vblank_on(crtc); |
| 5934 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5935 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5936 | encoder->enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5937 | } |
| 5938 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5939 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 5940 | { |
| 5941 | struct drm_device *dev = crtc->base.dev; |
| 5942 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5943 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5944 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 5945 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5946 | } |
| 5947 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5948 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5949 | { |
| 5950 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5951 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5952 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5953 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5954 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5955 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5956 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 5957 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5958 | if (intel_crtc->active) |
| 5959 | return; |
| 5960 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5961 | i9xx_set_pll_dividers(intel_crtc); |
| 5962 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5963 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5964 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5965 | |
| 5966 | intel_set_pipe_timings(intel_crtc); |
| 5967 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5968 | i9xx_set_pipeconf(intel_crtc); |
| 5969 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5970 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5971 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5972 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5973 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5974 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 5975 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 5976 | if (encoder->pre_enable) |
| 5977 | encoder->pre_enable(encoder); |
| 5978 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 5979 | i9xx_enable_pll(intel_crtc); |
| 5980 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5981 | i9xx_pfit_enable(intel_crtc); |
| 5982 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5983 | intel_crtc_load_lut(crtc); |
| 5984 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5985 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5986 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5987 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5988 | assert_vblank_disabled(crtc); |
| 5989 | drm_crtc_vblank_on(crtc); |
| 5990 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5991 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5992 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5995 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 5996 | { |
| 5997 | struct drm_device *dev = crtc->base.dev; |
| 5998 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5999 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6000 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6001 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6002 | |
| 6003 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6004 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6005 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6006 | I915_READ(PFIT_CONTROL)); |
| 6007 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6008 | } |
| 6009 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6010 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 6011 | { |
| 6012 | struct drm_device *dev = crtc->dev; |
| 6013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6014 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6015 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6016 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6017 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6018 | if (!intel_crtc->active) |
| 6019 | return; |
| 6020 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6021 | /* |
| 6022 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6023 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 6024 | * We also need to wait on all gmch platforms because of the |
| 6025 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6026 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 6027 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6028 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6029 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6030 | encoder->disable(encoder); |
| 6031 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6032 | drm_crtc_vblank_off(crtc); |
| 6033 | assert_vblank_disabled(crtc); |
| 6034 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6035 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6036 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6037 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6038 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6039 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6040 | if (encoder->post_disable) |
| 6041 | encoder->post_disable(encoder); |
| 6042 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6043 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6044 | if (IS_CHERRYVIEW(dev)) |
| 6045 | chv_disable_pll(dev_priv, pipe); |
| 6046 | else if (IS_VALLEYVIEW(dev)) |
| 6047 | vlv_disable_pll(dev_priv, pipe); |
| 6048 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6049 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6050 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6051 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6052 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6053 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6054 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6055 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 6056 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 6057 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 6058 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6059 | intel_fbc_update(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 6060 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6061 | } |
| 6062 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6063 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 6064 | { |
| 6065 | } |
| 6066 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 6067 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 6068 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 6069 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 6070 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6071 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6072 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6073 | enum intel_display_power_domain domain; |
| 6074 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6075 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6076 | if (enable) { |
| 6077 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 6078 | domains = get_crtc_power_domains(crtc); |
| 6079 | for_each_power_domain(domain, domains) |
| 6080 | intel_display_power_get(dev_priv, domain); |
| 6081 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6082 | |
| 6083 | dev_priv->display.crtc_enable(crtc); |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 6084 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6085 | } |
| 6086 | } else { |
| 6087 | if (intel_crtc->active) { |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 6088 | intel_crtc_disable_planes(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6089 | dev_priv->display.crtc_disable(crtc); |
| 6090 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 6091 | domains = intel_crtc->enabled_power_domains; |
| 6092 | for_each_power_domain(domain, domains) |
| 6093 | intel_display_power_put(dev_priv, domain); |
| 6094 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6095 | } |
| 6096 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | /** |
| 6100 | * Sets the power management mode of the pipe and plane. |
| 6101 | */ |
| 6102 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 6103 | { |
| 6104 | struct drm_device *dev = crtc->dev; |
| 6105 | struct intel_encoder *intel_encoder; |
| 6106 | bool enable = false; |
| 6107 | |
| 6108 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 6109 | enable |= intel_encoder->connectors_active; |
| 6110 | |
| 6111 | intel_crtc_control(crtc, enable); |
Ander Conselvan de Oliveira | 0f63cca | 2015-04-21 17:13:17 +0300 | [diff] [blame] | 6112 | |
| 6113 | crtc->state->active = enable; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6114 | } |
| 6115 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6116 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 6117 | { |
| 6118 | struct drm_device *dev = crtc->dev; |
| 6119 | struct drm_connector *connector; |
| 6120 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6121 | |
| 6122 | /* crtc should still be enabled when we disable it. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 6123 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6124 | |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 6125 | intel_crtc_disable_planes(crtc); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6126 | dev_priv->display.crtc_disable(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6127 | dev_priv->display.off(crtc); |
| 6128 | |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 6129 | drm_plane_helper_disable(crtc->primary); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6130 | |
| 6131 | /* Update computed state. */ |
| 6132 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 6133 | if (!connector->encoder || !connector->encoder->crtc) |
| 6134 | continue; |
| 6135 | |
| 6136 | if (connector->encoder->crtc != crtc) |
| 6137 | continue; |
| 6138 | |
| 6139 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 6140 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 6141 | } |
| 6142 | } |
| 6143 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6144 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6145 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6146 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6147 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6148 | drm_encoder_cleanup(encoder); |
| 6149 | kfree(intel_encoder); |
| 6150 | } |
| 6151 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 6152 | /* 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] | 6153 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 6154 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 6155 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6156 | { |
| 6157 | if (mode == DRM_MODE_DPMS_ON) { |
| 6158 | encoder->connectors_active = true; |
| 6159 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 6160 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6161 | } else { |
| 6162 | encoder->connectors_active = false; |
| 6163 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 6164 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6165 | } |
| 6166 | } |
| 6167 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6168 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6169 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 6170 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6171 | { |
| 6172 | if (connector->get_hw_state(connector)) { |
| 6173 | struct intel_encoder *encoder = connector->encoder; |
| 6174 | struct drm_crtc *crtc; |
| 6175 | bool encoder_enabled; |
| 6176 | enum pipe pipe; |
| 6177 | |
| 6178 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6179 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 6180 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6181 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 6182 | /* there is no real hw state for MST connectors */ |
| 6183 | if (connector->mst_port) |
| 6184 | return; |
| 6185 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 6186 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6187 | "wrong connector dpms state\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 6188 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6189 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6190 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6191 | if (encoder) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 6192 | I915_STATE_WARN(!encoder->connectors_active, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6193 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6194 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6195 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 6196 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
| 6197 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6198 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6199 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6200 | crtc = encoder->base.crtc; |
| 6201 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 6202 | I915_STATE_WARN(!crtc->state->enable, |
| 6203 | "crtc not enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 6204 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 6205 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6206 | "encoder active on the wrong pipe\n"); |
| 6207 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6208 | } |
| 6209 | } |
| 6210 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6211 | int intel_connector_init(struct intel_connector *connector) |
| 6212 | { |
| 6213 | struct drm_connector_state *connector_state; |
| 6214 | |
| 6215 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); |
| 6216 | if (!connector_state) |
| 6217 | return -ENOMEM; |
| 6218 | |
| 6219 | connector->base.state = connector_state; |
| 6220 | return 0; |
| 6221 | } |
| 6222 | |
| 6223 | struct intel_connector *intel_connector_alloc(void) |
| 6224 | { |
| 6225 | struct intel_connector *connector; |
| 6226 | |
| 6227 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6228 | if (!connector) |
| 6229 | return NULL; |
| 6230 | |
| 6231 | if (intel_connector_init(connector) < 0) { |
| 6232 | kfree(connector); |
| 6233 | return NULL; |
| 6234 | } |
| 6235 | |
| 6236 | return connector; |
| 6237 | } |
| 6238 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6239 | /* Even simpler default implementation, if there's really no special case to |
| 6240 | * consider. */ |
| 6241 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 6242 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6243 | /* All the simple cases only support two dpms states. */ |
| 6244 | if (mode != DRM_MODE_DPMS_ON) |
| 6245 | mode = DRM_MODE_DPMS_OFF; |
| 6246 | |
| 6247 | if (mode == connector->dpms) |
| 6248 | return; |
| 6249 | |
| 6250 | connector->dpms = mode; |
| 6251 | |
| 6252 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dc | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 6253 | if (connector->encoder) |
| 6254 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6255 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 6256 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 6257 | } |
| 6258 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6259 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6260 | * one connector and no cloning and hence the encoder state determines the state |
| 6261 | * of the connector. */ |
| 6262 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6263 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6264 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6265 | struct intel_encoder *encoder = connector->encoder; |
| 6266 | |
| 6267 | return encoder->get_hw_state(encoder, &pipe); |
| 6268 | } |
| 6269 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6270 | 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] | 6271 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6272 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6273 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6274 | |
| 6275 | return 0; |
| 6276 | } |
| 6277 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6278 | 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] | 6279 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6280 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6281 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6282 | struct intel_crtc *other_crtc; |
| 6283 | struct intel_crtc_state *other_crtc_state; |
| 6284 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6285 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6286 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6287 | if (pipe_config->fdi_lanes > 4) { |
| 6288 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6289 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6290 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6291 | } |
| 6292 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 6293 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6294 | if (pipe_config->fdi_lanes > 2) { |
| 6295 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6296 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6297 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6298 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6299 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6300 | } |
| 6301 | } |
| 6302 | |
| 6303 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6304 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6305 | |
| 6306 | /* Ivybridge 3 pipe is really complicated */ |
| 6307 | switch (pipe) { |
| 6308 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6309 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6310 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6311 | if (pipe_config->fdi_lanes <= 2) |
| 6312 | return 0; |
| 6313 | |
| 6314 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 6315 | other_crtc_state = |
| 6316 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6317 | if (IS_ERR(other_crtc_state)) |
| 6318 | return PTR_ERR(other_crtc_state); |
| 6319 | |
| 6320 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6321 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6322 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6323 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6324 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6325 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6326 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6327 | if (pipe_config->fdi_lanes > 2) { |
| 6328 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6329 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6330 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6331 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6332 | |
| 6333 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 6334 | other_crtc_state = |
| 6335 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6336 | if (IS_ERR(other_crtc_state)) |
| 6337 | return PTR_ERR(other_crtc_state); |
| 6338 | |
| 6339 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6340 | 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] | 6341 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6342 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6343 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6344 | default: |
| 6345 | BUG(); |
| 6346 | } |
| 6347 | } |
| 6348 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6349 | #define RETRY 1 |
| 6350 | 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] | 6351 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6352 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6353 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6354 | 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] | 6355 | int lane, link_bw, fdi_dotclock, ret; |
| 6356 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6357 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6358 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6359 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6360 | * each output octet as 10 bits. The actual frequency |
| 6361 | * is stored as a divider into a 100MHz clock, and the |
| 6362 | * mode pixel clock is stored in units of 1KHz. |
| 6363 | * Hence the bw of each lane in terms of the mode signal |
| 6364 | * is: |
| 6365 | */ |
| 6366 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 6367 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6368 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6369 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6370 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6371 | pipe_config->pipe_bpp); |
| 6372 | |
| 6373 | pipe_config->fdi_lanes = lane; |
| 6374 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6375 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6376 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6377 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6378 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 6379 | intel_crtc->pipe, pipe_config); |
| 6380 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6381 | pipe_config->pipe_bpp -= 2*3; |
| 6382 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6383 | pipe_config->pipe_bpp); |
| 6384 | needs_recompute = true; |
| 6385 | pipe_config->bw_constrained = true; |
| 6386 | |
| 6387 | goto retry; |
| 6388 | } |
| 6389 | |
| 6390 | if (needs_recompute) |
| 6391 | return RETRY; |
| 6392 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6393 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6394 | } |
| 6395 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6396 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6397 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6398 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6399 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 6400 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 6401 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6402 | } |
| 6403 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6404 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6405 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6406 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6407 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 6408 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6409 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 6410 | int ret; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6411 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6412 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6413 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6414 | int clock_limit = |
| 6415 | dev_priv->display.get_display_clock_speed(dev); |
| 6416 | |
| 6417 | /* |
| 6418 | * Enable pixel doubling when the dot clock |
| 6419 | * is > 90% of the (display) core speed. |
| 6420 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 6421 | * GDG double wide on either pipe, |
| 6422 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6423 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 6424 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6425 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6426 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6427 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6428 | } |
| 6429 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6430 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6431 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6432 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6433 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6434 | /* |
| 6435 | * Pipe horizontal size must be even in: |
| 6436 | * - DVO ganged mode |
| 6437 | * - LVDS dual channel mode |
| 6438 | * - Double wide pipe |
| 6439 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6440 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6441 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 6442 | pipe_config->pipe_src_w &= ~1; |
| 6443 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6444 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6445 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6446 | */ |
| 6447 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 6448 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6449 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6450 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 6451 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6452 | hsw_compute_ips_config(crtc, pipe_config); |
| 6453 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6454 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6455 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6456 | |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 6457 | /* FIXME: remove below call once atomic mode set is place and all crtc |
| 6458 | * related checks called from atomic_crtc_check function */ |
| 6459 | ret = 0; |
| 6460 | DRM_DEBUG_KMS("intel_crtc = %p drm_state (pipe_config->base.state) = %p\n", |
| 6461 | crtc, pipe_config->base.state); |
| 6462 | ret = intel_atomic_setup_scalers(dev, crtc, pipe_config); |
| 6463 | |
| 6464 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6465 | } |
| 6466 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6467 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 6468 | { |
| 6469 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6470 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 6471 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6472 | uint32_t linkrate; |
| 6473 | |
| 6474 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) { |
| 6475 | WARN(1, "LCPLL1 not enabled\n"); |
| 6476 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
| 6477 | } |
| 6478 | |
| 6479 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 6480 | return 540000; |
| 6481 | |
| 6482 | linkrate = (I915_READ(DPLL_CTRL1) & |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6483 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6484 | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6485 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
| 6486 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6487 | /* vco 8640 */ |
| 6488 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6489 | case CDCLK_FREQ_450_432: |
| 6490 | return 432000; |
| 6491 | case CDCLK_FREQ_337_308: |
| 6492 | return 308570; |
| 6493 | case CDCLK_FREQ_675_617: |
| 6494 | return 617140; |
| 6495 | default: |
| 6496 | WARN(1, "Unknown cd freq selection\n"); |
| 6497 | } |
| 6498 | } else { |
| 6499 | /* vco 8100 */ |
| 6500 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6501 | case CDCLK_FREQ_450_432: |
| 6502 | return 450000; |
| 6503 | case CDCLK_FREQ_337_308: |
| 6504 | return 337500; |
| 6505 | case CDCLK_FREQ_675_617: |
| 6506 | return 675000; |
| 6507 | default: |
| 6508 | WARN(1, "Unknown cd freq selection\n"); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /* error case, do as if DPLL0 isn't enabled */ |
| 6513 | return 24000; |
| 6514 | } |
| 6515 | |
| 6516 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 6517 | { |
| 6518 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6519 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6520 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6521 | |
| 6522 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6523 | return 800000; |
| 6524 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6525 | return 450000; |
| 6526 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6527 | return 450000; |
| 6528 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6529 | return 540000; |
| 6530 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6531 | return 337500; |
| 6532 | else |
| 6533 | return 675000; |
| 6534 | } |
| 6535 | |
| 6536 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6537 | { |
| 6538 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6539 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6540 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6541 | |
| 6542 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6543 | return 800000; |
| 6544 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6545 | return 450000; |
| 6546 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6547 | return 450000; |
| 6548 | else if (IS_HSW_ULT(dev)) |
| 6549 | return 337500; |
| 6550 | else |
| 6551 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6552 | } |
| 6553 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6554 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6555 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6556 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6557 | u32 val; |
| 6558 | int divider; |
| 6559 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6560 | if (dev_priv->hpll_freq == 0) |
| 6561 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 6562 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6563 | mutex_lock(&dev_priv->dpio_lock); |
| 6564 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 6565 | mutex_unlock(&dev_priv->dpio_lock); |
| 6566 | |
| 6567 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 6568 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 6569 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 6570 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 6571 | "cdclk change in progress\n"); |
| 6572 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6573 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6576 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6577 | { |
| 6578 | return 450000; |
| 6579 | } |
| 6580 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6581 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6582 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6583 | return 400000; |
| 6584 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6585 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6586 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 6587 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6588 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6589 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6590 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6591 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6592 | { |
| 6593 | return 200000; |
| 6594 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6595 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6596 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6597 | { |
| 6598 | u16 gcfgc = 0; |
| 6599 | |
| 6600 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6601 | |
| 6602 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6603 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6604 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6605 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6606 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6607 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6608 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6609 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6610 | return 200000; |
| 6611 | default: |
| 6612 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6613 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6614 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6615 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6616 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6617 | } |
| 6618 | } |
| 6619 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6620 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6621 | { |
| 6622 | u16 gcfgc = 0; |
| 6623 | |
| 6624 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6625 | |
| 6626 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6627 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6628 | else { |
| 6629 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6630 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6631 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6632 | default: |
| 6633 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6634 | return 190000; |
| 6635 | } |
| 6636 | } |
| 6637 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6638 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6639 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6640 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6641 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6642 | } |
| 6643 | |
| 6644 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 6645 | { |
| 6646 | u16 hpllcc = 0; |
| 6647 | /* Assume that the hardware is in the high speed state. This |
| 6648 | * should be the default. |
| 6649 | */ |
| 6650 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6651 | case GC_CLOCK_133_200: |
| 6652 | case GC_CLOCK_100_200: |
| 6653 | return 200000; |
| 6654 | case GC_CLOCK_166_250: |
| 6655 | return 250000; |
| 6656 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6657 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | /* Shouldn't happen */ |
| 6661 | return 0; |
| 6662 | } |
| 6663 | |
| 6664 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6665 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6666 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6667 | } |
| 6668 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6669 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6670 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6671 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6672 | while (*num > DATA_LINK_M_N_MASK || |
| 6673 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6674 | *num >>= 1; |
| 6675 | *den >>= 1; |
| 6676 | } |
| 6677 | } |
| 6678 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6679 | static void compute_m_n(unsigned int m, unsigned int n, |
| 6680 | uint32_t *ret_m, uint32_t *ret_n) |
| 6681 | { |
| 6682 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 6683 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6684 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6685 | } |
| 6686 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6687 | void |
| 6688 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6689 | int pixel_clock, int link_clock, |
| 6690 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6691 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6692 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6693 | |
| 6694 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6695 | link_clock * nlanes * 8, |
| 6696 | &m_n->gmch_m, &m_n->gmch_n); |
| 6697 | |
| 6698 | compute_m_n(pixel_clock, link_clock, |
| 6699 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6700 | } |
| 6701 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6702 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6703 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6704 | if (i915.panel_use_ssc >= 0) |
| 6705 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6706 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6707 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6708 | } |
| 6709 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6710 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 6711 | int num_connectors) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6712 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6713 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6714 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6715 | int refclk; |
| 6716 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6717 | WARN_ON(!crtc_state->base.state); |
| 6718 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 6719 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 6720 | refclk = 100000; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6721 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6722 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6723 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 6724 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6725 | } else if (!IS_GEN2(dev)) { |
| 6726 | refclk = 96000; |
| 6727 | } else { |
| 6728 | refclk = 48000; |
| 6729 | } |
| 6730 | |
| 6731 | return refclk; |
| 6732 | } |
| 6733 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6734 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6735 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6736 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6737 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6738 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6739 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6740 | { |
| 6741 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6742 | } |
| 6743 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6744 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6745 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6746 | intel_clock_t *reduced_clock) |
| 6747 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6748 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6749 | u32 fp, fp2 = 0; |
| 6750 | |
| 6751 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6752 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6753 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6754 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6755 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6756 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6757 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6758 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6759 | } |
| 6760 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6761 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6762 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6763 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6764 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6765 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6766 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6767 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6768 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6769 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6770 | } |
| 6771 | } |
| 6772 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6773 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6774 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6775 | { |
| 6776 | u32 reg_val; |
| 6777 | |
| 6778 | /* |
| 6779 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6780 | * and set it to a reasonable value instead. |
| 6781 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6782 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6783 | reg_val &= 0xffffff00; |
| 6784 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6785 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6786 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6787 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6788 | reg_val &= 0x8cffffff; |
| 6789 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6790 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6791 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6792 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6793 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6794 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6795 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6796 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6797 | reg_val &= 0x00ffffff; |
| 6798 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6799 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6800 | } |
| 6801 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6802 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6803 | struct intel_link_m_n *m_n) |
| 6804 | { |
| 6805 | struct drm_device *dev = crtc->base.dev; |
| 6806 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6807 | int pipe = crtc->pipe; |
| 6808 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6809 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6810 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6811 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6812 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6816 | struct intel_link_m_n *m_n, |
| 6817 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6818 | { |
| 6819 | struct drm_device *dev = crtc->base.dev; |
| 6820 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6821 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6822 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6823 | |
| 6824 | if (INTEL_INFO(dev)->gen >= 5) { |
| 6825 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6826 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6827 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6828 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6829 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6830 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6831 | * registers are not unnecessarily accessed). |
| 6832 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 6833 | 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] | 6834 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6835 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6836 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6837 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6838 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6839 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6840 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6841 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6842 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6843 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6844 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6845 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6849 | 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] | 6850 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6851 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6852 | |
| 6853 | if (m_n == M1_N1) { |
| 6854 | dp_m_n = &crtc->config->dp_m_n; |
| 6855 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6856 | } else if (m_n == M2_N2) { |
| 6857 | |
| 6858 | /* |
| 6859 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6860 | * needs to be programmed into M1_N1. |
| 6861 | */ |
| 6862 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6863 | } else { |
| 6864 | DRM_ERROR("Unsupported divider value\n"); |
| 6865 | return; |
| 6866 | } |
| 6867 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6868 | if (crtc->config->has_pch_encoder) |
| 6869 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6870 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6871 | 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] | 6872 | } |
| 6873 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6874 | static void vlv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6875 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6876 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6877 | u32 dpll, dpll_md; |
| 6878 | |
| 6879 | /* |
| 6880 | * Enable DPIO clock input. We should never disable the reference |
| 6881 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 6882 | * on it. |
| 6883 | */ |
| 6884 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 6885 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 6886 | /* We should never disable this, set it here for state tracking */ |
| 6887 | if (crtc->pipe == PIPE_B) |
| 6888 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6889 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6890 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6891 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6892 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6893 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6894 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6895 | } |
| 6896 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6897 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6898 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6899 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6900 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6901 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6902 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6903 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6904 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6905 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6906 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6907 | mutex_lock(&dev_priv->dpio_lock); |
| 6908 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6909 | bestn = pipe_config->dpll.n; |
| 6910 | bestm1 = pipe_config->dpll.m1; |
| 6911 | bestm2 = pipe_config->dpll.m2; |
| 6912 | bestp1 = pipe_config->dpll.p1; |
| 6913 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6914 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6915 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6916 | |
| 6917 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6918 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6919 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6920 | |
| 6921 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6922 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6923 | |
| 6924 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6925 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6926 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6927 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6928 | |
| 6929 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6930 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6931 | |
| 6932 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6933 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6934 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6935 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6936 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6937 | |
| 6938 | /* |
| 6939 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6940 | * but we don't support that). |
| 6941 | * Note: don't use the DAC post divider as it seems unstable. |
| 6942 | */ |
| 6943 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6944 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6945 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6946 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6947 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6948 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6949 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6950 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6951 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 6952 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6953 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6954 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6955 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6956 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6957 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6958 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 6959 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6960 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6961 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6962 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6963 | 0x0df40000); |
| 6964 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6965 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6966 | 0x0df70000); |
| 6967 | } else { /* HDMI or VGA */ |
| 6968 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6969 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6970 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6971 | 0x0df70000); |
| 6972 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6973 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6974 | 0x0df40000); |
| 6975 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6976 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6977 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6978 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6979 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 6980 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6981 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6982 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6983 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6984 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6985 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6986 | } |
| 6987 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6988 | static void chv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6989 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6990 | { |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6991 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6992 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 6993 | DPLL_VCO_ENABLE; |
| 6994 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6995 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6996 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6997 | pipe_config->dpll_hw_state.dpll_md = |
| 6998 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6999 | } |
| 7000 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7001 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7002 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7003 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7004 | struct drm_device *dev = crtc->base.dev; |
| 7005 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7006 | int pipe = crtc->pipe; |
| 7007 | int dpll_reg = DPLL(crtc->pipe); |
| 7008 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7009 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7010 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7011 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7012 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7013 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7014 | bestn = pipe_config->dpll.n; |
| 7015 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7016 | bestm1 = pipe_config->dpll.m1; |
| 7017 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7018 | bestp1 = pipe_config->dpll.p1; |
| 7019 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7020 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7021 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7022 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7023 | |
| 7024 | /* |
| 7025 | * Enable Refclk and SSC |
| 7026 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7027 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7028 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7029 | |
| 7030 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7031 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7032 | /* p1 and p2 divider */ |
| 7033 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7034 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7035 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7036 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7037 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7038 | |
| 7039 | /* Feedback post-divider - m2 */ |
| 7040 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7041 | |
| 7042 | /* Feedback refclk divider - n and m1 */ |
| 7043 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7044 | DPIO_CHV_M1_DIV_BY_2 | |
| 7045 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7046 | |
| 7047 | /* M2 fraction division */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7048 | if (bestm2_frac) |
| 7049 | 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] | 7050 | |
| 7051 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7052 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7053 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7054 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7055 | if (bestm2_frac) |
| 7056 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7057 | 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] | 7058 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7059 | /* Program digital lock detect threshold */ |
| 7060 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7061 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7062 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7063 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7064 | if (!bestm2_frac) |
| 7065 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7066 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7067 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7068 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7069 | if (vco == 5400000) { |
| 7070 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7071 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7072 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7073 | tribuf_calcntr = 0x9; |
| 7074 | } else if (vco <= 6200000) { |
| 7075 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7076 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7077 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7078 | tribuf_calcntr = 0x9; |
| 7079 | } else if (vco <= 6480000) { |
| 7080 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7081 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7082 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7083 | tribuf_calcntr = 0x8; |
| 7084 | } else { |
| 7085 | /* Not supported. Apply the same limits as in the max case */ |
| 7086 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7087 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7088 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7089 | tribuf_calcntr = 0; |
| 7090 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7091 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7092 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7093 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7094 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7095 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7096 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7097 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7098 | /* AFC Recal */ |
| 7099 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7100 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7101 | DPIO_AFC_RECAL); |
| 7102 | |
| 7103 | mutex_unlock(&dev_priv->dpio_lock); |
| 7104 | } |
| 7105 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7106 | /** |
| 7107 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7108 | * @dev_priv: i915 private structure |
| 7109 | * @pipe: pipe PLL to enable |
| 7110 | * @dpll: PLL configuration |
| 7111 | * |
| 7112 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7113 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7114 | * be enabled. |
| 7115 | */ |
| 7116 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 7117 | const struct dpll *dpll) |
| 7118 | { |
| 7119 | struct intel_crtc *crtc = |
| 7120 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7121 | struct intel_crtc_state pipe_config = { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7122 | .base.crtc = &crtc->base, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7123 | .pixel_multiplier = 1, |
| 7124 | .dpll = *dpll, |
| 7125 | }; |
| 7126 | |
| 7127 | if (IS_CHERRYVIEW(dev)) { |
| 7128 | chv_update_pll(crtc, &pipe_config); |
| 7129 | chv_prepare_pll(crtc, &pipe_config); |
| 7130 | chv_enable_pll(crtc, &pipe_config); |
| 7131 | } else { |
| 7132 | vlv_update_pll(crtc, &pipe_config); |
| 7133 | vlv_prepare_pll(crtc, &pipe_config); |
| 7134 | vlv_enable_pll(crtc, &pipe_config); |
| 7135 | } |
| 7136 | } |
| 7137 | |
| 7138 | /** |
| 7139 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7140 | * @dev_priv: i915 private structure |
| 7141 | * @pipe: pipe PLL to disable |
| 7142 | * |
| 7143 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7144 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7145 | */ |
| 7146 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 7147 | { |
| 7148 | if (IS_CHERRYVIEW(dev)) |
| 7149 | chv_disable_pll(to_i915(dev), pipe); |
| 7150 | else |
| 7151 | vlv_disable_pll(to_i915(dev), pipe); |
| 7152 | } |
| 7153 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7154 | static void i9xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7155 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7156 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7157 | int num_connectors) |
| 7158 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7159 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7160 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7161 | u32 dpll; |
| 7162 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7163 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7164 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7165 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7166 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7167 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7168 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7169 | |
| 7170 | dpll = DPLL_VGA_MODE_DIS; |
| 7171 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7172 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7173 | dpll |= DPLLB_MODE_LVDS; |
| 7174 | else |
| 7175 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7176 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7177 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7178 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7179 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7180 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7181 | |
| 7182 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7183 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7184 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7185 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7186 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7187 | |
| 7188 | /* compute bitmask from p1 value */ |
| 7189 | if (IS_PINEVIEW(dev)) |
| 7190 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7191 | else { |
| 7192 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7193 | if (IS_G4X(dev) && reduced_clock) |
| 7194 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7195 | } |
| 7196 | switch (clock->p2) { |
| 7197 | case 5: |
| 7198 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7199 | break; |
| 7200 | case 7: |
| 7201 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7202 | break; |
| 7203 | case 10: |
| 7204 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7205 | break; |
| 7206 | case 14: |
| 7207 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7208 | break; |
| 7209 | } |
| 7210 | if (INTEL_INFO(dev)->gen >= 4) |
| 7211 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7212 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7213 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7214 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7215 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7216 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 7217 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7218 | else |
| 7219 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7220 | |
| 7221 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7222 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7223 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7224 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7225 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7226 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7227 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7228 | } |
| 7229 | } |
| 7230 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7231 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7232 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7233 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7234 | int num_connectors) |
| 7235 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7236 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7237 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7238 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7239 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7240 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7241 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7242 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7243 | dpll = DPLL_VGA_MODE_DIS; |
| 7244 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7245 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7246 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7247 | } else { |
| 7248 | if (clock->p1 == 2) |
| 7249 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7250 | else |
| 7251 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7252 | if (clock->p2 == 4) |
| 7253 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7254 | } |
| 7255 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7256 | 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] | 7257 | dpll |= DPLL_DVO_2X_MODE; |
| 7258 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7259 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7260 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 7261 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7262 | else |
| 7263 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7264 | |
| 7265 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7266 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7267 | } |
| 7268 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7269 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7270 | { |
| 7271 | struct drm_device *dev = intel_crtc->base.dev; |
| 7272 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7273 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7274 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7275 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7276 | &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7277 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7278 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7279 | |
| 7280 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7281 | * the hw state checker will get angry at the mismatch. */ |
| 7282 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7283 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7284 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7285 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7286 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7287 | crtc_vtotal -= 1; |
| 7288 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7289 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7290 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7291 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7292 | else |
| 7293 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7294 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7295 | if (vsyncshift < 0) |
| 7296 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7300 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7301 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7302 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7303 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7304 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7305 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7306 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7307 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7308 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7309 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7310 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7311 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7312 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7313 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7314 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7315 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7316 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7317 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7318 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7319 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7320 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7321 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7322 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7323 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7324 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7325 | * bits. */ |
| 7326 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 7327 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7328 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7329 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7330 | /* pipesrc controls the size that is scaled from, which should |
| 7331 | * always be the user's requested size. |
| 7332 | */ |
| 7333 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7334 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7335 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7336 | } |
| 7337 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7338 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7339 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7340 | { |
| 7341 | struct drm_device *dev = crtc->base.dev; |
| 7342 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7343 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7344 | uint32_t tmp; |
| 7345 | |
| 7346 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7347 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7348 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7349 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7350 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7351 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7352 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7353 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7354 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7355 | |
| 7356 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7357 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7358 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7359 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7360 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7361 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7362 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7363 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7364 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7365 | |
| 7366 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7367 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7368 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7369 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7370 | } |
| 7371 | |
| 7372 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7373 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7374 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7375 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7376 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7377 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7378 | } |
| 7379 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7380 | 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] | 7381 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7382 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7383 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7384 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7385 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7386 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7387 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7388 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7389 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7390 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7391 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7392 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7393 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7394 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7395 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 7396 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7397 | } |
| 7398 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7399 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7400 | { |
| 7401 | struct drm_device *dev = intel_crtc->base.dev; |
| 7402 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7403 | uint32_t pipeconf; |
| 7404 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7405 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7406 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7407 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 7408 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 7409 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7410 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7411 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7412 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7413 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7414 | /* only g4x and later have fancy bpc/dither controls */ |
| 7415 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7416 | /* 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] | 7417 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7418 | pipeconf |= PIPECONF_DITHER_EN | |
| 7419 | PIPECONF_DITHER_TYPE_SP; |
| 7420 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7421 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7422 | case 18: |
| 7423 | pipeconf |= PIPECONF_6BPC; |
| 7424 | break; |
| 7425 | case 24: |
| 7426 | pipeconf |= PIPECONF_8BPC; |
| 7427 | break; |
| 7428 | case 30: |
| 7429 | pipeconf |= PIPECONF_10BPC; |
| 7430 | break; |
| 7431 | default: |
| 7432 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7433 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | if (HAS_PIPE_CXSR(dev)) { |
| 7438 | if (intel_crtc->lowfreq_avail) { |
| 7439 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 7440 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 7441 | } else { |
| 7442 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7443 | } |
| 7444 | } |
| 7445 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7446 | 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] | 7447 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7448 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7449 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7450 | else |
| 7451 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7452 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7453 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7454 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7455 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7456 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7457 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7458 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7459 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7460 | } |
| 7461 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7462 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7463 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7464 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7465 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7466 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 7467 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7468 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 7469 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7470 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7471 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 7472 | const intel_limit_t *limit; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7473 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 7474 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7475 | struct drm_connector_state *connector_state; |
| 7476 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7477 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 7478 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7479 | if (connector_state->crtc != &crtc->base) |
| 7480 | continue; |
| 7481 | |
| 7482 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7483 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7484 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7485 | case INTEL_OUTPUT_LVDS: |
| 7486 | is_lvds = true; |
| 7487 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7488 | case INTEL_OUTPUT_DSI: |
| 7489 | is_dsi = true; |
| 7490 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7491 | default: |
| 7492 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7493 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 7494 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 7495 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7496 | } |
| 7497 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7498 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 7499 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7500 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7501 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7502 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7503 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7504 | /* |
| 7505 | * Returns a set of divisors for the desired target clock with |
| 7506 | * the given refclk, or FALSE. The returned values represent |
| 7507 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 7508 | * 2) / p1 / p2. |
| 7509 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7510 | limit = intel_limit(crtc_state, refclk); |
| 7511 | ok = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7512 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7513 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7514 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7515 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7516 | return -EINVAL; |
| 7517 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7518 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7519 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7520 | /* |
| 7521 | * Ensure we match the reduced clock's P to the target |
| 7522 | * clock. If the clocks don't match, we can't switch |
| 7523 | * the display clock by using the FP0/FP1. In such case |
| 7524 | * we will disable the LVDS downclock feature. |
| 7525 | */ |
| 7526 | has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7527 | dev_priv->display.find_dpll(limit, crtc_state, |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7528 | dev_priv->lvds_downclock, |
| 7529 | refclk, &clock, |
| 7530 | &reduced_clock); |
| 7531 | } |
| 7532 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7533 | crtc_state->dpll.n = clock.n; |
| 7534 | crtc_state->dpll.m1 = clock.m1; |
| 7535 | crtc_state->dpll.m2 = clock.m2; |
| 7536 | crtc_state->dpll.p1 = clock.p1; |
| 7537 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7538 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7539 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7540 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7541 | i8xx_update_pll(crtc, crtc_state, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7542 | has_reduced_clock ? &reduced_clock : NULL, |
| 7543 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7544 | } else if (IS_CHERRYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7545 | chv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7546 | } else if (IS_VALLEYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7547 | vlv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7548 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7549 | i9xx_update_pll(crtc, crtc_state, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7550 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7551 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7552 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7553 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7554 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7555 | } |
| 7556 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7557 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7558 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7559 | { |
| 7560 | struct drm_device *dev = crtc->base.dev; |
| 7561 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7562 | uint32_t tmp; |
| 7563 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7564 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 7565 | return; |
| 7566 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7567 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7568 | if (!(tmp & PFIT_ENABLE)) |
| 7569 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7570 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7571 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7572 | if (INTEL_INFO(dev)->gen < 4) { |
| 7573 | if (crtc->pipe != PIPE_B) |
| 7574 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7575 | } else { |
| 7576 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7577 | return; |
| 7578 | } |
| 7579 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7580 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7581 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 7582 | if (INTEL_INFO(dev)->gen < 5) |
| 7583 | pipe_config->gmch_pfit.lvds_border_bits = |
| 7584 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 7585 | } |
| 7586 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7587 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7588 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7589 | { |
| 7590 | struct drm_device *dev = crtc->base.dev; |
| 7591 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7592 | int pipe = pipe_config->cpu_transcoder; |
| 7593 | intel_clock_t clock; |
| 7594 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7595 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7596 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7597 | /* In case of MIPI DPLL will not even be used */ |
| 7598 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 7599 | return; |
| 7600 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7601 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7602 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7603 | mutex_unlock(&dev_priv->dpio_lock); |
| 7604 | |
| 7605 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7606 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7607 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7608 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7609 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7610 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 7611 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7612 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 7613 | /* clock.dot is the fast clock */ |
| 7614 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7615 | } |
| 7616 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7617 | static void |
| 7618 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7619 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7620 | { |
| 7621 | struct drm_device *dev = crtc->base.dev; |
| 7622 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7623 | u32 val, base, offset; |
| 7624 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7625 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7626 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7627 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7628 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7629 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7630 | val = I915_READ(DSPCNTR(plane)); |
| 7631 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 7632 | return; |
| 7633 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7634 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7635 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7636 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7637 | return; |
| 7638 | } |
| 7639 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7640 | fb = &intel_fb->base; |
| 7641 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7642 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7643 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7644 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7645 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7646 | } |
| 7647 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7648 | |
| 7649 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7650 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7651 | fb->pixel_format = fourcc; |
| 7652 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7653 | |
| 7654 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7655 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7656 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7657 | else |
| 7658 | offset = I915_READ(DSPLINOFF(plane)); |
| 7659 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7660 | } else { |
| 7661 | base = I915_READ(DSPADDR(plane)); |
| 7662 | } |
| 7663 | plane_config->base = base; |
| 7664 | |
| 7665 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7666 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7667 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7668 | |
| 7669 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7670 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7671 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7672 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 7673 | fb->pixel_format, |
| 7674 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7675 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7676 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7677 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7678 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7679 | pipe_name(pipe), plane, fb->width, fb->height, |
| 7680 | fb->bits_per_pixel, base, fb->pitches[0], |
| 7681 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7682 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7683 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7684 | } |
| 7685 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7686 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7687 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7688 | { |
| 7689 | struct drm_device *dev = crtc->base.dev; |
| 7690 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7691 | int pipe = pipe_config->cpu_transcoder; |
| 7692 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 7693 | intel_clock_t clock; |
| 7694 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 7695 | int refclk = 100000; |
| 7696 | |
| 7697 | mutex_lock(&dev_priv->dpio_lock); |
| 7698 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7699 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7700 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7701 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 7702 | mutex_unlock(&dev_priv->dpio_lock); |
| 7703 | |
| 7704 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 7705 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 7706 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7707 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7708 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7709 | |
| 7710 | chv_clock(refclk, &clock); |
| 7711 | |
| 7712 | /* clock.dot is the fast clock */ |
| 7713 | pipe_config->port_clock = clock.dot / 5; |
| 7714 | } |
| 7715 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7716 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7717 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7718 | { |
| 7719 | struct drm_device *dev = crtc->base.dev; |
| 7720 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7721 | uint32_t tmp; |
| 7722 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 7723 | if (!intel_display_power_is_enabled(dev_priv, |
| 7724 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7725 | return false; |
| 7726 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7727 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7728 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7729 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7730 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7731 | if (!(tmp & PIPECONF_ENABLE)) |
| 7732 | return false; |
| 7733 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7734 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 7735 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7736 | case PIPECONF_6BPC: |
| 7737 | pipe_config->pipe_bpp = 18; |
| 7738 | break; |
| 7739 | case PIPECONF_8BPC: |
| 7740 | pipe_config->pipe_bpp = 24; |
| 7741 | break; |
| 7742 | case PIPECONF_10BPC: |
| 7743 | pipe_config->pipe_bpp = 30; |
| 7744 | break; |
| 7745 | default: |
| 7746 | break; |
| 7747 | } |
| 7748 | } |
| 7749 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7750 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 7751 | pipe_config->limited_color_range = true; |
| 7752 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7753 | if (INTEL_INFO(dev)->gen < 4) |
| 7754 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7755 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7756 | intel_get_pipe_timings(crtc, pipe_config); |
| 7757 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7758 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7759 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7760 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7761 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 7762 | pipe_config->pixel_multiplier = |
| 7763 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7764 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7765 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7766 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 7767 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7768 | pipe_config->pixel_multiplier = |
| 7769 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7770 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7771 | } else { |
| 7772 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7773 | * port and will be fixed up in the encoder->get_config |
| 7774 | * function. */ |
| 7775 | pipe_config->pixel_multiplier = 1; |
| 7776 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7777 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 7778 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7779 | /* |
| 7780 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7781 | * on 830. Filter it out here so that we don't |
| 7782 | * report errors due to that. |
| 7783 | */ |
| 7784 | if (IS_I830(dev)) |
| 7785 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7786 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7787 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7788 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7789 | } else { |
| 7790 | /* Mask out read-only status bits. */ |
| 7791 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7792 | DPLL_PORTC_READY_MASK | |
| 7793 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7794 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7795 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7796 | if (IS_CHERRYVIEW(dev)) |
| 7797 | chv_crtc_clock_get(crtc, pipe_config); |
| 7798 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7799 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7800 | else |
| 7801 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7802 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7803 | return true; |
| 7804 | } |
| 7805 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7806 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7807 | { |
| 7808 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7809 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7810 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7811 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7812 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7813 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7814 | bool has_ck505 = false; |
| 7815 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7816 | |
| 7817 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7818 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7819 | switch (encoder->type) { |
| 7820 | case INTEL_OUTPUT_LVDS: |
| 7821 | has_panel = true; |
| 7822 | has_lvds = true; |
| 7823 | break; |
| 7824 | case INTEL_OUTPUT_EDP: |
| 7825 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7826 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7827 | has_cpu_edp = true; |
| 7828 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7829 | default: |
| 7830 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7831 | } |
| 7832 | } |
| 7833 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7834 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7835 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7836 | can_ssc = has_ck505; |
| 7837 | } else { |
| 7838 | has_ck505 = false; |
| 7839 | can_ssc = true; |
| 7840 | } |
| 7841 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7842 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 7843 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7844 | |
| 7845 | /* Ironlake: try to setup display ref clock before DPLL |
| 7846 | * enabling. This is only under driver's control after |
| 7847 | * PCH B stepping, previous chipset stepping should be |
| 7848 | * ignoring this setting. |
| 7849 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7850 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7851 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7852 | /* As we must carefully and slowly disable/enable each source in turn, |
| 7853 | * compute the final state we want first and check if we need to |
| 7854 | * make any changes at all. |
| 7855 | */ |
| 7856 | final = val; |
| 7857 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7858 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7859 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7860 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7861 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7862 | |
| 7863 | final &= ~DREF_SSC_SOURCE_MASK; |
| 7864 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 7865 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7866 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7867 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7868 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7869 | |
| 7870 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7871 | final |= DREF_SSC1_ENABLE; |
| 7872 | |
| 7873 | if (has_cpu_edp) { |
| 7874 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7875 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 7876 | else |
| 7877 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 7878 | } else |
| 7879 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7880 | } else { |
| 7881 | final |= DREF_SSC_SOURCE_DISABLE; |
| 7882 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7883 | } |
| 7884 | |
| 7885 | if (final == val) |
| 7886 | return; |
| 7887 | |
| 7888 | /* Always enable nonspread source */ |
| 7889 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 7890 | |
| 7891 | if (has_ck505) |
| 7892 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 7893 | else |
| 7894 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7895 | |
| 7896 | if (has_panel) { |
| 7897 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7898 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7899 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7900 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7901 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7902 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7903 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 7904 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7905 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7906 | |
| 7907 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7908 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7909 | POSTING_READ(PCH_DREF_CONTROL); |
| 7910 | udelay(200); |
| 7911 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7912 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7913 | |
| 7914 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7915 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7916 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7917 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7918 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7919 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7920 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7921 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7922 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7923 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7924 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7925 | POSTING_READ(PCH_DREF_CONTROL); |
| 7926 | udelay(200); |
| 7927 | } else { |
| 7928 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 7929 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7930 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7931 | |
| 7932 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7933 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7934 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7935 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7936 | POSTING_READ(PCH_DREF_CONTROL); |
| 7937 | udelay(200); |
| 7938 | |
| 7939 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7940 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7941 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7942 | |
| 7943 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7944 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7945 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7946 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7947 | POSTING_READ(PCH_DREF_CONTROL); |
| 7948 | udelay(200); |
| 7949 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7950 | |
| 7951 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7952 | } |
| 7953 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7954 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7955 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7956 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7957 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7958 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7959 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 7960 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7961 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7962 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 7963 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 7964 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7965 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7966 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7967 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 7968 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7969 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7970 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 7971 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 7972 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7973 | } |
| 7974 | |
| 7975 | /* WaMPhyProgramming:hsw */ |
| 7976 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 7977 | { |
| 7978 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7979 | |
| 7980 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 7981 | tmp &= ~(0xFF << 24); |
| 7982 | tmp |= (0x12 << 24); |
| 7983 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 7984 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7985 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 7986 | tmp |= (1 << 11); |
| 7987 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 7988 | |
| 7989 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 7990 | tmp |= (1 << 11); |
| 7991 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 7992 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7993 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 7994 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7995 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 7996 | |
| 7997 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 7998 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7999 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8000 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8001 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8002 | tmp &= ~(7 << 13); |
| 8003 | tmp |= (5 << 13); |
| 8004 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8005 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8006 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8007 | tmp &= ~(7 << 13); |
| 8008 | tmp |= (5 << 13); |
| 8009 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8010 | |
| 8011 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8012 | tmp &= ~0xFF; |
| 8013 | tmp |= 0x1C; |
| 8014 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8015 | |
| 8016 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8017 | tmp &= ~0xFF; |
| 8018 | tmp |= 0x1C; |
| 8019 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8020 | |
| 8021 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8022 | tmp &= ~(0xFF << 16); |
| 8023 | tmp |= (0x1C << 16); |
| 8024 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8025 | |
| 8026 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8027 | tmp &= ~(0xFF << 16); |
| 8028 | tmp |= (0x1C << 16); |
| 8029 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8030 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8031 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8032 | tmp |= (1 << 27); |
| 8033 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8034 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8035 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8036 | tmp |= (1 << 27); |
| 8037 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8038 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8039 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8040 | tmp &= ~(0xF << 28); |
| 8041 | tmp |= (4 << 28); |
| 8042 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8043 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8044 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8045 | tmp &= ~(0xF << 28); |
| 8046 | tmp |= (4 << 28); |
| 8047 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8048 | } |
| 8049 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8050 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8051 | * Programming" based on the parameters passed: |
| 8052 | * - Sequence to enable CLKOUT_DP |
| 8053 | * - Sequence to enable CLKOUT_DP without spread |
| 8054 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8055 | */ |
| 8056 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 8057 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8058 | { |
| 8059 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8060 | uint32_t reg, tmp; |
| 8061 | |
| 8062 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8063 | with_spread = true; |
| 8064 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 8065 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 8066 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8067 | |
| 8068 | mutex_lock(&dev_priv->dpio_lock); |
| 8069 | |
| 8070 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8071 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8072 | tmp |= SBI_SSCCTL_PATHALT; |
| 8073 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8074 | |
| 8075 | udelay(24); |
| 8076 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8077 | if (with_spread) { |
| 8078 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8079 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8080 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8081 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8082 | if (with_fdi) { |
| 8083 | lpt_reset_fdi_mphy(dev_priv); |
| 8084 | lpt_program_fdi_mphy(dev_priv); |
| 8085 | } |
| 8086 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8087 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8088 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 8089 | SBI_GEN0 : SBI_DBUFF0; |
| 8090 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8091 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8092 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8093 | |
| 8094 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8095 | } |
| 8096 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8097 | /* Sequence to disable CLKOUT_DP */ |
| 8098 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 8099 | { |
| 8100 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8101 | uint32_t reg, tmp; |
| 8102 | |
| 8103 | mutex_lock(&dev_priv->dpio_lock); |
| 8104 | |
| 8105 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 8106 | SBI_GEN0 : SBI_DBUFF0; |
| 8107 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8108 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8109 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8110 | |
| 8111 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8112 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8113 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8114 | tmp |= SBI_SSCCTL_PATHALT; |
| 8115 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8116 | udelay(32); |
| 8117 | } |
| 8118 | tmp |= SBI_SSCCTL_DISABLE; |
| 8119 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8120 | } |
| 8121 | |
| 8122 | mutex_unlock(&dev_priv->dpio_lock); |
| 8123 | } |
| 8124 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8125 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 8126 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8127 | struct intel_encoder *encoder; |
| 8128 | bool has_vga = false; |
| 8129 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8130 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8131 | switch (encoder->type) { |
| 8132 | case INTEL_OUTPUT_ANALOG: |
| 8133 | has_vga = true; |
| 8134 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8135 | default: |
| 8136 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8137 | } |
| 8138 | } |
| 8139 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8140 | if (has_vga) |
| 8141 | lpt_enable_clkout_dp(dev, true, true); |
| 8142 | else |
| 8143 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8144 | } |
| 8145 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8146 | /* |
| 8147 | * Initialize reference clocks when the driver loads |
| 8148 | */ |
| 8149 | void intel_init_pch_refclk(struct drm_device *dev) |
| 8150 | { |
| 8151 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 8152 | ironlake_init_pch_refclk(dev); |
| 8153 | else if (HAS_PCH_LPT(dev)) |
| 8154 | lpt_init_pch_refclk(dev); |
| 8155 | } |
| 8156 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8157 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8158 | { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8159 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8160 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8161 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8162 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8163 | struct drm_connector_state *connector_state; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8164 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8165 | int num_connectors = 0, i; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8166 | bool is_lvds = false; |
| 8167 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8168 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8169 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8170 | continue; |
| 8171 | |
| 8172 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8173 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8174 | switch (encoder->type) { |
| 8175 | case INTEL_OUTPUT_LVDS: |
| 8176 | is_lvds = true; |
| 8177 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8178 | default: |
| 8179 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8180 | } |
| 8181 | num_connectors++; |
| 8182 | } |
| 8183 | |
| 8184 | 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] | 8185 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8186 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8187 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8188 | } |
| 8189 | |
| 8190 | return 120000; |
| 8191 | } |
| 8192 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8193 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8194 | { |
| 8195 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8196 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8197 | int pipe = intel_crtc->pipe; |
| 8198 | uint32_t val; |
| 8199 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8200 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8201 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8202 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8203 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8204 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8205 | break; |
| 8206 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8207 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8208 | break; |
| 8209 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8210 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8211 | break; |
| 8212 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8213 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8214 | break; |
| 8215 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8216 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8217 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8218 | } |
| 8219 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8220 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8221 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8222 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8223 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8224 | val |= PIPECONF_INTERLACED_ILK; |
| 8225 | else |
| 8226 | val |= PIPECONF_PROGRESSIVE; |
| 8227 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8228 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8229 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8230 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8231 | I915_WRITE(PIPECONF(pipe), val); |
| 8232 | POSTING_READ(PIPECONF(pipe)); |
| 8233 | } |
| 8234 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8235 | /* |
| 8236 | * Set up the pipe CSC unit. |
| 8237 | * |
| 8238 | * Currently only full range RGB to limited range RGB conversion |
| 8239 | * is supported, but eventually this should handle various |
| 8240 | * RGB<->YCbCr scenarios as well. |
| 8241 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 8242 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8243 | { |
| 8244 | struct drm_device *dev = crtc->dev; |
| 8245 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8246 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8247 | int pipe = intel_crtc->pipe; |
| 8248 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 8249 | |
| 8250 | /* |
| 8251 | * TODO: Check what kind of values actually come out of the pipe |
| 8252 | * with these coeff/postoff values and adjust to get the best |
| 8253 | * accuracy. Perhaps we even need to take the bpc value into |
| 8254 | * consideration. |
| 8255 | */ |
| 8256 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8257 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8258 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 8259 | |
| 8260 | /* |
| 8261 | * GY/GU and RY/RU should be the other way around according |
| 8262 | * to BSpec, but reality doesn't agree. Just set them up in |
| 8263 | * a way that results in the correct picture. |
| 8264 | */ |
| 8265 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 8266 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 8267 | |
| 8268 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 8269 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 8270 | |
| 8271 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 8272 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 8273 | |
| 8274 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 8275 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 8276 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 8277 | |
| 8278 | if (INTEL_INFO(dev)->gen > 6) { |
| 8279 | uint16_t postoff = 0; |
| 8280 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8281 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 8282 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8283 | |
| 8284 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 8285 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 8286 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 8287 | |
| 8288 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 8289 | } else { |
| 8290 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 8291 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8292 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8293 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 8294 | |
| 8295 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 8296 | } |
| 8297 | } |
| 8298 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8299 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8300 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8301 | struct drm_device *dev = crtc->dev; |
| 8302 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8303 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8304 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8305 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8306 | uint32_t val; |
| 8307 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 8308 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8309 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8310 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8311 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8312 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8313 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8314 | val |= PIPECONF_INTERLACED_ILK; |
| 8315 | else |
| 8316 | val |= PIPECONF_PROGRESSIVE; |
| 8317 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8318 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8319 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 8320 | |
| 8321 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 8322 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8323 | |
Satheeshakrishna M | 3cdf122c | 2014-04-08 15:46:53 +0530 | [diff] [blame] | 8324 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8325 | val = 0; |
| 8326 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8327 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8328 | case 18: |
| 8329 | val |= PIPEMISC_DITHER_6_BPC; |
| 8330 | break; |
| 8331 | case 24: |
| 8332 | val |= PIPEMISC_DITHER_8_BPC; |
| 8333 | break; |
| 8334 | case 30: |
| 8335 | val |= PIPEMISC_DITHER_10_BPC; |
| 8336 | break; |
| 8337 | case 36: |
| 8338 | val |= PIPEMISC_DITHER_12_BPC; |
| 8339 | break; |
| 8340 | default: |
| 8341 | /* Case prevented by pipe_config_set_bpp. */ |
| 8342 | BUG(); |
| 8343 | } |
| 8344 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8345 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8346 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8347 | |
| 8348 | I915_WRITE(PIPEMISC(pipe), val); |
| 8349 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8350 | } |
| 8351 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8352 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8353 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8354 | intel_clock_t *clock, |
| 8355 | bool *has_reduced_clock, |
| 8356 | intel_clock_t *reduced_clock) |
| 8357 | { |
| 8358 | struct drm_device *dev = crtc->dev; |
| 8359 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8360 | int refclk; |
| 8361 | const intel_limit_t *limit; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 8362 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8363 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 8364 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8365 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8366 | refclk = ironlake_get_refclk(crtc_state); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8367 | |
| 8368 | /* |
| 8369 | * Returns a set of divisors for the desired target clock with the given |
| 8370 | * refclk, or FALSE. The returned values represent the clock equation: |
| 8371 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 8372 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 8373 | limit = intel_limit(crtc_state, refclk); |
| 8374 | ret = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8375 | crtc_state->port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 8376 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8377 | if (!ret) |
| 8378 | return false; |
| 8379 | |
| 8380 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 8381 | /* |
| 8382 | * Ensure we match the reduced clock's P to the target clock. |
| 8383 | * If the clocks don't match, we can't switch the display clock |
| 8384 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 8385 | * downclock feature. |
| 8386 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 8387 | *has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 8388 | dev_priv->display.find_dpll(limit, crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 8389 | dev_priv->lvds_downclock, |
| 8390 | refclk, clock, |
| 8391 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8392 | } |
| 8393 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8394 | return true; |
| 8395 | } |
| 8396 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8397 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8398 | { |
| 8399 | /* |
| 8400 | * Account for spread spectrum to avoid |
| 8401 | * oversubscribing the link. Max center spread |
| 8402 | * is 2.5%; use 5% for safety's sake. |
| 8403 | */ |
| 8404 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8405 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8406 | } |
| 8407 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8408 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8409 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8410 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8411 | } |
| 8412 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8413 | 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] | 8414 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8415 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8416 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8417 | { |
| 8418 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8419 | struct drm_device *dev = crtc->dev; |
| 8420 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8421 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8422 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8423 | struct drm_connector_state *connector_state; |
| 8424 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8425 | uint32_t dpll; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8426 | int factor, num_connectors = 0, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 8427 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8428 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8429 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8430 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8431 | continue; |
| 8432 | |
| 8433 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8434 | |
| 8435 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8436 | case INTEL_OUTPUT_LVDS: |
| 8437 | is_lvds = true; |
| 8438 | break; |
| 8439 | case INTEL_OUTPUT_SDVO: |
| 8440 | case INTEL_OUTPUT_HDMI: |
| 8441 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8442 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8443 | default: |
| 8444 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8445 | } |
| 8446 | |
| 8447 | num_connectors++; |
| 8448 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8449 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8450 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8451 | factor = 21; |
| 8452 | if (is_lvds) { |
| 8453 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8454 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 8455 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8456 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8457 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8458 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8459 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8460 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 8461 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8462 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8463 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 8464 | *fp2 |= FP_CB_TUNE; |
| 8465 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8466 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8467 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8468 | if (is_lvds) |
| 8469 | dpll |= DPLLB_MODE_LVDS; |
| 8470 | else |
| 8471 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8472 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8473 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8474 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8475 | |
| 8476 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8477 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8478 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8479 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8480 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8481 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8482 | 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] | 8483 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8484 | 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] | 8485 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8486 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8487 | case 5: |
| 8488 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8489 | break; |
| 8490 | case 7: |
| 8491 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8492 | break; |
| 8493 | case 10: |
| 8494 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8495 | break; |
| 8496 | case 14: |
| 8497 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8498 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8499 | } |
| 8500 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 8501 | 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] | 8502 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8503 | else |
| 8504 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8505 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 8506 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8507 | } |
| 8508 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8509 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8510 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8511 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8512 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8513 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8514 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 8515 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 8516 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8517 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8518 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 8519 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8520 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8521 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 8522 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 8523 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8524 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8525 | &has_reduced_clock, &reduced_clock); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8526 | if (!ok && !crtc_state->clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8527 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8528 | return -EINVAL; |
| 8529 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8530 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8531 | if (!crtc_state->clock_set) { |
| 8532 | crtc_state->dpll.n = clock.n; |
| 8533 | crtc_state->dpll.m1 = clock.m1; |
| 8534 | crtc_state->dpll.m2 = clock.m2; |
| 8535 | crtc_state->dpll.p1 = clock.p1; |
| 8536 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8537 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8538 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8539 | /* 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] | 8540 | if (crtc_state->has_pch_encoder) { |
| 8541 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8542 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8543 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8544 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8545 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8546 | &fp, &reduced_clock, |
| 8547 | has_reduced_clock ? &fp2 : NULL); |
| 8548 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8549 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8550 | crtc_state->dpll_hw_state.fp0 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8551 | if (has_reduced_clock) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8552 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8553 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8554 | crtc_state->dpll_hw_state.fp1 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8555 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8556 | pll = intel_get_shared_dpll(crtc, crtc_state); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8557 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 8558 | 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] | 8559 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 8560 | return -EINVAL; |
| 8561 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8562 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8563 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 8564 | if (is_lvds && has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8565 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 8566 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8567 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8568 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8569 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8570 | } |
| 8571 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8572 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8573 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8574 | { |
| 8575 | struct drm_device *dev = crtc->base.dev; |
| 8576 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8577 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8578 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8579 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8580 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8581 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8582 | & ~TU_SIZE_MASK; |
| 8583 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8584 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8585 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8586 | } |
| 8587 | |
| 8588 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8589 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8590 | struct intel_link_m_n *m_n, |
| 8591 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8592 | { |
| 8593 | struct drm_device *dev = crtc->base.dev; |
| 8594 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8595 | enum pipe pipe = crtc->pipe; |
| 8596 | |
| 8597 | if (INTEL_INFO(dev)->gen >= 5) { |
| 8598 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8599 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8600 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8601 | & ~TU_SIZE_MASK; |
| 8602 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8603 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8604 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8605 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8606 | * gen < 8) and if DRRS is supported (to make sure the |
| 8607 | * registers are not unnecessarily read). |
| 8608 | */ |
| 8609 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8610 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8611 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8612 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8613 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8614 | & ~TU_SIZE_MASK; |
| 8615 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8616 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8617 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8618 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8619 | } else { |
| 8620 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8621 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8622 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8623 | & ~TU_SIZE_MASK; |
| 8624 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8625 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8626 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8627 | } |
| 8628 | } |
| 8629 | |
| 8630 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8631 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8632 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8633 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8634 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8635 | else |
| 8636 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8637 | &pipe_config->dp_m_n, |
| 8638 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8639 | } |
| 8640 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8641 | 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] | 8642 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8643 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8644 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8645 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8646 | } |
| 8647 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8648 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8649 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8650 | { |
| 8651 | struct drm_device *dev = crtc->base.dev; |
| 8652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8653 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8654 | uint32_t ps_ctrl = 0; |
| 8655 | int id = -1; |
| 8656 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8657 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8658 | /* find scaler attached to this pipe */ |
| 8659 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8660 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8661 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8662 | id = i; |
| 8663 | pipe_config->pch_pfit.enabled = true; |
| 8664 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8665 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8666 | break; |
| 8667 | } |
| 8668 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8669 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8670 | scaler_state->scaler_id = id; |
| 8671 | if (id >= 0) { |
| 8672 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8673 | } else { |
| 8674 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8675 | } |
| 8676 | } |
| 8677 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8678 | static void |
| 8679 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8680 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8681 | { |
| 8682 | struct drm_device *dev = crtc->base.dev; |
| 8683 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8684 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8685 | int pipe = crtc->pipe; |
| 8686 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8687 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8688 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8689 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8690 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8691 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8692 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8693 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8694 | return; |
| 8695 | } |
| 8696 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8697 | fb = &intel_fb->base; |
| 8698 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8699 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8700 | if (!(val & PLANE_CTL_ENABLE)) |
| 8701 | goto error; |
| 8702 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8703 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 8704 | fourcc = skl_format_to_fourcc(pixel_format, |
| 8705 | val & PLANE_CTL_ORDER_RGBX, |
| 8706 | val & PLANE_CTL_ALPHA_MASK); |
| 8707 | fb->pixel_format = fourcc; |
| 8708 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 8709 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8710 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8711 | switch (tiling) { |
| 8712 | case PLANE_CTL_TILED_LINEAR: |
| 8713 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 8714 | break; |
| 8715 | case PLANE_CTL_TILED_X: |
| 8716 | plane_config->tiling = I915_TILING_X; |
| 8717 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8718 | break; |
| 8719 | case PLANE_CTL_TILED_Y: |
| 8720 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 8721 | break; |
| 8722 | case PLANE_CTL_TILED_YF: |
| 8723 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 8724 | break; |
| 8725 | default: |
| 8726 | MISSING_CASE(tiling); |
| 8727 | goto error; |
| 8728 | } |
| 8729 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8730 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 8731 | plane_config->base = base; |
| 8732 | |
| 8733 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 8734 | |
| 8735 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 8736 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8737 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8738 | |
| 8739 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8740 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 8741 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8742 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8743 | |
| 8744 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8745 | fb->pixel_format, |
| 8746 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8747 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8748 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8749 | |
| 8750 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8751 | pipe_name(pipe), fb->width, fb->height, |
| 8752 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8753 | plane_config->size); |
| 8754 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8755 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8756 | return; |
| 8757 | |
| 8758 | error: |
| 8759 | kfree(fb); |
| 8760 | } |
| 8761 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8762 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8763 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8764 | { |
| 8765 | struct drm_device *dev = crtc->base.dev; |
| 8766 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8767 | uint32_t tmp; |
| 8768 | |
| 8769 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8770 | |
| 8771 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8772 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8773 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8774 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8775 | |
| 8776 | /* We currently do not free assignements of panel fitters on |
| 8777 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8778 | * differentiates them) so just WARN about this case for now. */ |
| 8779 | if (IS_GEN7(dev)) { |
| 8780 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8781 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8782 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8783 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8784 | } |
| 8785 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8786 | static void |
| 8787 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8788 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8789 | { |
| 8790 | struct drm_device *dev = crtc->base.dev; |
| 8791 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8792 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8793 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8794 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8795 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8796 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8797 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8798 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8799 | val = I915_READ(DSPCNTR(pipe)); |
| 8800 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8801 | return; |
| 8802 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8803 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8804 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8805 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8806 | return; |
| 8807 | } |
| 8808 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8809 | fb = &intel_fb->base; |
| 8810 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8811 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8812 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8813 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8814 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8815 | } |
| 8816 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8817 | |
| 8818 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8819 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8820 | fb->pixel_format = fourcc; |
| 8821 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8822 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8823 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8824 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8825 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8826 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8827 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8828 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8829 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8830 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8831 | } |
| 8832 | plane_config->base = base; |
| 8833 | |
| 8834 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8835 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8836 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8837 | |
| 8838 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8839 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8840 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8841 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8842 | fb->pixel_format, |
| 8843 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8844 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8845 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8846 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8847 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8848 | pipe_name(pipe), fb->width, fb->height, |
| 8849 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8850 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8851 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8852 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8853 | } |
| 8854 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8855 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8856 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8857 | { |
| 8858 | struct drm_device *dev = crtc->base.dev; |
| 8859 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8860 | uint32_t tmp; |
| 8861 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8862 | if (!intel_display_power_is_enabled(dev_priv, |
| 8863 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8864 | return false; |
| 8865 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8866 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8867 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8868 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8869 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8870 | if (!(tmp & PIPECONF_ENABLE)) |
| 8871 | return false; |
| 8872 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8873 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8874 | case PIPECONF_6BPC: |
| 8875 | pipe_config->pipe_bpp = 18; |
| 8876 | break; |
| 8877 | case PIPECONF_8BPC: |
| 8878 | pipe_config->pipe_bpp = 24; |
| 8879 | break; |
| 8880 | case PIPECONF_10BPC: |
| 8881 | pipe_config->pipe_bpp = 30; |
| 8882 | break; |
| 8883 | case PIPECONF_12BPC: |
| 8884 | pipe_config->pipe_bpp = 36; |
| 8885 | break; |
| 8886 | default: |
| 8887 | break; |
| 8888 | } |
| 8889 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8890 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8891 | pipe_config->limited_color_range = true; |
| 8892 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8893 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8894 | struct intel_shared_dpll *pll; |
| 8895 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8896 | pipe_config->has_pch_encoder = true; |
| 8897 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8898 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8899 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8900 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8901 | |
| 8902 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8903 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8904 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 8905 | pipe_config->shared_dpll = |
| 8906 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8907 | } else { |
| 8908 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8909 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 8910 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 8911 | else |
| 8912 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 8913 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8914 | |
| 8915 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8916 | |
| 8917 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8918 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8919 | |
| 8920 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8921 | pipe_config->pixel_multiplier = |
| 8922 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8923 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8924 | |
| 8925 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8926 | } else { |
| 8927 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8928 | } |
| 8929 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8930 | intel_get_pipe_timings(crtc, pipe_config); |
| 8931 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8932 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8933 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8934 | return true; |
| 8935 | } |
| 8936 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8937 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8938 | { |
| 8939 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8940 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8941 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 8942 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8943 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8944 | pipe_name(crtc->pipe)); |
| 8945 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8946 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 8947 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 8948 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 8949 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
| 8950 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 8951 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8952 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8953 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8954 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8955 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8956 | 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] | 8957 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8958 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8959 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8960 | 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] | 8961 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 8962 | /* |
| 8963 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 8964 | * interrupts remain enabled. We used to check for that, but since it's |
| 8965 | * gen-specific and since we only disable LCPLL after we fully disable |
| 8966 | * the interrupts, the check below should be enough. |
| 8967 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8968 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8969 | } |
| 8970 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8971 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 8972 | { |
| 8973 | struct drm_device *dev = dev_priv->dev; |
| 8974 | |
| 8975 | if (IS_HASWELL(dev)) |
| 8976 | return I915_READ(D_COMP_HSW); |
| 8977 | else |
| 8978 | return I915_READ(D_COMP_BDW); |
| 8979 | } |
| 8980 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8981 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 8982 | { |
| 8983 | struct drm_device *dev = dev_priv->dev; |
| 8984 | |
| 8985 | if (IS_HASWELL(dev)) { |
| 8986 | mutex_lock(&dev_priv->rps.hw_lock); |
| 8987 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 8988 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 8989 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8990 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 8991 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8992 | I915_WRITE(D_COMP_BDW, val); |
| 8993 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8994 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8995 | } |
| 8996 | |
| 8997 | /* |
| 8998 | * This function implements pieces of two sequences from BSpec: |
| 8999 | * - Sequence for display software to disable LCPLL |
| 9000 | * - Sequence for display software to allow package C8+ |
| 9001 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9002 | * register. Callers should take care of disabling all the display engine |
| 9003 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9004 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9005 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9006 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9007 | { |
| 9008 | uint32_t val; |
| 9009 | |
| 9010 | assert_can_disable_lcpll(dev_priv); |
| 9011 | |
| 9012 | val = I915_READ(LCPLL_CTL); |
| 9013 | |
| 9014 | if (switch_to_fclk) { |
| 9015 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9016 | I915_WRITE(LCPLL_CTL, val); |
| 9017 | |
| 9018 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9019 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9020 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9021 | |
| 9022 | val = I915_READ(LCPLL_CTL); |
| 9023 | } |
| 9024 | |
| 9025 | val |= LCPLL_PLL_DISABLE; |
| 9026 | I915_WRITE(LCPLL_CTL, val); |
| 9027 | POSTING_READ(LCPLL_CTL); |
| 9028 | |
| 9029 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 9030 | DRM_ERROR("LCPLL still locked\n"); |
| 9031 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9032 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9033 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9034 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9035 | ndelay(100); |
| 9036 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9037 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9038 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9039 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9040 | |
| 9041 | if (allow_power_down) { |
| 9042 | val = I915_READ(LCPLL_CTL); |
| 9043 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9044 | I915_WRITE(LCPLL_CTL, val); |
| 9045 | POSTING_READ(LCPLL_CTL); |
| 9046 | } |
| 9047 | } |
| 9048 | |
| 9049 | /* |
| 9050 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9051 | * source. |
| 9052 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9053 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9054 | { |
| 9055 | uint32_t val; |
| 9056 | |
| 9057 | val = I915_READ(LCPLL_CTL); |
| 9058 | |
| 9059 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9060 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9061 | return; |
| 9062 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9063 | /* |
| 9064 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9065 | * 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] | 9066 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9067 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9068 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9069 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9070 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9071 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9072 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9073 | } |
| 9074 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9075 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9076 | val |= D_COMP_COMP_FORCE; |
| 9077 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9078 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9079 | |
| 9080 | val = I915_READ(LCPLL_CTL); |
| 9081 | val &= ~LCPLL_PLL_DISABLE; |
| 9082 | I915_WRITE(LCPLL_CTL, val); |
| 9083 | |
| 9084 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 9085 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9086 | |
| 9087 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9088 | val = I915_READ(LCPLL_CTL); |
| 9089 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9090 | I915_WRITE(LCPLL_CTL, val); |
| 9091 | |
| 9092 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9093 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9094 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9095 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9096 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9097 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9098 | } |
| 9099 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9100 | /* |
| 9101 | * Package states C8 and deeper are really deep PC states that can only be |
| 9102 | * reached when all the devices on the system allow it, so even if the graphics |
| 9103 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9104 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9105 | * |
| 9106 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9107 | * well is disabled and most interrupts are disabled, and these are also |
| 9108 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9109 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9110 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9111 | * hang the machine. |
| 9112 | * |
| 9113 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9114 | * the state of some registers, so when we come back from PC8+ we need to |
| 9115 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9116 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9117 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9118 | * because of the runtime PM support). |
| 9119 | * |
| 9120 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9121 | * documentation. |
| 9122 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9123 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9124 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9125 | struct drm_device *dev = dev_priv->dev; |
| 9126 | uint32_t val; |
| 9127 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9128 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9129 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9130 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 9131 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9132 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9133 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9134 | } |
| 9135 | |
| 9136 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9137 | hsw_disable_lcpll(dev_priv, true, true); |
| 9138 | } |
| 9139 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9140 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9141 | { |
| 9142 | struct drm_device *dev = dev_priv->dev; |
| 9143 | uint32_t val; |
| 9144 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9145 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9146 | |
| 9147 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9148 | lpt_init_pch_refclk(dev); |
| 9149 | |
| 9150 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 9151 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9152 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9153 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9154 | } |
| 9155 | |
| 9156 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9157 | } |
| 9158 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9159 | static void broxton_modeset_global_resources(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9160 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9161 | struct drm_device *dev = old_state->dev; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9162 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9163 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9164 | int req_cdclk; |
| 9165 | |
| 9166 | /* see the comment in valleyview_modeset_global_resources */ |
| 9167 | if (WARN_ON(max_pixclk < 0)) |
| 9168 | return; |
| 9169 | |
| 9170 | req_cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); |
| 9171 | |
| 9172 | if (req_cdclk != dev_priv->cdclk_freq) |
| 9173 | broxton_set_cdclk(dev, req_cdclk); |
| 9174 | } |
| 9175 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9176 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9177 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9178 | { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9179 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 9180 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9181 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9182 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 9183 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9184 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9185 | } |
| 9186 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9187 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9188 | enum port port, |
| 9189 | struct intel_crtc_state *pipe_config) |
| 9190 | { |
| 9191 | switch (port) { |
| 9192 | case PORT_A: |
| 9193 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
| 9194 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 9195 | break; |
| 9196 | case PORT_B: |
| 9197 | pipe_config->ddi_pll_sel = SKL_DPLL1; |
| 9198 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 9199 | break; |
| 9200 | case PORT_C: |
| 9201 | pipe_config->ddi_pll_sel = SKL_DPLL2; |
| 9202 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 9203 | break; |
| 9204 | default: |
| 9205 | DRM_ERROR("Incorrect port type\n"); |
| 9206 | } |
| 9207 | } |
| 9208 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9209 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9210 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9211 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9212 | { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9213 | u32 temp, dpll_ctl1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9214 | |
| 9215 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 9216 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 9217 | |
| 9218 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9219 | case SKL_DPLL0: |
| 9220 | /* |
| 9221 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part |
| 9222 | * of the shared DPLL framework and thus needs to be read out |
| 9223 | * separately |
| 9224 | */ |
| 9225 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 9226 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; |
| 9227 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9228 | case SKL_DPLL1: |
| 9229 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 9230 | break; |
| 9231 | case SKL_DPLL2: |
| 9232 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 9233 | break; |
| 9234 | case SKL_DPLL3: |
| 9235 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 9236 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9237 | } |
| 9238 | } |
| 9239 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9240 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9241 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9242 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9243 | { |
| 9244 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 9245 | |
| 9246 | switch (pipe_config->ddi_pll_sel) { |
| 9247 | case PORT_CLK_SEL_WRPLL1: |
| 9248 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 9249 | break; |
| 9250 | case PORT_CLK_SEL_WRPLL2: |
| 9251 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 9252 | break; |
| 9253 | } |
| 9254 | } |
| 9255 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9256 | 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] | 9257 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9258 | { |
| 9259 | struct drm_device *dev = crtc->base.dev; |
| 9260 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9261 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9262 | enum port port; |
| 9263 | uint32_t tmp; |
| 9264 | |
| 9265 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9266 | |
| 9267 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9268 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9269 | if (IS_SKYLAKE(dev)) |
| 9270 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9271 | else if (IS_BROXTON(dev)) |
| 9272 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9273 | else |
| 9274 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9275 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9276 | if (pipe_config->shared_dpll >= 0) { |
| 9277 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 9278 | |
| 9279 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 9280 | &pipe_config->dpll_hw_state)); |
| 9281 | } |
| 9282 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9283 | /* |
| 9284 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9285 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9286 | * the PCH transcoder is on. |
| 9287 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9288 | if (INTEL_INFO(dev)->gen < 9 && |
| 9289 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9290 | pipe_config->has_pch_encoder = true; |
| 9291 | |
| 9292 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9293 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9294 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9295 | |
| 9296 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9297 | } |
| 9298 | } |
| 9299 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9300 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9301 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9302 | { |
| 9303 | struct drm_device *dev = crtc->base.dev; |
| 9304 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9305 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9306 | uint32_t tmp; |
| 9307 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 9308 | if (!intel_display_power_is_enabled(dev_priv, |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9309 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 9310 | return false; |
| 9311 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9312 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9313 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 9314 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9315 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9316 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9317 | enum pipe trans_edp_pipe; |
| 9318 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9319 | default: |
| 9320 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 9321 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9322 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9323 | trans_edp_pipe = PIPE_A; |
| 9324 | break; |
| 9325 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9326 | trans_edp_pipe = PIPE_B; |
| 9327 | break; |
| 9328 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9329 | trans_edp_pipe = PIPE_C; |
| 9330 | break; |
| 9331 | } |
| 9332 | |
| 9333 | if (trans_edp_pipe == crtc->pipe) |
| 9334 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9335 | } |
| 9336 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 9337 | if (!intel_display_power_is_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9338 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 9339 | return false; |
| 9340 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9341 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9342 | if (!(tmp & PIPECONF_ENABLE)) |
| 9343 | return false; |
| 9344 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9345 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9346 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9347 | intel_get_pipe_timings(crtc, pipe_config); |
| 9348 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9349 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9350 | skl_init_scalers(dev, crtc, pipe_config); |
| 9351 | } |
| 9352 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9353 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9354 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9355 | if (INTEL_INFO(dev)->gen == 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9356 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9357 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9358 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9359 | else |
| 9360 | MISSING_CASE(INTEL_INFO(dev)->gen); |
| 9361 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9362 | } else { |
| 9363 | pipe_config->scaler_state.scaler_id = -1; |
| 9364 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9365 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9366 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 9367 | if (IS_HASWELL(dev)) |
| 9368 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 9369 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 9370 | |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9371 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
| 9372 | pipe_config->pixel_multiplier = |
| 9373 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9374 | } else { |
| 9375 | pipe_config->pixel_multiplier = 1; |
| 9376 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9377 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9378 | return true; |
| 9379 | } |
| 9380 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9381 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 9382 | { |
| 9383 | struct drm_device *dev = crtc->dev; |
| 9384 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9385 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9386 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9387 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9388 | if (base) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9389 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
| 9390 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9391 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 9392 | |
| 9393 | switch (stride) { |
| 9394 | default: |
| 9395 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 9396 | width, stride); |
| 9397 | stride = 256; |
| 9398 | /* fallthrough */ |
| 9399 | case 256: |
| 9400 | case 512: |
| 9401 | case 1024: |
| 9402 | case 2048: |
| 9403 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9404 | } |
| 9405 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9406 | cntl |= CURSOR_ENABLE | |
| 9407 | CURSOR_GAMMA_ENABLE | |
| 9408 | CURSOR_FORMAT_ARGB | |
| 9409 | CURSOR_STRIDE(stride); |
| 9410 | |
| 9411 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9412 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9413 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9414 | if (intel_crtc->cursor_cntl != 0 && |
| 9415 | (intel_crtc->cursor_base != base || |
| 9416 | intel_crtc->cursor_size != size || |
| 9417 | intel_crtc->cursor_cntl != cntl)) { |
| 9418 | /* On these chipsets we can only modify the base/size/stride |
| 9419 | * whilst the cursor is disabled. |
| 9420 | */ |
| 9421 | I915_WRITE(_CURACNTR, 0); |
| 9422 | POSTING_READ(_CURACNTR); |
| 9423 | intel_crtc->cursor_cntl = 0; |
| 9424 | } |
| 9425 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9426 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9427 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9428 | intel_crtc->cursor_base = base; |
| 9429 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9430 | |
| 9431 | if (intel_crtc->cursor_size != size) { |
| 9432 | I915_WRITE(CURSIZE, size); |
| 9433 | intel_crtc->cursor_size = size; |
| 9434 | } |
| 9435 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9436 | if (intel_crtc->cursor_cntl != cntl) { |
| 9437 | I915_WRITE(_CURACNTR, cntl); |
| 9438 | POSTING_READ(_CURACNTR); |
| 9439 | intel_crtc->cursor_cntl = cntl; |
| 9440 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9441 | } |
| 9442 | |
| 9443 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 9444 | { |
| 9445 | struct drm_device *dev = crtc->dev; |
| 9446 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9447 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9448 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9449 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9450 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9451 | cntl = 0; |
| 9452 | if (base) { |
| 9453 | cntl = MCURSOR_GAMMA_ENABLE; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9454 | switch (intel_crtc->base.cursor->state->crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9455 | case 64: |
| 9456 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 9457 | break; |
| 9458 | case 128: |
| 9459 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 9460 | break; |
| 9461 | case 256: |
| 9462 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 9463 | break; |
| 9464 | default: |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9465 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9466 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9467 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9468 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 9469 | |
| 9470 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 9471 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9472 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9473 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 9474 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9475 | cntl |= CURSOR_ROTATE_180; |
| 9476 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9477 | if (intel_crtc->cursor_cntl != cntl) { |
| 9478 | I915_WRITE(CURCNTR(pipe), cntl); |
| 9479 | POSTING_READ(CURCNTR(pipe)); |
| 9480 | intel_crtc->cursor_cntl = cntl; |
| 9481 | } |
| 9482 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 9483 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9484 | I915_WRITE(CURBASE(pipe), base); |
| 9485 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9486 | |
| 9487 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 9488 | } |
| 9489 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9490 | /* 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] | 9491 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 9492 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9493 | { |
| 9494 | struct drm_device *dev = crtc->dev; |
| 9495 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9496 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9497 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 9498 | int x = crtc->cursor_x; |
| 9499 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9500 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9501 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9502 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9503 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9504 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9505 | if (x >= intel_crtc->config->pipe_src_w) |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9506 | base = 0; |
| 9507 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9508 | if (y >= intel_crtc->config->pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9509 | base = 0; |
| 9510 | |
| 9511 | if (x < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9512 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9513 | base = 0; |
| 9514 | |
| 9515 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9516 | x = -x; |
| 9517 | } |
| 9518 | pos |= x << CURSOR_X_SHIFT; |
| 9519 | |
| 9520 | if (y < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9521 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9522 | base = 0; |
| 9523 | |
| 9524 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9525 | y = -y; |
| 9526 | } |
| 9527 | pos |= y << CURSOR_Y_SHIFT; |
| 9528 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9529 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9530 | return; |
| 9531 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9532 | I915_WRITE(CURPOS(pipe), pos); |
| 9533 | |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9534 | /* ILK+ do this automagically */ |
| 9535 | if (HAS_GMCH_DISPLAY(dev) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 9536 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9537 | base += (intel_crtc->base.cursor->state->crtc_h * |
| 9538 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9539 | } |
| 9540 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 9541 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9542 | i845_update_cursor(crtc, base); |
| 9543 | else |
| 9544 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9545 | } |
| 9546 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9547 | static bool cursor_size_ok(struct drm_device *dev, |
| 9548 | uint32_t width, uint32_t height) |
| 9549 | { |
| 9550 | if (width == 0 || height == 0) |
| 9551 | return false; |
| 9552 | |
| 9553 | /* |
| 9554 | * 845g/865g are special in that they are only limited by |
| 9555 | * the width of their cursors, the height is arbitrary up to |
| 9556 | * the precision of the register. Everything else requires |
| 9557 | * square cursors, limited to a few power-of-two sizes. |
| 9558 | */ |
| 9559 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 9560 | if ((width & 63) != 0) |
| 9561 | return false; |
| 9562 | |
| 9563 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 9564 | return false; |
| 9565 | |
| 9566 | if (height > 1023) |
| 9567 | return false; |
| 9568 | } else { |
| 9569 | switch (width | height) { |
| 9570 | case 256: |
| 9571 | case 128: |
| 9572 | if (IS_GEN2(dev)) |
| 9573 | return false; |
| 9574 | case 64: |
| 9575 | break; |
| 9576 | default: |
| 9577 | return false; |
| 9578 | } |
| 9579 | } |
| 9580 | |
| 9581 | return true; |
| 9582 | } |
| 9583 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9584 | 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] | 9585 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9586 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9587 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9588 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9589 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9590 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9591 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 9592 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 9593 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 9594 | } |
| 9595 | |
| 9596 | intel_crtc_load_lut(crtc); |
| 9597 | } |
| 9598 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9599 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 9600 | static struct drm_display_mode load_detect_mode = { |
| 9601 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 9602 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 9603 | }; |
| 9604 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 9605 | struct drm_framebuffer * |
| 9606 | __intel_framebuffer_create(struct drm_device *dev, |
| 9607 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 9608 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9609 | { |
| 9610 | struct intel_framebuffer *intel_fb; |
| 9611 | int ret; |
| 9612 | |
| 9613 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 9614 | if (!intel_fb) { |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 9615 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9616 | return ERR_PTR(-ENOMEM); |
| 9617 | } |
| 9618 | |
| 9619 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9620 | if (ret) |
| 9621 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9622 | |
| 9623 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9624 | err: |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 9625 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9626 | kfree(intel_fb); |
| 9627 | |
| 9628 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9629 | } |
| 9630 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 9631 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 9632 | intel_framebuffer_create(struct drm_device *dev, |
| 9633 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 9634 | struct drm_i915_gem_object *obj) |
| 9635 | { |
| 9636 | struct drm_framebuffer *fb; |
| 9637 | int ret; |
| 9638 | |
| 9639 | ret = i915_mutex_lock_interruptible(dev); |
| 9640 | if (ret) |
| 9641 | return ERR_PTR(ret); |
| 9642 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 9643 | mutex_unlock(&dev->struct_mutex); |
| 9644 | |
| 9645 | return fb; |
| 9646 | } |
| 9647 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9648 | static u32 |
| 9649 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 9650 | { |
| 9651 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 9652 | return ALIGN(pitch, 64); |
| 9653 | } |
| 9654 | |
| 9655 | static u32 |
| 9656 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 9657 | { |
| 9658 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 9659 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9660 | } |
| 9661 | |
| 9662 | static struct drm_framebuffer * |
| 9663 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 9664 | struct drm_display_mode *mode, |
| 9665 | int depth, int bpp) |
| 9666 | { |
| 9667 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 9668 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9669 | |
| 9670 | obj = i915_gem_alloc_object(dev, |
| 9671 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 9672 | if (obj == NULL) |
| 9673 | return ERR_PTR(-ENOMEM); |
| 9674 | |
| 9675 | mode_cmd.width = mode->hdisplay; |
| 9676 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9677 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 9678 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 9679 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9680 | |
| 9681 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 9682 | } |
| 9683 | |
| 9684 | static struct drm_framebuffer * |
| 9685 | mode_fits_in_fbdev(struct drm_device *dev, |
| 9686 | struct drm_display_mode *mode) |
| 9687 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 9688 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9689 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9690 | struct drm_i915_gem_object *obj; |
| 9691 | struct drm_framebuffer *fb; |
| 9692 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 9693 | if (!dev_priv->fbdev) |
| 9694 | return NULL; |
| 9695 | |
| 9696 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9697 | return NULL; |
| 9698 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 9699 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 9700 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9701 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 9702 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9703 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 9704 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9705 | return NULL; |
| 9706 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9707 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9708 | return NULL; |
| 9709 | |
| 9710 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 9711 | #else |
| 9712 | return NULL; |
| 9713 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9714 | } |
| 9715 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9716 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 9717 | struct drm_crtc *crtc, |
| 9718 | struct drm_display_mode *mode, |
| 9719 | struct drm_framebuffer *fb, |
| 9720 | int x, int y) |
| 9721 | { |
| 9722 | struct drm_plane_state *plane_state; |
| 9723 | int hdisplay, vdisplay; |
| 9724 | int ret; |
| 9725 | |
| 9726 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 9727 | if (IS_ERR(plane_state)) |
| 9728 | return PTR_ERR(plane_state); |
| 9729 | |
| 9730 | if (mode) |
| 9731 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 9732 | else |
| 9733 | hdisplay = vdisplay = 0; |
| 9734 | |
| 9735 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 9736 | if (ret) |
| 9737 | return ret; |
| 9738 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 9739 | plane_state->crtc_x = 0; |
| 9740 | plane_state->crtc_y = 0; |
| 9741 | plane_state->crtc_w = hdisplay; |
| 9742 | plane_state->crtc_h = vdisplay; |
| 9743 | plane_state->src_x = x << 16; |
| 9744 | plane_state->src_y = y << 16; |
| 9745 | plane_state->src_w = hdisplay << 16; |
| 9746 | plane_state->src_h = vdisplay << 16; |
| 9747 | |
| 9748 | return 0; |
| 9749 | } |
| 9750 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9751 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9752 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9753 | struct intel_load_detect_pipe *old, |
| 9754 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9755 | { |
| 9756 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9757 | struct intel_encoder *intel_encoder = |
| 9758 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9759 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9760 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9761 | struct drm_crtc *crtc = NULL; |
| 9762 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9763 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9764 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9765 | struct drm_atomic_state *state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9766 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9767 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9768 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9769 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9770 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9771 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9772 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9773 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9774 | retry: |
| 9775 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 9776 | if (ret) |
| 9777 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 9778 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9779 | /* |
| 9780 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9781 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9782 | * - if the connector already has an assigned crtc, use it (but make |
| 9783 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9784 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9785 | * - try to find the first unused crtc that can drive this connector, |
| 9786 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9787 | */ |
| 9788 | |
| 9789 | /* See if we already have a CRTC for this connector */ |
| 9790 | if (encoder->crtc) { |
| 9791 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9792 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9793 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9794 | if (ret) |
| 9795 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 9796 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 9797 | if (ret) |
| 9798 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9799 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9800 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9801 | old->load_detect_temp = false; |
| 9802 | |
| 9803 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9804 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 9805 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9806 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9807 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9808 | } |
| 9809 | |
| 9810 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9811 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9812 | i++; |
| 9813 | if (!(encoder->possible_crtcs & (1 << i))) |
| 9814 | continue; |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9815 | if (possible_crtc->state->enable) |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 9816 | continue; |
| 9817 | /* This can occur when applying the pipe A quirk on resume. */ |
| 9818 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 9819 | continue; |
| 9820 | |
| 9821 | crtc = possible_crtc; |
| 9822 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9823 | } |
| 9824 | |
| 9825 | /* |
| 9826 | * If we didn't find an unused CRTC, don't use any. |
| 9827 | */ |
| 9828 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9829 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9830 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9831 | } |
| 9832 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9833 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9834 | if (ret) |
| 9835 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 9836 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 9837 | if (ret) |
| 9838 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9839 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 9840 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9841 | |
| 9842 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9843 | intel_crtc->new_enabled = true; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9844 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9845 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9846 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9847 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9848 | state = drm_atomic_state_alloc(dev); |
| 9849 | if (!state) |
| 9850 | return false; |
| 9851 | |
| 9852 | state->acquire_ctx = ctx; |
| 9853 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9854 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9855 | if (IS_ERR(connector_state)) { |
| 9856 | ret = PTR_ERR(connector_state); |
| 9857 | goto fail; |
| 9858 | } |
| 9859 | |
| 9860 | connector_state->crtc = crtc; |
| 9861 | connector_state->best_encoder = &intel_encoder->base; |
| 9862 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9863 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 9864 | if (IS_ERR(crtc_state)) { |
| 9865 | ret = PTR_ERR(crtc_state); |
| 9866 | goto fail; |
| 9867 | } |
| 9868 | |
| 9869 | crtc_state->base.enable = true; |
| 9870 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9871 | if (!mode) |
| 9872 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9873 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9874 | /* We need a framebuffer large enough to accommodate all accesses |
| 9875 | * that the plane may generate whilst we perform load detection. |
| 9876 | * We can not rely on the fbcon either being present (we get called |
| 9877 | * during its initialisation to detect all boot displays, or it may |
| 9878 | * not even exist) or that it is large enough to satisfy the |
| 9879 | * requested mode. |
| 9880 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9881 | fb = mode_fits_in_fbdev(dev, mode); |
| 9882 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9883 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9884 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 9885 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9886 | } else |
| 9887 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9888 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9889 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9890 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9891 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9892 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9893 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 9894 | if (ret) |
| 9895 | goto fail; |
| 9896 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 9897 | drm_mode_copy(&crtc_state->base.mode, mode); |
| 9898 | |
| 9899 | if (intel_set_mode(crtc, state)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9900 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9901 | if (old->release_fb) |
| 9902 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9903 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9904 | } |
Daniel Vetter | 9128b04 | 2015-03-03 17:31:21 +0100 | [diff] [blame] | 9905 | crtc->primary->crtc = crtc; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9906 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9907 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9908 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9909 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9910 | |
| 9911 | fail: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9912 | intel_crtc->new_enabled = crtc->state->enable; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9913 | fail_unlock: |
Ander Conselvan de Oliveira | e5d958e | 2015-04-21 17:12:57 +0300 | [diff] [blame] | 9914 | drm_atomic_state_free(state); |
| 9915 | state = NULL; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9916 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9917 | if (ret == -EDEADLK) { |
| 9918 | drm_modeset_backoff(ctx); |
| 9919 | goto retry; |
| 9920 | } |
| 9921 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9922 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9923 | } |
| 9924 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9925 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 9926 | struct intel_load_detect_pipe *old, |
| 9927 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9928 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9929 | struct drm_device *dev = connector->dev; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9930 | struct intel_encoder *intel_encoder = |
| 9931 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9932 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9933 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9934 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9935 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9936 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9937 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9938 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9939 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9940 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9941 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9942 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9943 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9944 | if (old->load_detect_temp) { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9945 | state = drm_atomic_state_alloc(dev); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9946 | if (!state) |
| 9947 | goto fail; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9948 | |
| 9949 | state->acquire_ctx = ctx; |
| 9950 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9951 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9952 | if (IS_ERR(connector_state)) |
| 9953 | goto fail; |
| 9954 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9955 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 9956 | if (IS_ERR(crtc_state)) |
| 9957 | goto fail; |
| 9958 | |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9959 | to_intel_connector(connector)->new_encoder = NULL; |
| 9960 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9961 | intel_crtc->new_enabled = false; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9962 | |
| 9963 | connector_state->best_encoder = NULL; |
| 9964 | connector_state->crtc = NULL; |
| 9965 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9966 | crtc_state->base.enable = false; |
| 9967 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9968 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
| 9969 | 0, 0); |
| 9970 | if (ret) |
| 9971 | goto fail; |
| 9972 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 9973 | ret = intel_set_mode(crtc, state); |
| 9974 | if (ret) |
| 9975 | goto fail; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9976 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 9977 | if (old->release_fb) { |
| 9978 | drm_framebuffer_unregister_private(old->release_fb); |
| 9979 | drm_framebuffer_unreference(old->release_fb); |
| 9980 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9981 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 9982 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9983 | } |
| 9984 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 9985 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9986 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 9987 | connector->funcs->dpms(connector, old->dpms_mode); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9988 | |
| 9989 | return; |
| 9990 | fail: |
| 9991 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); |
| 9992 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9993 | } |
| 9994 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9995 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9996 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9997 | { |
| 9998 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9999 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10000 | |
| 10001 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10002 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10003 | else if (HAS_PCH_SPLIT(dev)) |
| 10004 | return 120000; |
| 10005 | else if (!IS_GEN2(dev)) |
| 10006 | return 96000; |
| 10007 | else |
| 10008 | return 48000; |
| 10009 | } |
| 10010 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10011 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10012 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10013 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10014 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10015 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10016 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10017 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10018 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10019 | u32 fp; |
| 10020 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10021 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10022 | |
| 10023 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10024 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10025 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10026 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10027 | |
| 10028 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10029 | if (IS_PINEVIEW(dev)) { |
| 10030 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10031 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10032 | } else { |
| 10033 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10034 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10035 | } |
| 10036 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 10037 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10038 | if (IS_PINEVIEW(dev)) |
| 10039 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10040 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10041 | else |
| 10042 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10043 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10044 | |
| 10045 | switch (dpll & DPLL_MODE_MASK) { |
| 10046 | case DPLLB_MODE_DAC_SERIAL: |
| 10047 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10048 | 5 : 10; |
| 10049 | break; |
| 10050 | case DPLLB_MODE_LVDS: |
| 10051 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10052 | 7 : 14; |
| 10053 | break; |
| 10054 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10055 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10056 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10057 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10058 | } |
| 10059 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10060 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10061 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10062 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10063 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10064 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 10065 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10066 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10067 | |
| 10068 | if (is_lvds) { |
| 10069 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10070 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10071 | |
| 10072 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10073 | clock.p2 = 7; |
| 10074 | else |
| 10075 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10076 | } else { |
| 10077 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10078 | clock.p1 = 2; |
| 10079 | else { |
| 10080 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10081 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10082 | } |
| 10083 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10084 | clock.p2 = 4; |
| 10085 | else |
| 10086 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10087 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10088 | |
| 10089 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10090 | } |
| 10091 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10092 | /* |
| 10093 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10094 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10095 | * encoder's get_config() function. |
| 10096 | */ |
| 10097 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10098 | } |
| 10099 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10100 | int intel_dotclock_calculate(int link_freq, |
| 10101 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10102 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10103 | /* |
| 10104 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10105 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10106 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10107 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10108 | * |
| 10109 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10110 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10111 | */ |
| 10112 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10113 | if (!m_n->link_n) |
| 10114 | return 0; |
| 10115 | |
| 10116 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 10117 | } |
| 10118 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10119 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10120 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10121 | { |
| 10122 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10123 | |
| 10124 | /* read out port_clock from the DPLL */ |
| 10125 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10126 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10127 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10128 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10129 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10130 | * agree once we know their relationship in the encoder's |
| 10131 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10132 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10133 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10134 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 10135 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10136 | } |
| 10137 | |
| 10138 | /** Returns the currently programmed mode of the given pipe. */ |
| 10139 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 10140 | struct drm_crtc *crtc) |
| 10141 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 10142 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10143 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10144 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10145 | struct drm_display_mode *mode; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10146 | struct intel_crtc_state pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10147 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 10148 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10149 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 10150 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10151 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10152 | |
| 10153 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10154 | if (!mode) |
| 10155 | return NULL; |
| 10156 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10157 | /* |
| 10158 | * Construct a pipe_config sufficient for getting the clock info |
| 10159 | * back out of crtc_clock_get. |
| 10160 | * |
| 10161 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 10162 | * to use a real value here instead. |
| 10163 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10164 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10165 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10166 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 10167 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 10168 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10169 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 10170 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 10171 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10172 | mode->hdisplay = (htot & 0xffff) + 1; |
| 10173 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 10174 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 10175 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 10176 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 10177 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 10178 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 10179 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 10180 | |
| 10181 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10182 | |
| 10183 | return mode; |
| 10184 | } |
| 10185 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10186 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 10187 | { |
| 10188 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10189 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10191 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 10192 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10193 | return; |
| 10194 | |
| 10195 | if (!dev_priv->lvds_downclock_avail) |
| 10196 | return; |
| 10197 | |
| 10198 | /* |
| 10199 | * Since this is called by a timer, we should never get here in |
| 10200 | * the manual case. |
| 10201 | */ |
| 10202 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 10203 | int pipe = intel_crtc->pipe; |
| 10204 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 10205 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 10206 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 10207 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10208 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 10209 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10210 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 10211 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10212 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 10213 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 10214 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10215 | dpll = I915_READ(dpll_reg); |
| 10216 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 10217 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10218 | } |
| 10219 | |
| 10220 | } |
| 10221 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10222 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10223 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10224 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10225 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10226 | if (dev_priv->mm.busy) |
| 10227 | return; |
| 10228 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10229 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10230 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 10231 | if (INTEL_INFO(dev)->gen >= 6) |
| 10232 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10233 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10234 | } |
| 10235 | |
| 10236 | void intel_mark_idle(struct drm_device *dev) |
| 10237 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10238 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 10239 | struct drm_crtc *crtc; |
| 10240 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10241 | if (!dev_priv->mm.busy) |
| 10242 | return; |
| 10243 | |
| 10244 | dev_priv->mm.busy = false; |
| 10245 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10246 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10247 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 10248 | continue; |
| 10249 | |
| 10250 | intel_decrease_pllclock(crtc); |
| 10251 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 10252 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 10253 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 10254 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 10255 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10256 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10257 | } |
| 10258 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10259 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10260 | { |
| 10261 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10262 | struct drm_device *dev = crtc->dev; |
| 10263 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10264 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10265 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10266 | work = intel_crtc->unpin_work; |
| 10267 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10268 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10269 | |
| 10270 | if (work) { |
| 10271 | cancel_work_sync(&work->work); |
| 10272 | kfree(work); |
| 10273 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10274 | |
| 10275 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10276 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10277 | kfree(intel_crtc); |
| 10278 | } |
| 10279 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10280 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 10281 | { |
| 10282 | struct intel_unpin_work *work = |
| 10283 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10284 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10285 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10286 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10287 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 10288 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10289 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 10290 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 10291 | intel_fbc_update(dev); |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10292 | |
| 10293 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10294 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10295 | mutex_unlock(&dev->struct_mutex); |
| 10296 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10297 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10298 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10299 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10300 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 10301 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 10302 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10303 | kfree(work); |
| 10304 | } |
| 10305 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10306 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10307 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10308 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10309 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10310 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10311 | unsigned long flags; |
| 10312 | |
| 10313 | /* Ignore early vblank irqs */ |
| 10314 | if (intel_crtc == NULL) |
| 10315 | return; |
| 10316 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10317 | /* |
| 10318 | * This is called both by irq handlers and the reset code (to complete |
| 10319 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10320 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10321 | spin_lock_irqsave(&dev->event_lock, flags); |
| 10322 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10323 | |
| 10324 | /* Ensure we don't miss a work->pending update ... */ |
| 10325 | smp_rmb(); |
| 10326 | |
| 10327 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10328 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10329 | return; |
| 10330 | } |
| 10331 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10332 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 10333 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10334 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10335 | } |
| 10336 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10337 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 10338 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10339 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10340 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10341 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10342 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10343 | } |
| 10344 | |
| 10345 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 10346 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10347 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10348 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 10349 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10350 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10351 | } |
| 10352 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10353 | /* Is 'a' after or equal to 'b'? */ |
| 10354 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 10355 | { |
| 10356 | return !((a - b) & 0x80000000); |
| 10357 | } |
| 10358 | |
| 10359 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 10360 | { |
| 10361 | struct drm_device *dev = crtc->base.dev; |
| 10362 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10363 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 10364 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 10365 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 10366 | return true; |
| 10367 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10368 | /* |
| 10369 | * The relevant registers doen't exist on pre-ctg. |
| 10370 | * As the flip done interrupt doesn't trigger for mmio |
| 10371 | * flips on gmch platforms, a flip count check isn't |
| 10372 | * really needed there. But since ctg has the registers, |
| 10373 | * include it in the check anyway. |
| 10374 | */ |
| 10375 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 10376 | return true; |
| 10377 | |
| 10378 | /* |
| 10379 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 10380 | * used the same base address. In that case the mmio flip might |
| 10381 | * have completed, but the CS hasn't even executed the flip yet. |
| 10382 | * |
| 10383 | * A flip count check isn't enough as the CS might have updated |
| 10384 | * the base address just after start of vblank, but before we |
| 10385 | * managed to process the interrupt. This means we'd complete the |
| 10386 | * CS flip too soon. |
| 10387 | * |
| 10388 | * Combining both checks should get us a good enough result. It may |
| 10389 | * still happen that the CS flip has been executed, but has not |
| 10390 | * yet actually completed. But in case the base address is the same |
| 10391 | * anyway, we don't really care. |
| 10392 | */ |
| 10393 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 10394 | crtc->unpin_work->gtt_offset && |
| 10395 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 10396 | crtc->unpin_work->flip_count); |
| 10397 | } |
| 10398 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10399 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 10400 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10401 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10402 | struct intel_crtc *intel_crtc = |
| 10403 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 10404 | unsigned long flags; |
| 10405 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10406 | |
| 10407 | /* |
| 10408 | * This is called both by irq handlers and the reset code (to complete |
| 10409 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10410 | * |
| 10411 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10412 | * generate a page-flip completion irq, i.e. every modeset |
| 10413 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 10414 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10415 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10416 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10417 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10418 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10419 | } |
| 10420 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10421 | 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] | 10422 | { |
| 10423 | /* Ensure that the work item is consistent when activating it ... */ |
| 10424 | smp_wmb(); |
| 10425 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 10426 | /* and that it is marked active as soon as the irq could fire. */ |
| 10427 | smp_wmb(); |
| 10428 | } |
| 10429 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10430 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 10431 | struct drm_crtc *crtc, |
| 10432 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10433 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10434 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10435 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10436 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10437 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10438 | u32 flip_mask; |
| 10439 | int ret; |
| 10440 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10441 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10442 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10443 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10444 | |
| 10445 | /* Can't queue multiple flips, so wait for the previous |
| 10446 | * one to finish before executing the next. |
| 10447 | */ |
| 10448 | if (intel_crtc->plane) |
| 10449 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10450 | else |
| 10451 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10452 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 10453 | intel_ring_emit(ring, MI_NOOP); |
| 10454 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10455 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10456 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10457 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10458 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10459 | |
| 10460 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10461 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10462 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10463 | } |
| 10464 | |
| 10465 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 10466 | struct drm_crtc *crtc, |
| 10467 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10468 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10469 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10470 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10471 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10472 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10473 | u32 flip_mask; |
| 10474 | int ret; |
| 10475 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10476 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10477 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10478 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10479 | |
| 10480 | if (intel_crtc->plane) |
| 10481 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10482 | else |
| 10483 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10484 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 10485 | intel_ring_emit(ring, MI_NOOP); |
| 10486 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 10487 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10488 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10489 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10490 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10491 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10492 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10493 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10494 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10495 | } |
| 10496 | |
| 10497 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 10498 | struct drm_crtc *crtc, |
| 10499 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10500 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10501 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10502 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10503 | { |
| 10504 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10505 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10506 | uint32_t pf, pipesrc; |
| 10507 | int ret; |
| 10508 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10509 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10510 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10511 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10512 | |
| 10513 | /* i965+ uses the linear or tiled offsets from the |
| 10514 | * Display Registers (which do not change across a page-flip) |
| 10515 | * so we need only reprogram the base address. |
| 10516 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10517 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10518 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10519 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10520 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 10521 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10522 | |
| 10523 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 10524 | * untested on non-native modes, so ignore it for now. |
| 10525 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 10526 | */ |
| 10527 | pf = 0; |
| 10528 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10529 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10530 | |
| 10531 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10532 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10533 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10534 | } |
| 10535 | |
| 10536 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 10537 | struct drm_crtc *crtc, |
| 10538 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10539 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10540 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10541 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10542 | { |
| 10543 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10544 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10545 | uint32_t pf, pipesrc; |
| 10546 | int ret; |
| 10547 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10548 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10549 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10550 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10551 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10552 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10553 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10554 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10555 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10556 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 10557 | /* Contrary to the suggestions in the documentation, |
| 10558 | * "Enable Panel Fitter" does not seem to be required when page |
| 10559 | * flipping with a non-native mode, and worse causes a normal |
| 10560 | * modeset to fail. |
| 10561 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 10562 | */ |
| 10563 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10564 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10565 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10566 | |
| 10567 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10568 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10569 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10570 | } |
| 10571 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10572 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 10573 | struct drm_crtc *crtc, |
| 10574 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10575 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10576 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10577 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10578 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10579 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10580 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10581 | int len, ret; |
| 10582 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10583 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10584 | case PLANE_A: |
| 10585 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 10586 | break; |
| 10587 | case PLANE_B: |
| 10588 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 10589 | break; |
| 10590 | case PLANE_C: |
| 10591 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 10592 | break; |
| 10593 | default: |
| 10594 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10595 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10596 | } |
| 10597 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10598 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10599 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10600 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10601 | /* |
| 10602 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 10603 | * 48bits addresses, and we need a NOOP for the batch size to |
| 10604 | * stay even. |
| 10605 | */ |
| 10606 | if (IS_GEN8(dev)) |
| 10607 | len += 2; |
| 10608 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10609 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 10610 | /* |
| 10611 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 10612 | * "The full packet must be contained within the same cache line." |
| 10613 | * |
| 10614 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 10615 | * cacheline, if we ever start emitting more commands before |
| 10616 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 10617 | * then do the cacheline alignment, and finally emit the |
| 10618 | * MI_DISPLAY_FLIP. |
| 10619 | */ |
| 10620 | ret = intel_ring_cacheline_align(ring); |
| 10621 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10622 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 10623 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10624 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10625 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10626 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10627 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10628 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 10629 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 10630 | * more than one flip event at any time (or ensure that one flip message |
| 10631 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 10632 | * Experimentation says that BCS works despite DERRMR masking all |
| 10633 | * flip-done completion events and that unmasking all planes at once |
| 10634 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 10635 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 10636 | */ |
| 10637 | if (ring->id == RCS) { |
| 10638 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 10639 | intel_ring_emit(ring, DERRMR); |
| 10640 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 10641 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 10642 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10643 | if (IS_GEN8(dev)) |
| 10644 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 10645 | MI_SRM_LRM_GLOBAL_GTT); |
| 10646 | else |
| 10647 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 10648 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10649 | intel_ring_emit(ring, DERRMR); |
| 10650 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10651 | if (IS_GEN8(dev)) { |
| 10652 | intel_ring_emit(ring, 0); |
| 10653 | intel_ring_emit(ring, MI_NOOP); |
| 10654 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10655 | } |
| 10656 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10657 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10658 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10659 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10660 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10661 | |
| 10662 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10663 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10664 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10665 | } |
| 10666 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10667 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 10668 | struct drm_i915_gem_object *obj) |
| 10669 | { |
| 10670 | /* |
| 10671 | * This is not being used for older platforms, because |
| 10672 | * non-availability of flip done interrupt forces us to use |
| 10673 | * CS flips. Older platforms derive flip done using some clever |
| 10674 | * tricks involving the flip_pending status bits and vblank irqs. |
| 10675 | * So using MMIO flips there would disrupt this mechanism. |
| 10676 | */ |
| 10677 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 10678 | if (ring == NULL) |
| 10679 | return true; |
| 10680 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10681 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 10682 | return false; |
| 10683 | |
| 10684 | if (i915.use_mmio_flip < 0) |
| 10685 | return false; |
| 10686 | else if (i915.use_mmio_flip > 0) |
| 10687 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 10688 | else if (i915.enable_execlists) |
| 10689 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10690 | else |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 10691 | return ring != i915_gem_request_get_ring(obj->last_read_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10692 | } |
| 10693 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10694 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 10695 | { |
| 10696 | struct drm_device *dev = intel_crtc->base.dev; |
| 10697 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10698 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10699 | const enum pipe pipe = intel_crtc->pipe; |
| 10700 | u32 ctl, stride; |
| 10701 | |
| 10702 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 10703 | ctl &= ~PLANE_CTL_TILED_MASK; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 10704 | switch (fb->modifier[0]) { |
| 10705 | case DRM_FORMAT_MOD_NONE: |
| 10706 | break; |
| 10707 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10708 | ctl |= PLANE_CTL_TILED_X; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 10709 | break; |
| 10710 | case I915_FORMAT_MOD_Y_TILED: |
| 10711 | ctl |= PLANE_CTL_TILED_Y; |
| 10712 | break; |
| 10713 | case I915_FORMAT_MOD_Yf_TILED: |
| 10714 | ctl |= PLANE_CTL_TILED_YF; |
| 10715 | break; |
| 10716 | default: |
| 10717 | MISSING_CASE(fb->modifier[0]); |
| 10718 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10719 | |
| 10720 | /* |
| 10721 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 10722 | * linear buffers or in number of tiles for tiled buffers. |
| 10723 | */ |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 10724 | stride = fb->pitches[0] / |
| 10725 | intel_fb_stride_alignment(dev, fb->modifier[0], |
| 10726 | fb->pixel_format); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10727 | |
| 10728 | /* |
| 10729 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 10730 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 10731 | */ |
| 10732 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 10733 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 10734 | |
| 10735 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); |
| 10736 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 10737 | } |
| 10738 | |
| 10739 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10740 | { |
| 10741 | struct drm_device *dev = intel_crtc->base.dev; |
| 10742 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10743 | struct intel_framebuffer *intel_fb = |
| 10744 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 10745 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 10746 | u32 dspcntr; |
| 10747 | u32 reg; |
| 10748 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10749 | reg = DSPCNTR(intel_crtc->plane); |
| 10750 | dspcntr = I915_READ(reg); |
| 10751 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 10752 | if (obj->tiling_mode != I915_TILING_NONE) |
| 10753 | dspcntr |= DISPPLANE_TILED; |
| 10754 | else |
| 10755 | dspcntr &= ~DISPPLANE_TILED; |
| 10756 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10757 | I915_WRITE(reg, dspcntr); |
| 10758 | |
| 10759 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 10760 | intel_crtc->unpin_work->gtt_offset); |
| 10761 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10762 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10763 | } |
| 10764 | |
| 10765 | /* |
| 10766 | * XXX: This is the temporary way to update the plane registers until we get |
| 10767 | * around to using the usual plane update functions for MMIO flips |
| 10768 | */ |
| 10769 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 10770 | { |
| 10771 | struct drm_device *dev = intel_crtc->base.dev; |
| 10772 | bool atomic_update; |
| 10773 | u32 start_vbl_count; |
| 10774 | |
| 10775 | intel_mark_page_flip_active(intel_crtc); |
| 10776 | |
| 10777 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 10778 | |
| 10779 | if (INTEL_INFO(dev)->gen >= 9) |
| 10780 | skl_do_mmio_flip(intel_crtc); |
| 10781 | else |
| 10782 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 10783 | ilk_do_mmio_flip(intel_crtc); |
| 10784 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10785 | if (atomic_update) |
| 10786 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10787 | } |
| 10788 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10789 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10790 | { |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10791 | struct intel_crtc *crtc = |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10792 | container_of(work, struct intel_crtc, mmio_flip.work); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10793 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10794 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10795 | mmio_flip = &crtc->mmio_flip; |
| 10796 | if (mmio_flip->req) |
John Harrison | 9c65481 | 2014-11-24 18:49:35 +0000 | [diff] [blame] | 10797 | WARN_ON(__i915_wait_request(mmio_flip->req, |
| 10798 | crtc->reset_counter, |
| 10799 | false, NULL, NULL) != 0); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10800 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10801 | intel_do_mmio_flip(crtc); |
| 10802 | if (mmio_flip->req) { |
| 10803 | mutex_lock(&crtc->base.dev->struct_mutex); |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10804 | i915_gem_request_assign(&mmio_flip->req, NULL); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10805 | mutex_unlock(&crtc->base.dev->struct_mutex); |
| 10806 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10807 | } |
| 10808 | |
| 10809 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 10810 | struct drm_crtc *crtc, |
| 10811 | struct drm_framebuffer *fb, |
| 10812 | struct drm_i915_gem_object *obj, |
| 10813 | struct intel_engine_cs *ring, |
| 10814 | uint32_t flags) |
| 10815 | { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10816 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10817 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10818 | i915_gem_request_assign(&intel_crtc->mmio_flip.req, |
| 10819 | obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10820 | |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 10821 | schedule_work(&intel_crtc->mmio_flip.work); |
| 10822 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10823 | return 0; |
| 10824 | } |
| 10825 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10826 | static int intel_default_queue_flip(struct drm_device *dev, |
| 10827 | struct drm_crtc *crtc, |
| 10828 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10829 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10830 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10831 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10832 | { |
| 10833 | return -ENODEV; |
| 10834 | } |
| 10835 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10836 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 10837 | struct drm_crtc *crtc) |
| 10838 | { |
| 10839 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10840 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10841 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 10842 | u32 addr; |
| 10843 | |
| 10844 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 10845 | return true; |
| 10846 | |
| 10847 | if (!work->enable_stall_check) |
| 10848 | return false; |
| 10849 | |
| 10850 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 10851 | if (work->flip_queued_req && |
| 10852 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10853 | return false; |
| 10854 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10855 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10856 | } |
| 10857 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10858 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10859 | return false; |
| 10860 | |
| 10861 | /* Potential stall - if we see that the flip has happened, |
| 10862 | * assume a missed interrupt. */ |
| 10863 | if (INTEL_INFO(dev)->gen >= 4) |
| 10864 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 10865 | else |
| 10866 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 10867 | |
| 10868 | /* There is a potential issue here with a false positive after a flip |
| 10869 | * to the same address. We could address this by checking for a |
| 10870 | * non-incrementing frame counter. |
| 10871 | */ |
| 10872 | return addr == work->gtt_offset; |
| 10873 | } |
| 10874 | |
| 10875 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 10876 | { |
| 10877 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10878 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10879 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10880 | struct intel_unpin_work *work; |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10881 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 10882 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10883 | |
| 10884 | if (crtc == NULL) |
| 10885 | return; |
| 10886 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10887 | spin_lock(&dev->event_lock); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10888 | work = intel_crtc->unpin_work; |
| 10889 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10890 | 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] | 10891 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10892 | page_flip_completed(intel_crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10893 | work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10894 | } |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10895 | if (work != NULL && |
| 10896 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) |
| 10897 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10898 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10899 | } |
| 10900 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10901 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 10902 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10903 | struct drm_pending_vblank_event *event, |
| 10904 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10905 | { |
| 10906 | struct drm_device *dev = crtc->dev; |
| 10907 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10908 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10909 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10910 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 10911 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10912 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10913 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10914 | struct intel_engine_cs *ring; |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 10915 | bool mmio_flip; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 10916 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10917 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10918 | /* |
| 10919 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 10920 | * check to be safe. In the future we may enable pageflipping from |
| 10921 | * a disabled primary plane. |
| 10922 | */ |
| 10923 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 10924 | return -EBUSY; |
| 10925 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10926 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10927 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10928 | return -EINVAL; |
| 10929 | |
| 10930 | /* |
| 10931 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 10932 | * Note that pitch changes could also affect these register. |
| 10933 | */ |
| 10934 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10935 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 10936 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10937 | return -EINVAL; |
| 10938 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10939 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 10940 | goto out_hang; |
| 10941 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 10942 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10943 | if (work == NULL) |
| 10944 | return -ENOMEM; |
| 10945 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10946 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10947 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10948 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10949 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 10950 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10951 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10952 | if (ret) |
| 10953 | goto free_work; |
| 10954 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10955 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10956 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10957 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10958 | /* Before declaring the flip queue wedged, check if |
| 10959 | * the hardware completed the operation behind our backs. |
| 10960 | */ |
| 10961 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 10962 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 10963 | page_flip_completed(intel_crtc); |
| 10964 | } else { |
| 10965 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10966 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 10967 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10968 | drm_crtc_vblank_put(crtc); |
| 10969 | kfree(work); |
| 10970 | return -EBUSY; |
| 10971 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10972 | } |
| 10973 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10974 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10975 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10976 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 10977 | flush_workqueue(dev_priv->wq); |
| 10978 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 10979 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10980 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10981 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10982 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10983 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10984 | update_state_fb(crtc->primary); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 10985 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10986 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10987 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10988 | ret = i915_mutex_lock_interruptible(dev); |
| 10989 | if (ret) |
| 10990 | goto cleanup; |
| 10991 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10992 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 10993 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10994 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10995 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10996 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10997 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10998 | if (IS_VALLEYVIEW(dev)) { |
| 10999 | ring = &dev_priv->ring[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11000 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11001 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 11002 | ring = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 11003 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 11004 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11005 | } else if (INTEL_INFO(dev)->gen >= 7) { |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 11006 | ring = i915_gem_request_get_ring(obj->last_read_req); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11007 | if (ring == NULL || ring->id != RCS) |
| 11008 | ring = &dev_priv->ring[BCS]; |
| 11009 | } else { |
| 11010 | ring = &dev_priv->ring[RCS]; |
| 11011 | } |
| 11012 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11013 | mmio_flip = use_mmio_flip(ring, obj); |
| 11014 | |
| 11015 | /* When using CS flips, we want to emit semaphores between rings. |
| 11016 | * However, when using mmio flips we will create a task to do the |
| 11017 | * synchronisation, so all we want here is to pin the framebuffer |
| 11018 | * into the display plane and skip any waits. |
| 11019 | */ |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 11020 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11021 | crtc->primary->state, |
| 11022 | mmio_flip ? i915_gem_request_get_ring(obj->last_read_req) : ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11023 | if (ret) |
| 11024 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11025 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 11026 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
| 11027 | + intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11028 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11029 | if (mmio_flip) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11030 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 11031 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11032 | if (ret) |
| 11033 | goto cleanup_unpin; |
| 11034 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 11035 | i915_gem_request_assign(&work->flip_queued_req, |
| 11036 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11037 | } else { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11038 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11039 | page_flip_flags); |
| 11040 | if (ret) |
| 11041 | goto cleanup_unpin; |
| 11042 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 11043 | i915_gem_request_assign(&work->flip_queued_req, |
| 11044 | intel_ring_get_request(ring)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11045 | } |
| 11046 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11047 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11048 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11049 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11050 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11051 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 11052 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 11053 | intel_fbc_disable(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 11054 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11055 | mutex_unlock(&dev->struct_mutex); |
| 11056 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 11057 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 11058 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11059 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11060 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11061 | cleanup_unpin: |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 11062 | intel_unpin_fb_obj(fb, crtc->primary->state); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11063 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11064 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11065 | mutex_unlock(&dev->struct_mutex); |
| 11066 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11067 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11068 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11069 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11070 | drm_gem_object_unreference_unlocked(&obj->base); |
| 11071 | drm_framebuffer_unreference(work->old_fb); |
| 11072 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11073 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11074 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11075 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11076 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11077 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11078 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11079 | kfree(work); |
| 11080 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11081 | if (ret == -EIO) { |
| 11082 | out_hang: |
Matt Roper | 53a366b | 2014-12-23 10:41:53 -0800 | [diff] [blame] | 11083 | ret = intel_plane_restore(primary); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11084 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11085 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11086 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11087 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11088 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11089 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11090 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11091 | } |
| 11092 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11093 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11094 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 11095 | .load_lut = intel_crtc_load_lut, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 11096 | .atomic_begin = intel_begin_crtc_commit, |
| 11097 | .atomic_flush = intel_finish_crtc_commit, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11098 | }; |
| 11099 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11100 | /** |
| 11101 | * intel_modeset_update_staged_output_state |
| 11102 | * |
| 11103 | * Updates the staged output configuration state, e.g. after we've read out the |
| 11104 | * current hw state. |
| 11105 | */ |
| 11106 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 11107 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11108 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11109 | struct intel_encoder *encoder; |
| 11110 | struct intel_connector *connector; |
| 11111 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11112 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11113 | connector->new_encoder = |
| 11114 | to_intel_encoder(connector->base.encoder); |
| 11115 | } |
| 11116 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11117 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11118 | encoder->new_crtc = |
| 11119 | to_intel_crtc(encoder->base.crtc); |
| 11120 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11121 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11122 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11123 | crtc->new_enabled = crtc->base.state->enable; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11124 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11125 | } |
| 11126 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11127 | /* Transitional helper to copy current connector/encoder state to |
| 11128 | * connector->state. This is needed so that code that is partially |
| 11129 | * converted to atomic does the right thing. |
| 11130 | */ |
| 11131 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11132 | { |
| 11133 | struct intel_connector *connector; |
| 11134 | |
| 11135 | for_each_intel_connector(dev, connector) { |
| 11136 | if (connector->base.encoder) { |
| 11137 | connector->base.state->best_encoder = |
| 11138 | connector->base.encoder; |
| 11139 | connector->base.state->crtc = |
| 11140 | connector->base.encoder->crtc; |
| 11141 | } else { |
| 11142 | connector->base.state->best_encoder = NULL; |
| 11143 | connector->base.state->crtc = NULL; |
| 11144 | } |
| 11145 | } |
| 11146 | } |
| 11147 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11148 | /* Fixup legacy state after an atomic state swap. |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11149 | */ |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11150 | static void intel_modeset_fixup_state(struct drm_atomic_state *state) |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11151 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11152 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11153 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11154 | struct intel_connector *connector; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11155 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11156 | for_each_intel_connector(state->dev, connector) { |
| 11157 | connector->base.encoder = connector->base.state->best_encoder; |
| 11158 | if (connector->base.encoder) |
| 11159 | connector->base.encoder->crtc = |
| 11160 | connector->base.state->crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11161 | } |
| 11162 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 11163 | /* Update crtc of disabled encoders */ |
| 11164 | for_each_intel_encoder(state->dev, encoder) { |
| 11165 | int num_connectors = 0; |
| 11166 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11167 | for_each_intel_connector(state->dev, connector) |
| 11168 | if (connector->base.encoder == &encoder->base) |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 11169 | num_connectors++; |
| 11170 | |
| 11171 | if (num_connectors == 0) |
| 11172 | encoder->base.crtc = NULL; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11173 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11174 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11175 | for_each_intel_crtc(state->dev, crtc) { |
| 11176 | crtc->base.enabled = crtc->base.state->enable; |
| 11177 | crtc->config = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11178 | } |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11179 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 11180 | /* Copy the new configuration to the staged state, to keep the few |
| 11181 | * pieces of code that haven't been converted yet happy */ |
| 11182 | intel_modeset_update_staged_output_state(state->dev); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11183 | } |
| 11184 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11185 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 11186 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11187 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11188 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11189 | int bpp = pipe_config->pipe_bpp; |
| 11190 | |
| 11191 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 11192 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11193 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11194 | |
| 11195 | /* Don't use an invalid EDID bpc value */ |
| 11196 | if (connector->base.display_info.bpc && |
| 11197 | connector->base.display_info.bpc * 3 < bpp) { |
| 11198 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 11199 | bpp, connector->base.display_info.bpc*3); |
| 11200 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 11201 | } |
| 11202 | |
| 11203 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 11204 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 11205 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 11206 | bpp); |
| 11207 | pipe_config->pipe_bpp = 24; |
| 11208 | } |
| 11209 | } |
| 11210 | |
| 11211 | static int |
| 11212 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11213 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11214 | { |
| 11215 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11216 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11217 | struct drm_connector *connector; |
| 11218 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11219 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11220 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11221 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11222 | bpp = 10*3; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11223 | else if (INTEL_INFO(dev)->gen >= 5) |
| 11224 | bpp = 12*3; |
| 11225 | else |
| 11226 | bpp = 8*3; |
| 11227 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11228 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11229 | pipe_config->pipe_bpp = bpp; |
| 11230 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11231 | state = pipe_config->base.state; |
| 11232 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11233 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11234 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11235 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11236 | continue; |
| 11237 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11238 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 11239 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11240 | } |
| 11241 | |
| 11242 | return bpp; |
| 11243 | } |
| 11244 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11245 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11246 | { |
| 11247 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11248 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11249 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11250 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11251 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11252 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11253 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11254 | } |
| 11255 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11256 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11257 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11258 | const char *context) |
| 11259 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11260 | struct drm_device *dev = crtc->base.dev; |
| 11261 | struct drm_plane *plane; |
| 11262 | struct intel_plane *intel_plane; |
| 11263 | struct intel_plane_state *state; |
| 11264 | struct drm_framebuffer *fb; |
| 11265 | |
| 11266 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 11267 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11268 | |
| 11269 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 11270 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 11271 | pipe_config->pipe_bpp, pipe_config->dither); |
| 11272 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11273 | pipe_config->has_pch_encoder, |
| 11274 | pipe_config->fdi_lanes, |
| 11275 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 11276 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 11277 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11278 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11279 | pipe_config->has_dp_encoder, |
| 11280 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 11281 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 11282 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11283 | |
| 11284 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 11285 | pipe_config->has_dp_encoder, |
| 11286 | pipe_config->dp_m2_n2.gmch_m, |
| 11287 | pipe_config->dp_m2_n2.gmch_n, |
| 11288 | pipe_config->dp_m2_n2.link_m, |
| 11289 | pipe_config->dp_m2_n2.link_n, |
| 11290 | pipe_config->dp_m2_n2.tu); |
| 11291 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11292 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 11293 | pipe_config->has_audio, |
| 11294 | pipe_config->has_infoframe); |
| 11295 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11296 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11297 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11298 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11299 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11300 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 11301 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 11302 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 11303 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11304 | DRM_DEBUG_KMS("num_scalers: %d\n", crtc->num_scalers); |
| 11305 | DRM_DEBUG_KMS("scaler_users: 0x%x\n", pipe_config->scaler_state.scaler_users); |
| 11306 | 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] | 11307 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11308 | pipe_config->gmch_pfit.control, |
| 11309 | pipe_config->gmch_pfit.pgm_ratios, |
| 11310 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11311 | 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] | 11312 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11313 | pipe_config->pch_pfit.size, |
| 11314 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 11315 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 11316 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11317 | |
| 11318 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11319 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 11320 | intel_plane = to_intel_plane(plane); |
| 11321 | if (intel_plane->pipe != crtc->pipe) |
| 11322 | continue; |
| 11323 | |
| 11324 | state = to_intel_plane_state(plane->state); |
| 11325 | fb = state->base.fb; |
| 11326 | if (!fb) { |
| 11327 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 11328 | "disabled, scaler_id = %d\n", |
| 11329 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 11330 | plane->base.id, intel_plane->pipe, |
| 11331 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 11332 | drm_plane_index(plane), state->scaler_id); |
| 11333 | continue; |
| 11334 | } |
| 11335 | |
| 11336 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 11337 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 11338 | plane->base.id, intel_plane->pipe, |
| 11339 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 11340 | drm_plane_index(plane)); |
| 11341 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 11342 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 11343 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 11344 | state->scaler_id, |
| 11345 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 11346 | drm_rect_width(&state->src) >> 16, |
| 11347 | drm_rect_height(&state->src) >> 16, |
| 11348 | state->dst.x1, state->dst.y1, |
| 11349 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 11350 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11351 | } |
| 11352 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11353 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11354 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11355 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11356 | /* masks could be asymmetric, so check both ways */ |
| 11357 | return a == b || (a->cloneable & (1 << b->type) && |
| 11358 | b->cloneable & (1 << a->type)); |
| 11359 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11360 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11361 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11362 | struct intel_crtc *crtc, |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11363 | struct intel_encoder *encoder) |
| 11364 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11365 | struct intel_encoder *source_encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11366 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11367 | struct drm_connector_state *connector_state; |
| 11368 | int i; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11369 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11370 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11371 | if (connector_state->crtc != &crtc->base) |
| 11372 | continue; |
| 11373 | |
| 11374 | source_encoder = |
| 11375 | to_intel_encoder(connector_state->best_encoder); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11376 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11377 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11378 | } |
| 11379 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11380 | return true; |
| 11381 | } |
| 11382 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11383 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 11384 | struct intel_crtc *crtc) |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11385 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11386 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11387 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11388 | struct drm_connector_state *connector_state; |
| 11389 | int i; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11390 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11391 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11392 | if (connector_state->crtc != &crtc->base) |
| 11393 | continue; |
| 11394 | |
| 11395 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11396 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 11397 | return false; |
| 11398 | } |
| 11399 | |
| 11400 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11401 | } |
| 11402 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11403 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11404 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11405 | struct drm_device *dev = state->dev; |
| 11406 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11407 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11408 | struct drm_connector_state *connector_state; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11409 | unsigned int used_ports = 0; |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11410 | int i; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11411 | |
| 11412 | /* |
| 11413 | * Walk the connector list instead of the encoder |
| 11414 | * list to detect the problem on ddi platforms |
| 11415 | * where there's just one encoder per digital port. |
| 11416 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11417 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11418 | if (!connector_state->best_encoder) |
| 11419 | continue; |
| 11420 | |
| 11421 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11422 | |
| 11423 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11424 | |
| 11425 | switch (encoder->type) { |
| 11426 | unsigned int port_mask; |
| 11427 | case INTEL_OUTPUT_UNKNOWN: |
| 11428 | if (WARN_ON(!HAS_DDI(dev))) |
| 11429 | break; |
| 11430 | case INTEL_OUTPUT_DISPLAYPORT: |
| 11431 | case INTEL_OUTPUT_HDMI: |
| 11432 | case INTEL_OUTPUT_EDP: |
| 11433 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 11434 | |
| 11435 | /* the same port mustn't appear more than once */ |
| 11436 | if (used_ports & port_mask) |
| 11437 | return false; |
| 11438 | |
| 11439 | used_ports |= port_mask; |
| 11440 | default: |
| 11441 | break; |
| 11442 | } |
| 11443 | } |
| 11444 | |
| 11445 | return true; |
| 11446 | } |
| 11447 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11448 | static void |
| 11449 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11450 | { |
| 11451 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11452 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11453 | struct intel_dpll_hw_state dpll_hw_state; |
| 11454 | enum intel_dpll_id shared_dpll; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11455 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11456 | /* 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] | 11457 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11458 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11459 | shared_dpll = crtc_state->shared_dpll; |
| 11460 | dpll_hw_state = crtc_state->dpll_hw_state; |
| 11461 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11462 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11463 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11464 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11465 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11466 | crtc_state->shared_dpll = shared_dpll; |
| 11467 | crtc_state->dpll_hw_state = dpll_hw_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11468 | } |
| 11469 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11470 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11471 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11472 | struct drm_atomic_state *state, |
| 11473 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11474 | { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11475 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11476 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11477 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11478 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11479 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11480 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11481 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 11482 | if (!check_encoder_cloning(state, to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11483 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11484 | return -EINVAL; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 11485 | } |
| 11486 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11487 | if (!check_digital_port_conflicts(state)) { |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11488 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11489 | return -EINVAL; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11490 | } |
| 11491 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11492 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11493 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11494 | pipe_config->cpu_transcoder = |
| 11495 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11496 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11497 | /* |
| 11498 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11499 | * positive or negative polarity is requested, treat this as meaning |
| 11500 | * negative polarity. |
| 11501 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11502 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11503 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11504 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11505 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11506 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11507 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11508 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11509 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11510 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 11511 | * plane pixel format and any sink constraints into account. Returns the |
| 11512 | * source plane bpp so that dithering can be selected on mismatches |
| 11513 | * after encoders and crtc also have had their say. */ |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11514 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11515 | pipe_config); |
| 11516 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11517 | goto fail; |
| 11518 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11519 | /* |
| 11520 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11521 | * increase the actual pipe size due to the frame doubling and |
| 11522 | * insertion of additional space for blanks between the frame. This |
| 11523 | * is stored in the crtc timings. We use the requested mode to do this |
| 11524 | * computation to clearly distinguish it from the adjusted mode, which |
| 11525 | * can be changed by the connectors in the below retry loop. |
| 11526 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11527 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11528 | &pipe_config->pipe_src_w, |
| 11529 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11530 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11531 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11532 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11533 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11534 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11535 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11536 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11537 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11538 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11539 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11540 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11541 | * adjust it according to limitations or connector properties, and also |
| 11542 | * a chance to reject the mode entirely. |
| 11543 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11544 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11545 | if (connector_state->crtc != crtc) |
| 11546 | continue; |
| 11547 | |
| 11548 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11549 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 11550 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 11551 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11552 | goto fail; |
| 11553 | } |
| 11554 | } |
| 11555 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11556 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11557 | * done afterwards in case the encoder adjusts the mode. */ |
| 11558 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11559 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11560 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11561 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11562 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11563 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11564 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 11565 | goto fail; |
| 11566 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11567 | |
| 11568 | if (ret == RETRY) { |
| 11569 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 11570 | ret = -EINVAL; |
| 11571 | goto fail; |
| 11572 | } |
| 11573 | |
| 11574 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11575 | retry = false; |
| 11576 | goto encoder_retry; |
| 11577 | } |
| 11578 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11579 | pipe_config->dither = pipe_config->pipe_bpp != base_bpp; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11580 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11581 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11582 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11583 | return 0; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11584 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11585 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11586 | } |
| 11587 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11588 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 11589 | { |
| 11590 | struct drm_encoder *encoder; |
| 11591 | struct drm_device *dev = crtc->dev; |
| 11592 | |
| 11593 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 11594 | if (encoder->crtc == crtc) |
| 11595 | return true; |
| 11596 | |
| 11597 | return false; |
| 11598 | } |
| 11599 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11600 | static bool |
| 11601 | needs_modeset(struct drm_crtc_state *state) |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11602 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11603 | return state->mode_changed || state->active_changed; |
| 11604 | } |
| 11605 | |
| 11606 | static void |
| 11607 | intel_modeset_update_state(struct drm_atomic_state *state) |
| 11608 | { |
| 11609 | struct drm_device *dev = state->dev; |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 11610 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11611 | struct intel_encoder *intel_encoder; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11612 | struct drm_crtc *crtc; |
| 11613 | struct drm_crtc_state *crtc_state; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11614 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11615 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11616 | |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 11617 | intel_shared_dpll_commit(dev_priv); |
| 11618 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11619 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11620 | if (!intel_encoder->base.crtc) |
| 11621 | continue; |
| 11622 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11623 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
| 11624 | if (crtc == intel_encoder->base.crtc) |
| 11625 | break; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11626 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11627 | if (crtc != intel_encoder->base.crtc) |
| 11628 | continue; |
| 11629 | |
| 11630 | if (crtc_state->enable && needs_modeset(crtc_state)) |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11631 | intel_encoder->connectors_active = false; |
| 11632 | } |
| 11633 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11634 | drm_atomic_helper_swap_state(state->dev, state); |
| 11635 | intel_modeset_fixup_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11636 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11637 | /* Double check state. */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11638 | for_each_crtc(dev, crtc) { |
| 11639 | WARN_ON(crtc->state->enable != intel_crtc_in_use(crtc)); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11640 | } |
| 11641 | |
| 11642 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 11643 | if (!connector->encoder || !connector->encoder->crtc) |
| 11644 | continue; |
| 11645 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11646 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
| 11647 | if (crtc == connector->encoder->crtc) |
| 11648 | break; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11649 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11650 | if (crtc != connector->encoder->crtc) |
| 11651 | continue; |
| 11652 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 11653 | if (crtc->state->enable && needs_modeset(crtc->state)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 11654 | struct drm_property *dpms_property = |
| 11655 | dev->mode_config.dpms_property; |
| 11656 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11657 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 11658 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 11659 | dpms_property, |
| 11660 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11661 | |
| 11662 | intel_encoder = to_intel_encoder(connector->encoder); |
| 11663 | intel_encoder->connectors_active = true; |
| 11664 | } |
| 11665 | } |
| 11666 | |
| 11667 | } |
| 11668 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11669 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11670 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11671 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11672 | |
| 11673 | if (clock1 == clock2) |
| 11674 | return true; |
| 11675 | |
| 11676 | if (!clock1 || !clock2) |
| 11677 | return false; |
| 11678 | |
| 11679 | diff = abs(clock1 - clock2); |
| 11680 | |
| 11681 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11682 | return true; |
| 11683 | |
| 11684 | return false; |
| 11685 | } |
| 11686 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11687 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 11688 | list_for_each_entry((intel_crtc), \ |
| 11689 | &(dev)->mode_config.crtc_list, \ |
| 11690 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 11691 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11692 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11693 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11694 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11695 | struct intel_crtc_state *current_config, |
| 11696 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11697 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11698 | #define PIPE_CONF_CHECK_X(name) \ |
| 11699 | if (current_config->name != pipe_config->name) { \ |
| 11700 | DRM_ERROR("mismatch in " #name " " \ |
| 11701 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11702 | current_config->name, \ |
| 11703 | pipe_config->name); \ |
| 11704 | return false; \ |
| 11705 | } |
| 11706 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11707 | #define PIPE_CONF_CHECK_I(name) \ |
| 11708 | if (current_config->name != pipe_config->name) { \ |
| 11709 | DRM_ERROR("mismatch in " #name " " \ |
| 11710 | "(expected %i, found %i)\n", \ |
| 11711 | current_config->name, \ |
| 11712 | pipe_config->name); \ |
| 11713 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11714 | } |
| 11715 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11716 | /* This is required for BDW+ where there is only one set of registers for |
| 11717 | * switching between high and low RR. |
| 11718 | * This macro can be used whenever a comparison has to be made between one |
| 11719 | * hw state and multiple sw state variables. |
| 11720 | */ |
| 11721 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 11722 | if ((current_config->name != pipe_config->name) && \ |
| 11723 | (current_config->alt_name != pipe_config->name)) { \ |
| 11724 | DRM_ERROR("mismatch in " #name " " \ |
| 11725 | "(expected %i or %i, found %i)\n", \ |
| 11726 | current_config->name, \ |
| 11727 | current_config->alt_name, \ |
| 11728 | pipe_config->name); \ |
| 11729 | return false; \ |
| 11730 | } |
| 11731 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11732 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 11733 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 11734 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11735 | "(expected %i, found %i)\n", \ |
| 11736 | current_config->name & (mask), \ |
| 11737 | pipe_config->name & (mask)); \ |
| 11738 | return false; \ |
| 11739 | } |
| 11740 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11741 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 11742 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 11743 | DRM_ERROR("mismatch in " #name " " \ |
| 11744 | "(expected %i, found %i)\n", \ |
| 11745 | current_config->name, \ |
| 11746 | pipe_config->name); \ |
| 11747 | return false; \ |
| 11748 | } |
| 11749 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11750 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11751 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11752 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11753 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11754 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11755 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 11756 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 11757 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 11758 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 11759 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 11760 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 11761 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11762 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11763 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11764 | |
| 11765 | if (INTEL_INFO(dev)->gen < 8) { |
| 11766 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 11767 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 11768 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 11769 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 11770 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 11771 | |
| 11772 | if (current_config->has_drrs) { |
| 11773 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 11774 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 11775 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 11776 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 11777 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 11778 | } |
| 11779 | } else { |
| 11780 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 11781 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 11782 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 11783 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 11784 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 11785 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11786 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11787 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11788 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11789 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11790 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11791 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11792 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11793 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11794 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11795 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11796 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11797 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11798 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11799 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11800 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11801 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 11802 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 11803 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 11804 | IS_VALLEYVIEW(dev)) |
| 11805 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 11806 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11807 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11808 | PIPE_CONF_CHECK_I(has_audio); |
| 11809 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11810 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11811 | DRM_MODE_FLAG_INTERLACE); |
| 11812 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11813 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11814 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11815 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11816 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11817 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11818 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11819 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11820 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11821 | DRM_MODE_FLAG_NVSYNC); |
| 11822 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11823 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 11824 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11825 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11826 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11827 | /* |
| 11828 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 11829 | * screen. Since we don't yet re-compute the pipe config when moving |
| 11830 | * just the lvds port away to another pipe the sw tracking won't match. |
| 11831 | * |
| 11832 | * Proper atomic modesets with recomputed global state will fix this. |
| 11833 | * Until then just don't check gmch state for inherited modes. |
| 11834 | */ |
| 11835 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 11836 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 11837 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 11838 | if (INTEL_INFO(dev)->gen < 4) |
| 11839 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 11840 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 11841 | } |
| 11842 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11843 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 11844 | if (current_config->pch_pfit.enabled) { |
| 11845 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 11846 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 11847 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11848 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11849 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 11850 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 11851 | /* BDW+ don't expose a synchronous way to read the state */ |
| 11852 | if (IS_HASWELL(dev)) |
| 11853 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 11854 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11855 | PIPE_CONF_CHECK_I(double_wide); |
| 11856 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 11857 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 11858 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11859 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11860 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11861 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11862 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11863 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11864 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11865 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11866 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11867 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11868 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11869 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 11870 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11871 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11872 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11873 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11874 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11875 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11876 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11877 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11878 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11879 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11880 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11881 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11882 | return true; |
| 11883 | } |
| 11884 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11885 | static void check_wm_state(struct drm_device *dev) |
| 11886 | { |
| 11887 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11888 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 11889 | struct intel_crtc *intel_crtc; |
| 11890 | int plane; |
| 11891 | |
| 11892 | if (INTEL_INFO(dev)->gen < 9) |
| 11893 | return; |
| 11894 | |
| 11895 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11896 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11897 | |
| 11898 | for_each_intel_crtc(dev, intel_crtc) { |
| 11899 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 11900 | const enum pipe pipe = intel_crtc->pipe; |
| 11901 | |
| 11902 | if (!intel_crtc->active) |
| 11903 | continue; |
| 11904 | |
| 11905 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 11906 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11907 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 11908 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 11909 | |
| 11910 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11911 | continue; |
| 11912 | |
| 11913 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 11914 | "(expected (%u,%u), found (%u,%u))\n", |
| 11915 | pipe_name(pipe), plane + 1, |
| 11916 | sw_entry->start, sw_entry->end, |
| 11917 | hw_entry->start, hw_entry->end); |
| 11918 | } |
| 11919 | |
| 11920 | /* cursor */ |
| 11921 | hw_entry = &hw_ddb.cursor[pipe]; |
| 11922 | sw_entry = &sw_ddb->cursor[pipe]; |
| 11923 | |
| 11924 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11925 | continue; |
| 11926 | |
| 11927 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 11928 | "(expected (%u,%u), found (%u,%u))\n", |
| 11929 | pipe_name(pipe), |
| 11930 | sw_entry->start, sw_entry->end, |
| 11931 | hw_entry->start, hw_entry->end); |
| 11932 | } |
| 11933 | } |
| 11934 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11935 | static void |
| 11936 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11937 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11938 | struct intel_connector *connector; |
| 11939 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11940 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11941 | /* This also checks the encoder/connector hw state with the |
| 11942 | * ->get_hw_state callbacks. */ |
| 11943 | intel_connector_check_state(connector); |
| 11944 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11945 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11946 | "connector's staged encoder doesn't match current encoder\n"); |
| 11947 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11948 | } |
| 11949 | |
| 11950 | static void |
| 11951 | check_encoder_state(struct drm_device *dev) |
| 11952 | { |
| 11953 | struct intel_encoder *encoder; |
| 11954 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11955 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11956 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11957 | bool enabled = false; |
| 11958 | bool active = false; |
| 11959 | enum pipe pipe, tracked_pipe; |
| 11960 | |
| 11961 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11962 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11963 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11964 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11965 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11966 | "encoder's stage crtc doesn't match current crtc\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11967 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11968 | "encoder's active_connectors set, but no crtc\n"); |
| 11969 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11970 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11971 | if (connector->base.encoder != &encoder->base) |
| 11972 | continue; |
| 11973 | enabled = true; |
| 11974 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 11975 | active = true; |
| 11976 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11977 | /* |
| 11978 | * for MST connectors if we unplug the connector is gone |
| 11979 | * away but the encoder is still connected to a crtc |
| 11980 | * until a modeset happens in response to the hotplug. |
| 11981 | */ |
| 11982 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 11983 | continue; |
| 11984 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11985 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11986 | "encoder's enabled state mismatch " |
| 11987 | "(expected %i, found %i)\n", |
| 11988 | !!encoder->base.crtc, enabled); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11989 | I915_STATE_WARN(active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11990 | "active encoder with no crtc\n"); |
| 11991 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11992 | I915_STATE_WARN(encoder->connectors_active != active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11993 | "encoder's computed active state doesn't match tracked active state " |
| 11994 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 11995 | |
| 11996 | active = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11997 | I915_STATE_WARN(active != encoder->connectors_active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11998 | "encoder's hw state doesn't match sw tracking " |
| 11999 | "(expected %i, found %i)\n", |
| 12000 | encoder->connectors_active, active); |
| 12001 | |
| 12002 | if (!encoder->base.crtc) |
| 12003 | continue; |
| 12004 | |
| 12005 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12006 | I915_STATE_WARN(active && pipe != tracked_pipe, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12007 | "active encoder's pipe doesn't match" |
| 12008 | "(expected %i, found %i)\n", |
| 12009 | tracked_pipe, pipe); |
| 12010 | |
| 12011 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12012 | } |
| 12013 | |
| 12014 | static void |
| 12015 | check_crtc_state(struct drm_device *dev) |
| 12016 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12017 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12018 | struct intel_crtc *crtc; |
| 12019 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12020 | struct intel_crtc_state pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12021 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12022 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12023 | bool enabled = false; |
| 12024 | bool active = false; |
| 12025 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12026 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 12027 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12028 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 12029 | crtc->base.base.id); |
| 12030 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12031 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12032 | "active crtc, but not enabled in sw tracking\n"); |
| 12033 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12034 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12035 | if (encoder->base.crtc != &crtc->base) |
| 12036 | continue; |
| 12037 | enabled = true; |
| 12038 | if (encoder->connectors_active) |
| 12039 | active = true; |
| 12040 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12041 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12042 | I915_STATE_WARN(active != crtc->active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12043 | "crtc's computed active state doesn't match tracked active state " |
| 12044 | "(expected %i, found %i)\n", active, crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12045 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12046 | "crtc's computed enabled state doesn't match tracked enabled state " |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12047 | "(expected %i, found %i)\n", enabled, |
| 12048 | crtc->base.state->enable); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12049 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12050 | active = dev_priv->display.get_pipe_config(crtc, |
| 12051 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 12052 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 12053 | /* hw state is inconsistent with the pipe quirk */ |
| 12054 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 12055 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 12056 | active = crtc->active; |
| 12057 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12058 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 12059 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12060 | if (encoder->base.crtc != &crtc->base) |
| 12061 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 12062 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12063 | encoder->get_config(encoder, &pipe_config); |
| 12064 | } |
| 12065 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12066 | I915_STATE_WARN(crtc->active != active, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12067 | "crtc active state doesn't match with hw state " |
| 12068 | "(expected %i, found %i)\n", crtc->active, active); |
| 12069 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12070 | if (active && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12071 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12072 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12073 | intel_dump_pipe_config(crtc, &pipe_config, |
| 12074 | "[hw state]"); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12075 | intel_dump_pipe_config(crtc, crtc->config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12076 | "[sw state]"); |
| 12077 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12078 | } |
| 12079 | } |
| 12080 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12081 | static void |
| 12082 | check_shared_dpll_state(struct drm_device *dev) |
| 12083 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12084 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12085 | struct intel_crtc *crtc; |
| 12086 | struct intel_dpll_hw_state dpll_hw_state; |
| 12087 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12088 | |
| 12089 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 12090 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 12091 | int enabled_crtcs = 0, active_crtcs = 0; |
| 12092 | bool active; |
| 12093 | |
| 12094 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12095 | |
| 12096 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 12097 | |
| 12098 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 12099 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12100 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12101 | "more active pll users than references: %i vs %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12102 | pll->active, hweight32(pll->config.crtc_mask)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12103 | I915_STATE_WARN(pll->active && !pll->on, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12104 | "pll in active use but not on in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12105 | I915_STATE_WARN(pll->on && !pll->active, |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 12106 | "pll in on but not on in use in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12107 | I915_STATE_WARN(pll->on != active, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12108 | "pll on state mismatch (expected %i, found %i)\n", |
| 12109 | pll->on, active); |
| 12110 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12111 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12112 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12113 | enabled_crtcs++; |
| 12114 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 12115 | active_crtcs++; |
| 12116 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12117 | I915_STATE_WARN(pll->active != active_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12118 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 12119 | pll->active, active_crtcs); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12120 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12121 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12122 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12123 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12124 | 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] | 12125 | sizeof(dpll_hw_state)), |
| 12126 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12127 | } |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 12128 | } |
| 12129 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12130 | void |
| 12131 | intel_modeset_check_state(struct drm_device *dev) |
| 12132 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12133 | check_wm_state(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12134 | check_connector_state(dev); |
| 12135 | check_encoder_state(dev); |
| 12136 | check_crtc_state(dev); |
| 12137 | check_shared_dpll_state(dev); |
| 12138 | } |
| 12139 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12140 | 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] | 12141 | int dotclock) |
| 12142 | { |
| 12143 | /* |
| 12144 | * FDI already provided one idea for the dotclock. |
| 12145 | * Yell if the encoder disagrees. |
| 12146 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12147 | 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] | 12148 | "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] | 12149 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 12150 | } |
| 12151 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12152 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 12153 | { |
| 12154 | struct drm_device *dev = crtc->base.dev; |
| 12155 | |
| 12156 | /* |
| 12157 | * The scanline counter increments at the leading edge of hsync. |
| 12158 | * |
| 12159 | * On most platforms it starts counting from vtotal-1 on the |
| 12160 | * first active line. That means the scanline counter value is |
| 12161 | * always one less than what we would expect. Ie. just after |
| 12162 | * start of vblank, which also occurs at start of hsync (on the |
| 12163 | * last active line), the scanline counter will read vblank_start-1. |
| 12164 | * |
| 12165 | * On gen2 the scanline counter starts counting from 1 instead |
| 12166 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12167 | * to keep the value positive), instead of adding one. |
| 12168 | * |
| 12169 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12170 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12171 | * there's an extra 1 line difference. So we need to add two instead of |
| 12172 | * one to the value. |
| 12173 | */ |
| 12174 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12175 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12176 | int vtotal; |
| 12177 | |
| 12178 | vtotal = mode->crtc_vtotal; |
| 12179 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 12180 | vtotal /= 2; |
| 12181 | |
| 12182 | crtc->scanline_offset = vtotal - 1; |
| 12183 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 12184 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12185 | crtc->scanline_offset = 2; |
| 12186 | } else |
| 12187 | crtc->scanline_offset = 1; |
| 12188 | } |
| 12189 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12190 | static struct intel_crtc_state * |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12191 | intel_modeset_compute_config(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12192 | struct drm_atomic_state *state) |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12193 | { |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12194 | struct intel_crtc_state *pipe_config; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12195 | int ret = 0; |
| 12196 | |
| 12197 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12198 | if (ret) |
| 12199 | return ERR_PTR(ret); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12200 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12201 | ret = drm_atomic_helper_check_modeset(state->dev, state); |
| 12202 | if (ret) |
| 12203 | return ERR_PTR(ret); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12204 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12205 | /* |
| 12206 | * Note this needs changes when we start tracking multiple modes |
| 12207 | * and crtcs. At that point we'll need to compute the whole config |
| 12208 | * (i.e. one pipe_config for each crtc) rather than just the one |
| 12209 | * for this crtc. |
| 12210 | */ |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12211 | pipe_config = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc)); |
| 12212 | if (IS_ERR(pipe_config)) |
| 12213 | return pipe_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12214 | |
Ander Conselvan de Oliveira | 4fed33f | 2015-04-21 17:13:03 +0300 | [diff] [blame] | 12215 | if (!pipe_config->base.enable) |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12216 | return pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12217 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12218 | ret = intel_modeset_pipe_config(crtc, state, pipe_config); |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12219 | if (ret) |
| 12220 | return ERR_PTR(ret); |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 12221 | |
Ander Conselvan de Oliveira | 8d8c9b5 | 2015-04-21 17:13:11 +0300 | [diff] [blame] | 12222 | /* Check things that can only be changed through modeset */ |
| 12223 | if (pipe_config->has_audio != |
| 12224 | to_intel_crtc(crtc)->config->has_audio) |
| 12225 | pipe_config->base.mode_changed = true; |
| 12226 | |
| 12227 | /* |
| 12228 | * Note we have an issue here with infoframes: current code |
| 12229 | * only updates them on the full mode set path per hw |
| 12230 | * requirements. So here we should be checking for any |
| 12231 | * required changes and forcing a mode set. |
| 12232 | */ |
| 12233 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12234 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,"[modeset]"); |
| 12235 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12236 | ret = drm_atomic_helper_check_planes(state->dev, state); |
| 12237 | if (ret) |
| 12238 | return ERR_PTR(ret); |
| 12239 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12240 | return pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12241 | } |
| 12242 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12243 | 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] | 12244 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12245 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12246 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12247 | unsigned clear_pipes = 0; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12248 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12249 | struct intel_crtc_state *intel_crtc_state; |
| 12250 | struct drm_crtc *crtc; |
| 12251 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12252 | int ret = 0; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12253 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12254 | |
| 12255 | if (!dev_priv->display.crtc_compute_clock) |
| 12256 | return 0; |
| 12257 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12258 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 12259 | intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12260 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12261 | |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12262 | if (needs_modeset(crtc_state)) { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12263 | clear_pipes |= 1 << intel_crtc->pipe; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12264 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
| 12265 | memset(&intel_crtc_state->dpll_hw_state, 0, |
| 12266 | sizeof(intel_crtc_state->dpll_hw_state)); |
| 12267 | } |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12268 | } |
| 12269 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12270 | ret = intel_shared_dpll_start_config(dev_priv, clear_pipes); |
| 12271 | if (ret) |
| 12272 | goto done; |
| 12273 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12274 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 12275 | if (!needs_modeset(crtc_state) || !crtc_state->enable) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12276 | continue; |
| 12277 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12278 | intel_crtc = to_intel_crtc(crtc); |
| 12279 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
| 12280 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12281 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12282 | intel_crtc_state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12283 | if (ret) { |
| 12284 | intel_shared_dpll_abort_config(dev_priv); |
| 12285 | goto done; |
| 12286 | } |
| 12287 | } |
| 12288 | |
| 12289 | done: |
| 12290 | return ret; |
| 12291 | } |
| 12292 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12293 | /* Code that should eventually be part of atomic_check() */ |
| 12294 | static int __intel_set_mode_checks(struct drm_atomic_state *state) |
| 12295 | { |
| 12296 | struct drm_device *dev = state->dev; |
| 12297 | int ret; |
| 12298 | |
| 12299 | /* |
| 12300 | * See if the config requires any additional preparation, e.g. |
| 12301 | * to adjust global state with pipes off. We need to do this |
| 12302 | * here so we can get the modeset_pipe updated config for the new |
| 12303 | * mode set on this crtc. For other crtcs we need to use the |
| 12304 | * adjusted_mode bits in the crtc directly. |
| 12305 | */ |
| 12306 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
| 12307 | ret = valleyview_modeset_global_pipes(state); |
| 12308 | if (ret) |
| 12309 | return ret; |
| 12310 | } |
| 12311 | |
| 12312 | ret = __intel_set_mode_setup_plls(state); |
| 12313 | if (ret) |
| 12314 | return ret; |
| 12315 | |
| 12316 | return 0; |
| 12317 | } |
| 12318 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12319 | static int __intel_set_mode(struct drm_crtc *modeset_crtc, |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12320 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12321 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12322 | struct drm_device *dev = modeset_crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12323 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 12324 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12325 | struct drm_crtc *crtc; |
| 12326 | struct drm_crtc_state *crtc_state; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 12327 | int ret = 0; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12328 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12329 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12330 | ret = __intel_set_mode_checks(state); |
| 12331 | if (ret < 0) |
| 12332 | return ret; |
| 12333 | |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 12334 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 12335 | if (ret) |
| 12336 | return ret; |
| 12337 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12338 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 12339 | if (!needs_modeset(crtc_state)) |
| 12340 | continue; |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 12341 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12342 | if (!crtc_state->enable) { |
Matt Roper | 90d4690 | 2015-05-07 14:31:28 -0700 | [diff] [blame] | 12343 | crtc_state->active = false; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12344 | intel_crtc_disable(crtc); |
| 12345 | } else if (crtc->state->enable) { |
| 12346 | intel_crtc_disable_planes(crtc); |
| 12347 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 12348 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12349 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12350 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 12351 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 12352 | * 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] | 12353 | * |
| 12354 | * Note we'll need to fix this up when we start tracking multiple |
| 12355 | * pipes; here we assume a single modeset_pipe and only track the |
| 12356 | * single crtc and mode. |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 12357 | */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12358 | if (pipe_config->base.enable && needs_modeset(&pipe_config->base)) { |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12359 | modeset_crtc->mode = pipe_config->base.mode; |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 12360 | |
| 12361 | /* |
| 12362 | * Calculate and store various constants which |
| 12363 | * are later needed by vblank and swap-completion |
| 12364 | * timestamping. They are derived from true hwmode. |
| 12365 | */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12366 | drm_calc_timestamping_constants(modeset_crtc, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12367 | &pipe_config->base.adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12368 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12369 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12370 | /* Only after disabling all output pipelines that will be changed can we |
| 12371 | * update the the output configuration. */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12372 | intel_modeset_update_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12373 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 12374 | /* The state has been swaped above, so state actually contains the |
| 12375 | * old state now. */ |
| 12376 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 12377 | modeset_update_crtc_power_domains(state); |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 12378 | |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 12379 | drm_atomic_helper_commit_planes(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12380 | |
| 12381 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12382 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 12383 | if (!needs_modeset(crtc->state) || !crtc->state->enable) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12384 | continue; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12385 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12386 | update_scanline_offset(to_intel_crtc(crtc)); |
| 12387 | |
| 12388 | dev_priv->display.crtc_enable(crtc); |
| 12389 | intel_crtc_enable_planes(crtc); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12390 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12391 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12392 | /* FIXME: add subpixel order */ |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12393 | |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 12394 | drm_atomic_helper_cleanup_planes(dev, state); |
| 12395 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 12396 | drm_atomic_state_free(state); |
| 12397 | |
Ander Conselvan de Oliveira | 9eb45f2 | 2015-04-21 17:13:07 +0300 | [diff] [blame] | 12398 | return 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12399 | } |
| 12400 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12401 | static int intel_set_mode_with_config(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12402 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12403 | { |
| 12404 | int ret; |
| 12405 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12406 | ret = __intel_set_mode(crtc, pipe_config); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12407 | |
| 12408 | if (ret == 0) |
| 12409 | intel_modeset_check_state(crtc->dev); |
| 12410 | |
| 12411 | return ret; |
| 12412 | } |
| 12413 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 12414 | static int intel_set_mode(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12415 | struct drm_atomic_state *state) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12416 | { |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12417 | struct intel_crtc_state *pipe_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12418 | int ret = 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12419 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12420 | pipe_config = intel_modeset_compute_config(crtc, state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12421 | if (IS_ERR(pipe_config)) { |
| 12422 | ret = PTR_ERR(pipe_config); |
| 12423 | goto out; |
| 12424 | } |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12425 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12426 | ret = intel_set_mode_with_config(crtc, pipe_config); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12427 | if (ret) |
| 12428 | goto out; |
| 12429 | |
| 12430 | out: |
| 12431 | return ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12432 | } |
| 12433 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 12434 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 12435 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12436 | struct drm_device *dev = crtc->dev; |
| 12437 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 12438 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12439 | struct intel_encoder *encoder; |
| 12440 | struct intel_connector *connector; |
| 12441 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 12442 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 12443 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12444 | |
| 12445 | state = drm_atomic_state_alloc(dev); |
| 12446 | if (!state) { |
| 12447 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", |
| 12448 | crtc->base.id); |
| 12449 | return; |
| 12450 | } |
| 12451 | |
| 12452 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 12453 | |
| 12454 | /* The force restore path in the HW readout code relies on the staged |
| 12455 | * config still keeping the user requested config while the actual |
| 12456 | * state has been overwritten by the configuration read from HW. We |
| 12457 | * need to copy the staged config to the atomic state, otherwise the |
| 12458 | * mode set will just reapply the state the HW is already in. */ |
| 12459 | for_each_intel_encoder(dev, encoder) { |
| 12460 | if (&encoder->new_crtc->base != crtc) |
| 12461 | continue; |
| 12462 | |
| 12463 | for_each_intel_connector(dev, connector) { |
| 12464 | if (connector->new_encoder != encoder) |
| 12465 | continue; |
| 12466 | |
| 12467 | connector_state = drm_atomic_get_connector_state(state, &connector->base); |
| 12468 | if (IS_ERR(connector_state)) { |
| 12469 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", |
| 12470 | connector->base.base.id, |
| 12471 | connector->base.name, |
| 12472 | PTR_ERR(connector_state)); |
| 12473 | continue; |
| 12474 | } |
| 12475 | |
| 12476 | connector_state->crtc = crtc; |
| 12477 | connector_state->best_encoder = &encoder->base; |
| 12478 | } |
| 12479 | } |
| 12480 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 12481 | for_each_intel_crtc(dev, intel_crtc) { |
| 12482 | if (intel_crtc->new_enabled == intel_crtc->base.enabled) |
| 12483 | continue; |
| 12484 | |
| 12485 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12486 | if (IS_ERR(crtc_state)) { |
| 12487 | DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", |
| 12488 | intel_crtc->base.base.id, |
| 12489 | PTR_ERR(crtc_state)); |
| 12490 | continue; |
| 12491 | } |
| 12492 | |
| 12493 | crtc_state->base.enable = intel_crtc->new_enabled; |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12494 | |
| 12495 | if (&intel_crtc->base == crtc) |
| 12496 | drm_mode_copy(&crtc_state->base.mode, &crtc->mode); |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 12497 | } |
| 12498 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 12499 | intel_modeset_setup_plane_state(state, crtc, &crtc->mode, |
| 12500 | crtc->primary->fb, crtc->x, crtc->y); |
| 12501 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 12502 | ret = intel_set_mode(crtc, state); |
| 12503 | if (ret) |
| 12504 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 12505 | } |
| 12506 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12507 | #undef for_each_intel_crtc_masked |
| 12508 | |
Ander Conselvan de Oliveira | b788526 | 2015-04-21 17:13:14 +0300 | [diff] [blame] | 12509 | static bool intel_connector_in_mode_set(struct intel_connector *connector, |
| 12510 | struct drm_mode_set *set) |
| 12511 | { |
| 12512 | int ro; |
| 12513 | |
| 12514 | for (ro = 0; ro < set->num_connectors; ro++) |
| 12515 | if (set->connectors[ro] == &connector->base) |
| 12516 | return true; |
| 12517 | |
| 12518 | return false; |
| 12519 | } |
| 12520 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12521 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12522 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 12523 | struct drm_mode_set *set, |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12524 | struct drm_atomic_state *state) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12525 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12526 | struct intel_connector *connector; |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12527 | struct drm_connector *drm_connector; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12528 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12529 | struct drm_crtc *crtc; |
| 12530 | struct drm_crtc_state *crtc_state; |
| 12531 | int i, ret; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12532 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 12533 | /* 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] | 12534 | * of connectors. For paranoia, double-check this. */ |
| 12535 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 12536 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 12537 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12538 | for_each_intel_connector(dev, connector) { |
Ander Conselvan de Oliveira | b788526 | 2015-04-21 17:13:14 +0300 | [diff] [blame] | 12539 | bool in_mode_set = intel_connector_in_mode_set(connector, set); |
| 12540 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12541 | if (!in_mode_set && connector->base.state->crtc != set->crtc) |
| 12542 | continue; |
| 12543 | |
| 12544 | connector_state = |
| 12545 | drm_atomic_get_connector_state(state, &connector->base); |
| 12546 | if (IS_ERR(connector_state)) |
| 12547 | return PTR_ERR(connector_state); |
| 12548 | |
Ander Conselvan de Oliveira | b788526 | 2015-04-21 17:13:14 +0300 | [diff] [blame] | 12549 | if (in_mode_set) { |
| 12550 | int pipe = to_intel_crtc(set->crtc)->pipe; |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12551 | connector_state->best_encoder = |
| 12552 | &intel_find_encoder(connector, pipe)->base; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12553 | } |
| 12554 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12555 | if (connector->base.state->crtc != set->crtc) |
Ander Conselvan de Oliveira | b788526 | 2015-04-21 17:13:14 +0300 | [diff] [blame] | 12556 | continue; |
| 12557 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12558 | /* If we disable the crtc, disable all its connectors. Also, if |
| 12559 | * the connector is on the changing crtc but not on the new |
| 12560 | * connector list, disable it. */ |
Ander Conselvan de Oliveira | b788526 | 2015-04-21 17:13:14 +0300 | [diff] [blame] | 12561 | if (!set->fb || !in_mode_set) { |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12562 | connector_state->best_encoder = NULL; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12563 | |
| 12564 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 12565 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12566 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12567 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12568 | } |
| 12569 | /* connector->new_encoder is now updated for all connectors. */ |
| 12570 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12571 | for_each_connector_in_state(state, drm_connector, connector_state, i) { |
| 12572 | connector = to_intel_connector(drm_connector); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12573 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12574 | if (!connector_state->best_encoder) { |
| 12575 | ret = drm_atomic_set_crtc_for_connector(connector_state, |
| 12576 | NULL); |
| 12577 | if (ret) |
| 12578 | return ret; |
| 12579 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12580 | continue; |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12581 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12582 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12583 | if (intel_connector_in_mode_set(connector, set)) { |
| 12584 | struct drm_crtc *crtc = connector->base.state->crtc; |
| 12585 | |
| 12586 | /* If this connector was in a previous crtc, add it |
| 12587 | * to the state. We might need to disable it. */ |
| 12588 | if (crtc) { |
| 12589 | crtc_state = |
| 12590 | drm_atomic_get_crtc_state(state, crtc); |
| 12591 | if (IS_ERR(crtc_state)) |
| 12592 | return PTR_ERR(crtc_state); |
| 12593 | } |
| 12594 | |
| 12595 | ret = drm_atomic_set_crtc_for_connector(connector_state, |
| 12596 | set->crtc); |
| 12597 | if (ret) |
| 12598 | return ret; |
| 12599 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12600 | |
| 12601 | /* Make sure the new CRTC will work with the encoder */ |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12602 | if (!drm_encoder_crtc_ok(connector_state->best_encoder, |
| 12603 | connector_state->crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12604 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12605 | } |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12606 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12607 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 12608 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12609 | connector->base.name, |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12610 | connector_state->crtc->base.id); |
| 12611 | |
| 12612 | if (connector_state->best_encoder != &connector->encoder->base) |
| 12613 | connector->encoder = |
| 12614 | to_intel_encoder(connector_state->best_encoder); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12615 | } |
| 12616 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12617 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 12618 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12619 | if (ret) |
| 12620 | return ret; |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 12621 | |
Ander Conselvan de Oliveira | d5432a9d | 2015-04-21 17:13:15 +0300 | [diff] [blame] | 12622 | crtc_state->enable = drm_atomic_connectors_for_crtc(state, crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12623 | } |
| 12624 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12625 | ret = intel_modeset_setup_plane_state(state, set->crtc, set->mode, |
| 12626 | set->fb, set->x, set->y); |
| 12627 | if (ret) |
| 12628 | return ret; |
| 12629 | |
| 12630 | crtc_state = drm_atomic_get_crtc_state(state, set->crtc); |
| 12631 | if (IS_ERR(crtc_state)) |
| 12632 | return PTR_ERR(crtc_state); |
| 12633 | |
| 12634 | if (set->mode) |
| 12635 | drm_mode_copy(&crtc_state->mode, set->mode); |
| 12636 | |
| 12637 | if (set->num_connectors) |
| 12638 | crtc_state->active = true; |
| 12639 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12640 | return 0; |
| 12641 | } |
| 12642 | |
Ander Conselvan de Oliveira | bb54662 | 2015-04-21 17:13:13 +0300 | [diff] [blame] | 12643 | static bool primary_plane_visible(struct drm_crtc *crtc) |
| 12644 | { |
| 12645 | struct intel_plane_state *plane_state = |
| 12646 | to_intel_plane_state(crtc->primary->state); |
| 12647 | |
| 12648 | return plane_state->visible; |
| 12649 | } |
| 12650 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12651 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 12652 | { |
| 12653 | struct drm_device *dev; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12654 | struct drm_atomic_state *state = NULL; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12655 | struct intel_crtc_state *pipe_config; |
Ander Conselvan de Oliveira | bb54662 | 2015-04-21 17:13:13 +0300 | [diff] [blame] | 12656 | bool primary_plane_was_visible; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12657 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12658 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 12659 | BUG_ON(!set); |
| 12660 | BUG_ON(!set->crtc); |
| 12661 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12662 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 12663 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 12664 | BUG_ON(!set->mode && set->fb); |
| 12665 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 12666 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12667 | if (set->fb) { |
| 12668 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 12669 | set->crtc->base.id, set->fb->base.id, |
| 12670 | (int)set->num_connectors, set->x, set->y); |
| 12671 | } else { |
| 12672 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12673 | } |
| 12674 | |
| 12675 | dev = set->crtc->dev; |
| 12676 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12677 | state = drm_atomic_state_alloc(dev); |
Ander Conselvan de Oliveira | 7cbf41d | 2015-04-21 17:13:16 +0300 | [diff] [blame] | 12678 | if (!state) |
| 12679 | return -ENOMEM; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12680 | |
| 12681 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 12682 | |
Ander Conselvan de Oliveira | 462a425 | 2015-04-21 17:13:00 +0300 | [diff] [blame] | 12683 | ret = intel_modeset_stage_output_state(dev, set, state); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12684 | if (ret) |
Ander Conselvan de Oliveira | 7cbf41d | 2015-04-21 17:13:16 +0300 | [diff] [blame] | 12685 | goto out; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12686 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12687 | pipe_config = intel_modeset_compute_config(set->crtc, state); |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12688 | if (IS_ERR(pipe_config)) { |
Matt Roper | 6ac0483 | 2014-11-17 09:59:28 -0800 | [diff] [blame] | 12689 | ret = PTR_ERR(pipe_config); |
Ander Conselvan de Oliveira | 7cbf41d | 2015-04-21 17:13:16 +0300 | [diff] [blame] | 12690 | goto out; |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12691 | } |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12692 | |
Jesse Barnes | 1f9954d | 2014-11-05 14:26:10 -0800 | [diff] [blame] | 12693 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
| 12694 | |
Ander Conselvan de Oliveira | bb54662 | 2015-04-21 17:13:13 +0300 | [diff] [blame] | 12695 | primary_plane_was_visible = primary_plane_visible(set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12696 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 12697 | ret = intel_set_mode_with_config(set->crtc, pipe_config); |
Ander Conselvan de Oliveira | bb54662 | 2015-04-21 17:13:13 +0300 | [diff] [blame] | 12698 | |
| 12699 | if (ret == 0 && |
| 12700 | pipe_config->base.enable && |
| 12701 | pipe_config->base.planes_changed && |
| 12702 | !needs_modeset(&pipe_config->base)) { |
| 12703 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12704 | |
| 12705 | /* |
| 12706 | * We need to make sure the primary plane is re-enabled if it |
| 12707 | * has previously been turned off. |
| 12708 | */ |
Ander Conselvan de Oliveira | bb54662 | 2015-04-21 17:13:13 +0300 | [diff] [blame] | 12709 | if (ret == 0 && !primary_plane_was_visible && |
| 12710 | primary_plane_visible(set->crtc)) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12711 | WARN_ON(!intel_crtc->active); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 12712 | intel_post_enable_primary(set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12713 | } |
| 12714 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12715 | /* |
| 12716 | * In the fastboot case this may be our only check of the |
| 12717 | * state after boot. It would be better to only do it on |
| 12718 | * the first update, but we don't have a nice way of doing that |
| 12719 | * (and really, set_config isn't used much for high freq page |
| 12720 | * flipping, so increasing its cost here shouldn't be a big |
| 12721 | * deal). |
| 12722 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 12723 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12724 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12725 | } |
| 12726 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12727 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 12728 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 12729 | set->crtc->base.id, ret); |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12730 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12731 | |
Ander Conselvan de Oliveira | 7cbf41d | 2015-04-21 17:13:16 +0300 | [diff] [blame] | 12732 | out: |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 12733 | if (ret) |
| 12734 | drm_atomic_state_free(state); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12735 | return ret; |
| 12736 | } |
| 12737 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12738 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12739 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12740 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12741 | .destroy = intel_crtc_destroy, |
| 12742 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 12743 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 12744 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12745 | }; |
| 12746 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12747 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 12748 | struct intel_shared_dpll *pll, |
| 12749 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12750 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12751 | uint32_t val; |
| 12752 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 12753 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 12754 | return false; |
| 12755 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12756 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12757 | hw_state->dpll = val; |
| 12758 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 12759 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12760 | |
| 12761 | return val & DPLL_VCO_ENABLE; |
| 12762 | } |
| 12763 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12764 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 12765 | struct intel_shared_dpll *pll) |
| 12766 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12767 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
| 12768 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12769 | } |
| 12770 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12771 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 12772 | struct intel_shared_dpll *pll) |
| 12773 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12774 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 12775 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12776 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12777 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12778 | |
| 12779 | /* Wait for the clocks to stabilize. */ |
| 12780 | POSTING_READ(PCH_DPLL(pll->id)); |
| 12781 | udelay(150); |
| 12782 | |
| 12783 | /* The pixel multiplier can only be updated once the |
| 12784 | * DPLL is enabled and the clocks are stable. |
| 12785 | * |
| 12786 | * So write it again. |
| 12787 | */ |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12788 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12789 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12790 | udelay(200); |
| 12791 | } |
| 12792 | |
| 12793 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 12794 | struct intel_shared_dpll *pll) |
| 12795 | { |
| 12796 | struct drm_device *dev = dev_priv->dev; |
| 12797 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12798 | |
| 12799 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12800 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12801 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 12802 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 12803 | } |
| 12804 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12805 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 12806 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12807 | udelay(200); |
| 12808 | } |
| 12809 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12810 | static char *ibx_pch_dpll_names[] = { |
| 12811 | "PCH DPLL A", |
| 12812 | "PCH DPLL B", |
| 12813 | }; |
| 12814 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12815 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12816 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12817 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12818 | int i; |
| 12819 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12820 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12821 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 12822 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12823 | dev_priv->shared_dplls[i].id = i; |
| 12824 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12825 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12826 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 12827 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12828 | dev_priv->shared_dplls[i].get_hw_state = |
| 12829 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12830 | } |
| 12831 | } |
| 12832 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12833 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 12834 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12835 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12836 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 12837 | if (HAS_DDI(dev)) |
| 12838 | intel_ddi_pll_init(dev); |
| 12839 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12840 | ibx_pch_dpll_init(dev); |
| 12841 | else |
| 12842 | dev_priv->num_shared_dpll = 0; |
| 12843 | |
| 12844 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12845 | } |
| 12846 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12847 | /** |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 12848 | * intel_wm_need_update - Check whether watermarks need updating |
| 12849 | * @plane: drm plane |
| 12850 | * @state: new plane state |
| 12851 | * |
| 12852 | * Check current plane state versus the new one to determine whether |
| 12853 | * watermarks need to be recalculated. |
| 12854 | * |
| 12855 | * Returns true or false. |
| 12856 | */ |
| 12857 | bool intel_wm_need_update(struct drm_plane *plane, |
| 12858 | struct drm_plane_state *state) |
| 12859 | { |
| 12860 | /* Update watermarks on tiling changes. */ |
| 12861 | if (!plane->state->fb || !state->fb || |
| 12862 | plane->state->fb->modifier[0] != state->fb->modifier[0] || |
| 12863 | plane->state->rotation != state->rotation) |
| 12864 | return true; |
| 12865 | |
| 12866 | return false; |
| 12867 | } |
| 12868 | |
| 12869 | /** |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12870 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 12871 | * @plane: drm plane to prepare for |
| 12872 | * @fb: framebuffer to prepare for presentation |
| 12873 | * |
| 12874 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 12875 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 12876 | * bits. Some older platforms need special physical address handling for |
| 12877 | * cursor planes. |
| 12878 | * |
| 12879 | * Returns 0 on success, negative error code on failure. |
| 12880 | */ |
| 12881 | int |
| 12882 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12883 | struct drm_framebuffer *fb, |
| 12884 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12885 | { |
| 12886 | struct drm_device *dev = plane->dev; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12887 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12888 | enum pipe pipe = intel_plane->pipe; |
| 12889 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12890 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
| 12891 | unsigned frontbuffer_bits = 0; |
| 12892 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12893 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12894 | if (!obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12895 | return 0; |
| 12896 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12897 | switch (plane->type) { |
| 12898 | case DRM_PLANE_TYPE_PRIMARY: |
| 12899 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); |
| 12900 | break; |
| 12901 | case DRM_PLANE_TYPE_CURSOR: |
| 12902 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); |
| 12903 | break; |
| 12904 | case DRM_PLANE_TYPE_OVERLAY: |
| 12905 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); |
| 12906 | break; |
| 12907 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12908 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 12909 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12910 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12911 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
| 12912 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 12913 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 12914 | ret = i915_gem_object_attach_phys(obj, align); |
| 12915 | if (ret) |
| 12916 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 12917 | } else { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12918 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12919 | } |
| 12920 | |
| 12921 | if (ret == 0) |
| 12922 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); |
| 12923 | |
| 12924 | mutex_unlock(&dev->struct_mutex); |
| 12925 | |
| 12926 | return ret; |
| 12927 | } |
| 12928 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12929 | /** |
| 12930 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 12931 | * @plane: drm plane to clean up for |
| 12932 | * @fb: old framebuffer that was on plane |
| 12933 | * |
| 12934 | * Cleans up a framebuffer that has just been removed from a plane. |
| 12935 | */ |
| 12936 | void |
| 12937 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12938 | struct drm_framebuffer *fb, |
| 12939 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12940 | { |
| 12941 | struct drm_device *dev = plane->dev; |
| 12942 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12943 | |
| 12944 | if (WARN_ON(!obj)) |
| 12945 | return; |
| 12946 | |
| 12947 | if (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 12948 | !INTEL_INFO(dev)->cursor_needs_physical) { |
| 12949 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12950 | intel_unpin_fb_obj(fb, old_state); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12951 | mutex_unlock(&dev->struct_mutex); |
| 12952 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12953 | } |
| 12954 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12955 | int |
| 12956 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 12957 | { |
| 12958 | int max_scale; |
| 12959 | struct drm_device *dev; |
| 12960 | struct drm_i915_private *dev_priv; |
| 12961 | int crtc_clock, cdclk; |
| 12962 | |
| 12963 | if (!intel_crtc || !crtc_state) |
| 12964 | return DRM_PLANE_HELPER_NO_SCALING; |
| 12965 | |
| 12966 | dev = intel_crtc->base.dev; |
| 12967 | dev_priv = dev->dev_private; |
| 12968 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 12969 | cdclk = dev_priv->display.get_display_clock_speed(dev); |
| 12970 | |
| 12971 | if (!crtc_clock || !cdclk) |
| 12972 | return DRM_PLANE_HELPER_NO_SCALING; |
| 12973 | |
| 12974 | /* |
| 12975 | * skl max scale is lower of: |
| 12976 | * close to 3 but not 3, -1 is for that purpose |
| 12977 | * or |
| 12978 | * cdclk/crtc_clock |
| 12979 | */ |
| 12980 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 12981 | |
| 12982 | return max_scale; |
| 12983 | } |
| 12984 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12985 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12986 | intel_check_primary_plane(struct drm_plane *plane, |
| 12987 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12988 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12989 | struct drm_device *dev = plane->dev; |
| 12990 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12991 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12992 | struct intel_crtc *intel_crtc; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12993 | struct intel_crtc_state *crtc_state; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12994 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12995 | struct drm_rect *dest = &state->dst; |
| 12996 | struct drm_rect *src = &state->src; |
| 12997 | const struct drm_rect *clip = &state->clip; |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 12998 | bool can_position = false; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12999 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 13000 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13001 | int ret; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13002 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13003 | crtc = crtc ? crtc : plane->crtc; |
| 13004 | intel_crtc = to_intel_crtc(crtc); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13005 | crtc_state = state->base.state ? |
| 13006 | intel_atomic_get_crtc_state(state->base.state, intel_crtc) : NULL; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13007 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13008 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13009 | min_scale = 1; |
| 13010 | max_scale = skl_max_scale(intel_crtc, crtc_state); |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13011 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13012 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13013 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13014 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 13015 | src, dest, clip, |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13016 | min_scale, |
| 13017 | max_scale, |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13018 | can_position, true, |
| 13019 | &state->visible); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13020 | if (ret) |
| 13021 | return ret; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13022 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13023 | if (intel_crtc->active) { |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 13024 | struct intel_plane_state *old_state = |
| 13025 | to_intel_plane_state(plane->state); |
| 13026 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13027 | intel_crtc->atomic.wait_for_flips = true; |
| 13028 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13029 | /* |
| 13030 | * FBC does not work on some platforms for rotated |
| 13031 | * planes, so disable it when rotation is not 0 and |
| 13032 | * update it when rotation is set back to 0. |
| 13033 | * |
| 13034 | * FIXME: This is redundant with the fbc update done in |
| 13035 | * the primary plane enable function except that that |
| 13036 | * one is done too late. We eventually need to unify |
| 13037 | * this. |
| 13038 | */ |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 13039 | if (state->visible && |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13040 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 13041 | dev_priv->fbc.crtc == intel_crtc && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13042 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13043 | intel_crtc->atomic.disable_fbc = true; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13044 | } |
| 13045 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 13046 | if (state->visible && !old_state->visible) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13047 | /* |
| 13048 | * BDW signals flip done immediately if the plane |
| 13049 | * is disabled, even if the plane enable is already |
| 13050 | * armed to occur at the next vblank :( |
| 13051 | */ |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 13052 | if (IS_BROADWELL(dev)) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13053 | intel_crtc->atomic.wait_vblank = true; |
| 13054 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13055 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13056 | intel_crtc->atomic.fb_bits |= |
| 13057 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
| 13058 | |
| 13059 | intel_crtc->atomic.update_fbc = true; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 13060 | |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 13061 | if (intel_wm_need_update(plane, &state->base)) |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 13062 | intel_crtc->atomic.update_wm = true; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13063 | } |
| 13064 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13065 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13066 | ret = skl_update_scaler_users(intel_crtc, crtc_state, |
| 13067 | to_intel_plane(plane), state, 0); |
| 13068 | if (ret) |
| 13069 | return ret; |
| 13070 | } |
| 13071 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13072 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13073 | } |
| 13074 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13075 | static void |
| 13076 | intel_commit_primary_plane(struct drm_plane *plane, |
| 13077 | struct intel_plane_state *state) |
| 13078 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13079 | struct drm_crtc *crtc = state->base.crtc; |
| 13080 | struct drm_framebuffer *fb = state->base.fb; |
| 13081 | struct drm_device *dev = plane->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13082 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13083 | struct intel_crtc *intel_crtc; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 13084 | struct drm_rect *src = &state->src; |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13085 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13086 | crtc = crtc ? crtc : plane->crtc; |
| 13087 | intel_crtc = to_intel_crtc(crtc); |
| 13088 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13089 | plane->fb = fb; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 13090 | crtc->x = src->x1 >> 16; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13091 | crtc->y = src->y1 >> 16; |
| 13092 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13093 | if (intel_crtc->active) { |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 13094 | if (state->visible) |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13095 | /* FIXME: kill this fastboot hack */ |
| 13096 | intel_update_pipe_size(intel_crtc); |
| 13097 | |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 13098 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 13099 | crtc->x, crtc->y); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13100 | } |
| 13101 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13102 | |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13103 | static void |
| 13104 | intel_disable_primary_plane(struct drm_plane *plane, |
| 13105 | struct drm_crtc *crtc, |
| 13106 | bool force) |
| 13107 | { |
| 13108 | struct drm_device *dev = plane->dev; |
| 13109 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13110 | |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13111 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
| 13112 | } |
| 13113 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13114 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
| 13115 | { |
| 13116 | struct drm_device *dev = crtc->dev; |
| 13117 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13118 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13119 | struct intel_plane *intel_plane; |
| 13120 | struct drm_plane *p; |
| 13121 | unsigned fb_bits = 0; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13122 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13123 | /* Track fb's for any planes being disabled */ |
| 13124 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { |
| 13125 | intel_plane = to_intel_plane(p); |
| 13126 | |
| 13127 | if (intel_crtc->atomic.disabled_planes & |
| 13128 | (1 << drm_plane_index(p))) { |
| 13129 | switch (p->type) { |
| 13130 | case DRM_PLANE_TYPE_PRIMARY: |
| 13131 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); |
| 13132 | break; |
| 13133 | case DRM_PLANE_TYPE_CURSOR: |
| 13134 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); |
| 13135 | break; |
| 13136 | case DRM_PLANE_TYPE_OVERLAY: |
| 13137 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); |
| 13138 | break; |
| 13139 | } |
| 13140 | |
| 13141 | mutex_lock(&dev->struct_mutex); |
| 13142 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); |
| 13143 | mutex_unlock(&dev->struct_mutex); |
| 13144 | } |
| 13145 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13146 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13147 | if (intel_crtc->atomic.wait_for_flips) |
| 13148 | intel_crtc_wait_for_pending_flips(crtc); |
| 13149 | |
| 13150 | if (intel_crtc->atomic.disable_fbc) |
| 13151 | intel_fbc_disable(dev); |
| 13152 | |
| 13153 | if (intel_crtc->atomic.pre_disable_primary) |
| 13154 | intel_pre_disable_primary(crtc); |
| 13155 | |
| 13156 | if (intel_crtc->atomic.update_wm) |
| 13157 | intel_update_watermarks(crtc); |
| 13158 | |
| 13159 | intel_runtime_pm_get(dev_priv); |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 13160 | |
| 13161 | /* Perform vblank evasion around commit operation */ |
| 13162 | if (intel_crtc->active) |
| 13163 | intel_crtc->atomic.evade = |
| 13164 | intel_pipe_update_start(intel_crtc, |
| 13165 | &intel_crtc->atomic.start_vbl_count); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13166 | } |
| 13167 | |
| 13168 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) |
| 13169 | { |
| 13170 | struct drm_device *dev = crtc->dev; |
| 13171 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13172 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13173 | struct drm_plane *p; |
| 13174 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 13175 | if (intel_crtc->atomic.evade) |
| 13176 | intel_pipe_update_end(intel_crtc, |
| 13177 | intel_crtc->atomic.start_vbl_count); |
| 13178 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13179 | intel_runtime_pm_put(dev_priv); |
| 13180 | |
| 13181 | if (intel_crtc->atomic.wait_vblank) |
| 13182 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 13183 | |
| 13184 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); |
| 13185 | |
| 13186 | if (intel_crtc->atomic.update_fbc) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13187 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 13188 | intel_fbc_update(dev); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13189 | mutex_unlock(&dev->struct_mutex); |
| 13190 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13191 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13192 | if (intel_crtc->atomic.post_enable_primary) |
| 13193 | intel_post_enable_primary(crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13194 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13195 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
| 13196 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) |
| 13197 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, |
| 13198 | false, false); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13199 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13200 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13201 | } |
| 13202 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13203 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13204 | * intel_plane_destroy - destroy a plane |
| 13205 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13206 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13207 | * Common destruction function for all types of planes (primary, cursor, |
| 13208 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13209 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13210 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13211 | { |
| 13212 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13213 | drm_plane_cleanup(plane); |
| 13214 | kfree(intel_plane); |
| 13215 | } |
| 13216 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13217 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 13218 | .update_plane = drm_atomic_helper_update_plane, |
| 13219 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13220 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 13221 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 13222 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13223 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13224 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13225 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13226 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13227 | }; |
| 13228 | |
| 13229 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 13230 | int pipe) |
| 13231 | { |
| 13232 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13233 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13234 | const uint32_t *intel_primary_formats; |
| 13235 | int num_formats; |
| 13236 | |
| 13237 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 13238 | if (primary == NULL) |
| 13239 | return NULL; |
| 13240 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13241 | state = intel_create_plane_state(&primary->base); |
| 13242 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13243 | kfree(primary); |
| 13244 | return NULL; |
| 13245 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13246 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13247 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13248 | primary->can_scale = false; |
| 13249 | primary->max_downscale = 1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13250 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13251 | primary->can_scale = true; |
| 13252 | } |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13253 | state->scaler_id = -1; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13254 | primary->pipe = pipe; |
| 13255 | primary->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13256 | primary->check_plane = intel_check_primary_plane; |
| 13257 | primary->commit_plane = intel_commit_primary_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13258 | primary->disable_plane = intel_disable_primary_plane; |
Chandra Konduru | 08e221f | 2015-04-07 15:28:37 -0700 | [diff] [blame] | 13259 | primary->ckey.flags = I915_SET_COLORKEY_NONE; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13260 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 13261 | primary->plane = !pipe; |
| 13262 | |
| 13263 | if (INTEL_INFO(dev)->gen <= 3) { |
| 13264 | intel_primary_formats = intel_primary_formats_gen2; |
| 13265 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 13266 | } else { |
| 13267 | intel_primary_formats = intel_primary_formats_gen4; |
| 13268 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 13269 | } |
| 13270 | |
| 13271 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13272 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13273 | intel_primary_formats, num_formats, |
| 13274 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13275 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13276 | if (INTEL_INFO(dev)->gen >= 4) |
| 13277 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13278 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13279 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 13280 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13281 | return &primary->base; |
| 13282 | } |
| 13283 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13284 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 13285 | { |
| 13286 | if (!dev->mode_config.rotation_property) { |
| 13287 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 13288 | BIT(DRM_ROTATE_180); |
| 13289 | |
| 13290 | if (INTEL_INFO(dev)->gen >= 9) |
| 13291 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 13292 | |
| 13293 | dev->mode_config.rotation_property = |
| 13294 | drm_mode_create_rotation_property(dev, flags); |
| 13295 | } |
| 13296 | if (dev->mode_config.rotation_property) |
| 13297 | drm_object_attach_property(&plane->base.base, |
| 13298 | dev->mode_config.rotation_property, |
| 13299 | plane->base.state->rotation); |
| 13300 | } |
| 13301 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13302 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13303 | intel_check_cursor_plane(struct drm_plane *plane, |
| 13304 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13305 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13306 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13307 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13308 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13309 | struct drm_rect *dest = &state->dst; |
| 13310 | struct drm_rect *src = &state->src; |
| 13311 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13312 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13313 | struct intel_crtc *intel_crtc; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13314 | unsigned stride; |
| 13315 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13316 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13317 | crtc = crtc ? crtc : plane->crtc; |
| 13318 | intel_crtc = to_intel_crtc(crtc); |
| 13319 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13320 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13321 | src, dest, clip, |
| 13322 | DRM_PLANE_HELPER_NO_SCALING, |
| 13323 | DRM_PLANE_HELPER_NO_SCALING, |
| 13324 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13325 | if (ret) |
| 13326 | return ret; |
| 13327 | |
| 13328 | |
| 13329 | /* if we want to turn off the cursor ignore width and height */ |
| 13330 | if (!obj) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13331 | goto finish; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13332 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13333 | /* Check for which cursor types we support */ |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13334 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
| 13335 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 13336 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13337 | return -EINVAL; |
| 13338 | } |
| 13339 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13340 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 13341 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13342 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 13343 | return -ENOMEM; |
| 13344 | } |
| 13345 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 13346 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13347 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 13348 | ret = -EINVAL; |
| 13349 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13350 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13351 | finish: |
| 13352 | if (intel_crtc->active) { |
Ville Syrjälä | 3749f46 | 2015-03-10 13:15:22 +0200 | [diff] [blame] | 13353 | if (plane->state->crtc_w != state->base.crtc_w) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13354 | intel_crtc->atomic.update_wm = true; |
| 13355 | |
| 13356 | intel_crtc->atomic.fb_bits |= |
| 13357 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); |
| 13358 | } |
| 13359 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13360 | return ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13361 | } |
| 13362 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13363 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13364 | intel_disable_cursor_plane(struct drm_plane *plane, |
| 13365 | struct drm_crtc *crtc, |
| 13366 | bool force) |
| 13367 | { |
| 13368 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13369 | |
| 13370 | if (!force) { |
| 13371 | plane->fb = NULL; |
| 13372 | intel_crtc->cursor_bo = NULL; |
| 13373 | intel_crtc->cursor_addr = 0; |
| 13374 | } |
| 13375 | |
| 13376 | intel_crtc_update_cursor(crtc, false); |
| 13377 | } |
| 13378 | |
| 13379 | static void |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13380 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 13381 | struct intel_plane_state *state) |
| 13382 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13383 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13384 | struct drm_device *dev = plane->dev; |
| 13385 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13386 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13387 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13388 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13389 | crtc = crtc ? crtc : plane->crtc; |
| 13390 | intel_crtc = to_intel_crtc(crtc); |
Sonika Jindal | a919db9 | 2014-10-23 07:41:33 -0700 | [diff] [blame] | 13391 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13392 | plane->fb = state->base.fb; |
| 13393 | crtc->cursor_x = state->base.crtc_x; |
| 13394 | crtc->cursor_y = state->base.crtc_y; |
| 13395 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13396 | if (intel_crtc->cursor_bo == obj) |
| 13397 | goto update; |
| 13398 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13399 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13400 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13401 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13402 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13403 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13404 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13405 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13406 | intel_crtc->cursor_addr = addr; |
| 13407 | intel_crtc->cursor_bo = obj; |
| 13408 | update: |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13409 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13410 | if (intel_crtc->active) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13411 | intel_crtc_update_cursor(crtc, state->visible); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13412 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13413 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13414 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 13415 | int pipe) |
| 13416 | { |
| 13417 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13418 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13419 | |
| 13420 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 13421 | if (cursor == NULL) |
| 13422 | return NULL; |
| 13423 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13424 | state = intel_create_plane_state(&cursor->base); |
| 13425 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13426 | kfree(cursor); |
| 13427 | return NULL; |
| 13428 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13429 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13430 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13431 | cursor->can_scale = false; |
| 13432 | cursor->max_downscale = 1; |
| 13433 | cursor->pipe = pipe; |
| 13434 | cursor->plane = pipe; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13435 | state->scaler_id = -1; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13436 | cursor->check_plane = intel_check_cursor_plane; |
| 13437 | cursor->commit_plane = intel_commit_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13438 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13439 | |
| 13440 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13441 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13442 | intel_cursor_formats, |
| 13443 | ARRAY_SIZE(intel_cursor_formats), |
| 13444 | DRM_PLANE_TYPE_CURSOR); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13445 | |
| 13446 | if (INTEL_INFO(dev)->gen >= 4) { |
| 13447 | if (!dev->mode_config.rotation_property) |
| 13448 | dev->mode_config.rotation_property = |
| 13449 | drm_mode_create_rotation_property(dev, |
| 13450 | BIT(DRM_ROTATE_0) | |
| 13451 | BIT(DRM_ROTATE_180)); |
| 13452 | if (dev->mode_config.rotation_property) |
| 13453 | drm_object_attach_property(&cursor->base.base, |
| 13454 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13455 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13456 | } |
| 13457 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13458 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13459 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13460 | return &cursor->base; |
| 13461 | } |
| 13462 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13463 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 13464 | struct intel_crtc_state *crtc_state) |
| 13465 | { |
| 13466 | int i; |
| 13467 | struct intel_scaler *intel_scaler; |
| 13468 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 13469 | |
| 13470 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 13471 | intel_scaler = &scaler_state->scalers[i]; |
| 13472 | intel_scaler->in_use = 0; |
| 13473 | intel_scaler->id = i; |
| 13474 | |
| 13475 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 13476 | } |
| 13477 | |
| 13478 | scaler_state->scaler_id = -1; |
| 13479 | } |
| 13480 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 13481 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13482 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13483 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13484 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13485 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13486 | struct drm_plane *primary = NULL; |
| 13487 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13488 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13489 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13490 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13491 | if (intel_crtc == NULL) |
| 13492 | return; |
| 13493 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13494 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 13495 | if (!crtc_state) |
| 13496 | goto fail; |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 13497 | intel_crtc->config = crtc_state; |
| 13498 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13499 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13500 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13501 | /* initialize shared scalers */ |
| 13502 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13503 | if (pipe == PIPE_C) |
| 13504 | intel_crtc->num_scalers = 1; |
| 13505 | else |
| 13506 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 13507 | |
| 13508 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 13509 | } |
| 13510 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13511 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13512 | if (!primary) |
| 13513 | goto fail; |
| 13514 | |
| 13515 | cursor = intel_cursor_plane_create(dev, pipe); |
| 13516 | if (!cursor) |
| 13517 | goto fail; |
| 13518 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13519 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13520 | cursor, &intel_crtc_funcs); |
| 13521 | if (ret) |
| 13522 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13523 | |
| 13524 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13525 | for (i = 0; i < 256; i++) { |
| 13526 | intel_crtc->lut_r[i] = i; |
| 13527 | intel_crtc->lut_g[i] = i; |
| 13528 | intel_crtc->lut_b[i] = i; |
| 13529 | } |
| 13530 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 13531 | /* |
| 13532 | * 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] | 13533 | * 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] | 13534 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13535 | intel_crtc->pipe = pipe; |
| 13536 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 13537 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 13538 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 13539 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13540 | } |
| 13541 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 13542 | intel_crtc->cursor_base = ~0; |
| 13543 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 13544 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 13545 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13546 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13547 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 13548 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 13549 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 13550 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 13551 | INIT_WORK(&intel_crtc->mmio_flip.work, intel_mmio_flip_work_func); |
| 13552 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13553 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13554 | |
| 13555 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13556 | return; |
| 13557 | |
| 13558 | fail: |
| 13559 | if (primary) |
| 13560 | drm_plane_cleanup(primary); |
| 13561 | if (cursor) |
| 13562 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13563 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13564 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13565 | } |
| 13566 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13567 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 13568 | { |
| 13569 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13570 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13571 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 13572 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13573 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 13574 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13575 | return INVALID_PIPE; |
| 13576 | |
| 13577 | return to_intel_crtc(encoder->crtc)->pipe; |
| 13578 | } |
| 13579 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13580 | 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] | 13581 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13582 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13583 | 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] | 13584 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13585 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13586 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13587 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13588 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13589 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13590 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 13591 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13592 | } |
| 13593 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13594 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13595 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13596 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13597 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13598 | } |
| 13599 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13600 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13601 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13602 | struct drm_device *dev = encoder->base.dev; |
| 13603 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13604 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13605 | int entry = 0; |
| 13606 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13607 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 13608 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13609 | index_mask |= (1 << entry); |
| 13610 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13611 | entry++; |
| 13612 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13613 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13614 | return index_mask; |
| 13615 | } |
| 13616 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13617 | static bool has_edp_a(struct drm_device *dev) |
| 13618 | { |
| 13619 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13620 | |
| 13621 | if (!IS_MOBILE(dev)) |
| 13622 | return false; |
| 13623 | |
| 13624 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 13625 | return false; |
| 13626 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 13627 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13628 | return false; |
| 13629 | |
| 13630 | return true; |
| 13631 | } |
| 13632 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13633 | static bool intel_crt_present(struct drm_device *dev) |
| 13634 | { |
| 13635 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13636 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 13637 | if (INTEL_INFO(dev)->gen >= 9) |
| 13638 | return false; |
| 13639 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 13640 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13641 | return false; |
| 13642 | |
| 13643 | if (IS_CHERRYVIEW(dev)) |
| 13644 | return false; |
| 13645 | |
| 13646 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 13647 | return false; |
| 13648 | |
| 13649 | return true; |
| 13650 | } |
| 13651 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13652 | static void intel_setup_outputs(struct drm_device *dev) |
| 13653 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13654 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13655 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13656 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13657 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 13658 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13659 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13660 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 13661 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13662 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 13663 | if (IS_BROXTON(dev)) { |
| 13664 | /* |
| 13665 | * FIXME: Broxton doesn't support port detection via the |
| 13666 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 13667 | * detect the ports. |
| 13668 | */ |
| 13669 | intel_ddi_init(dev, PORT_A); |
| 13670 | intel_ddi_init(dev, PORT_B); |
| 13671 | intel_ddi_init(dev, PORT_C); |
| 13672 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13673 | int found; |
| 13674 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13675 | /* |
| 13676 | * Haswell uses DDI functions to detect digital outputs. |
| 13677 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 13678 | * it's there. |
| 13679 | */ |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13680 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13681 | /* WaIgnoreDDIAStrap: skl */ |
| 13682 | if (found || |
| 13683 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13684 | intel_ddi_init(dev, PORT_A); |
| 13685 | |
| 13686 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 13687 | * register */ |
| 13688 | found = I915_READ(SFUSE_STRAP); |
| 13689 | |
| 13690 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 13691 | intel_ddi_init(dev, PORT_B); |
| 13692 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 13693 | intel_ddi_init(dev, PORT_C); |
| 13694 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 13695 | intel_ddi_init(dev, PORT_D); |
| 13696 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13697 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 13698 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13699 | |
| 13700 | if (has_edp_a(dev)) |
| 13701 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13702 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13703 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 13704 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 13705 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13706 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13707 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13708 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13709 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13710 | } |
| 13711 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13712 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13713 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13714 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13715 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13716 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13717 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13718 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13719 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13720 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13721 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13722 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 13723 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13724 | /* |
| 13725 | * The DP_DETECTED bit is the latched state of the DDC |
| 13726 | * SDA pin at boot. However since eDP doesn't require DDC |
| 13727 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 13728 | * eDP ports may have been muxed to an alternate function. |
| 13729 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 13730 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 13731 | * detect eDP ports. |
| 13732 | */ |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13733 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
| 13734 | !intel_dp_is_edp(dev, PORT_B)) |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13735 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 13736 | PORT_B); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13737 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
| 13738 | intel_dp_is_edp(dev, PORT_B)) |
| 13739 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13740 | |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13741 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
| 13742 | !intel_dp_is_edp(dev, PORT_C)) |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 13743 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 13744 | PORT_C); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13745 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
| 13746 | intel_dp_is_edp(dev, PORT_C)) |
| 13747 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 13748 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13749 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13750 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13751 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 13752 | PORT_D); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13753 | /* eDP not supported on port D, so don't check VBT */ |
| 13754 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 13755 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13756 | } |
| 13757 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 13758 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13759 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13760 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 13761 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13762 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13763 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13764 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13765 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13766 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13767 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13768 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13769 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13770 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13771 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13772 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13773 | |
| 13774 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13775 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13776 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13777 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13778 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13779 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13780 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13781 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13782 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13783 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13784 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13785 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13786 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13787 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13788 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13789 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13790 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13791 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13792 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13793 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 13794 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13795 | intel_dvo_init(dev); |
| 13796 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13797 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13798 | intel_tv_init(dev); |
| 13799 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 13800 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 13801 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13802 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13803 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 13804 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13805 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13806 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 13807 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 13808 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13809 | |
| 13810 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13811 | } |
| 13812 | |
| 13813 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 13814 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13815 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13816 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13817 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13818 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13819 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13820 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13821 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 13822 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13823 | kfree(intel_fb); |
| 13824 | } |
| 13825 | |
| 13826 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13827 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13828 | unsigned int *handle) |
| 13829 | { |
| 13830 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13831 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13832 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13833 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13834 | } |
| 13835 | |
| 13836 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 13837 | .destroy = intel_user_framebuffer_destroy, |
| 13838 | .create_handle = intel_user_framebuffer_create_handle, |
| 13839 | }; |
| 13840 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13841 | static |
| 13842 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 13843 | uint32_t pixel_format) |
| 13844 | { |
| 13845 | u32 gen = INTEL_INFO(dev)->gen; |
| 13846 | |
| 13847 | if (gen >= 9) { |
| 13848 | /* "The stride in bytes must not exceed the of the size of 8K |
| 13849 | * pixels and 32K bytes." |
| 13850 | */ |
| 13851 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); |
| 13852 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 13853 | return 32*1024; |
| 13854 | } else if (gen >= 4) { |
| 13855 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13856 | return 16*1024; |
| 13857 | else |
| 13858 | return 32*1024; |
| 13859 | } else if (gen >= 3) { |
| 13860 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13861 | return 8*1024; |
| 13862 | else |
| 13863 | return 16*1024; |
| 13864 | } else { |
| 13865 | /* XXX DSPC is limited to 4k tiled */ |
| 13866 | return 8*1024; |
| 13867 | } |
| 13868 | } |
| 13869 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 13870 | static int intel_framebuffer_init(struct drm_device *dev, |
| 13871 | struct intel_framebuffer *intel_fb, |
| 13872 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 13873 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13874 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 13875 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13876 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13877 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13878 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 13879 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 13880 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13881 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 13882 | /* Enforce that fb modifier and tiling mode match, but only for |
| 13883 | * X-tiled. This is needed for FBC. */ |
| 13884 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 13885 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 13886 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 13887 | return -EINVAL; |
| 13888 | } |
| 13889 | } else { |
| 13890 | if (obj->tiling_mode == I915_TILING_X) |
| 13891 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 13892 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 13893 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 13894 | return -EINVAL; |
| 13895 | } |
| 13896 | } |
| 13897 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 13898 | /* Passed in modifier sanity checking. */ |
| 13899 | switch (mode_cmd->modifier[0]) { |
| 13900 | case I915_FORMAT_MOD_Y_TILED: |
| 13901 | case I915_FORMAT_MOD_Yf_TILED: |
| 13902 | if (INTEL_INFO(dev)->gen < 9) { |
| 13903 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 13904 | mode_cmd->modifier[0]); |
| 13905 | return -EINVAL; |
| 13906 | } |
| 13907 | case DRM_FORMAT_MOD_NONE: |
| 13908 | case I915_FORMAT_MOD_X_TILED: |
| 13909 | break; |
| 13910 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 13911 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 13912 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13913 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13914 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13915 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13916 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
| 13917 | mode_cmd->pixel_format); |
| 13918 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 13919 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 13920 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13921 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13922 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13923 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13924 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 13925 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13926 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13927 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 13928 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13929 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13930 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13931 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13932 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13933 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13934 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13935 | mode_cmd->pitches[0] != obj->stride) { |
| 13936 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 13937 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13938 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13939 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13940 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13941 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13942 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13943 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13944 | case DRM_FORMAT_RGB565: |
| 13945 | case DRM_FORMAT_XRGB8888: |
| 13946 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13947 | break; |
| 13948 | case DRM_FORMAT_XRGB1555: |
| 13949 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13950 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13951 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13952 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13953 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13954 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13955 | break; |
| 13956 | case DRM_FORMAT_XBGR8888: |
| 13957 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13958 | case DRM_FORMAT_XRGB2101010: |
| 13959 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13960 | case DRM_FORMAT_XBGR2101010: |
| 13961 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13962 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13963 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13964 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13965 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13966 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 13967 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13968 | case DRM_FORMAT_YUYV: |
| 13969 | case DRM_FORMAT_UYVY: |
| 13970 | case DRM_FORMAT_YVYU: |
| 13971 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13972 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13973 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13974 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13975 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13976 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13977 | break; |
| 13978 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13979 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13980 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13981 | return -EINVAL; |
| 13982 | } |
| 13983 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 13984 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 13985 | if (mode_cmd->offsets[0] != 0) |
| 13986 | return -EINVAL; |
| 13987 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 13988 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 13989 | mode_cmd->pixel_format, |
| 13990 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 13991 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 13992 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 13993 | return -EINVAL; |
| 13994 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13995 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 13996 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 13997 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13998 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13999 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 14000 | if (ret) { |
| 14001 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 14002 | return ret; |
| 14003 | } |
| 14004 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14005 | return 0; |
| 14006 | } |
| 14007 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14008 | static struct drm_framebuffer * |
| 14009 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14010 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14011 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14012 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14013 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14014 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14015 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 14016 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 14017 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14018 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14019 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 14020 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14021 | } |
| 14022 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14023 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14024 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14025 | { |
| 14026 | } |
| 14027 | #endif |
| 14028 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14029 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14030 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14031 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14032 | .atomic_check = intel_atomic_check, |
| 14033 | .atomic_commit = intel_atomic_commit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14034 | }; |
| 14035 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14036 | /* Set up chip specific display functions */ |
| 14037 | static void intel_init_display(struct drm_device *dev) |
| 14038 | { |
| 14039 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14040 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14041 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 14042 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 14043 | else if (IS_CHERRYVIEW(dev)) |
| 14044 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14045 | else if (IS_VALLEYVIEW(dev)) |
| 14046 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 14047 | else if (IS_PINEVIEW(dev)) |
| 14048 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 14049 | else |
| 14050 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 14051 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14052 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14053 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14054 | dev_priv->display.get_initial_plane_config = |
| 14055 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14056 | dev_priv->display.crtc_compute_clock = |
| 14057 | haswell_crtc_compute_clock; |
| 14058 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14059 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
| 14060 | dev_priv->display.off = ironlake_crtc_off; |
| 14061 | dev_priv->display.update_primary_plane = |
| 14062 | skylake_update_primary_plane; |
| 14063 | } else if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14064 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14065 | dev_priv->display.get_initial_plane_config = |
| 14066 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14067 | dev_priv->display.crtc_compute_clock = |
| 14068 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14069 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14070 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 14071 | dev_priv->display.off = ironlake_crtc_off; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14072 | dev_priv->display.update_primary_plane = |
| 14073 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 14074 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14075 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14076 | dev_priv->display.get_initial_plane_config = |
| 14077 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14078 | dev_priv->display.crtc_compute_clock = |
| 14079 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14080 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14081 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14082 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14083 | dev_priv->display.update_primary_plane = |
| 14084 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14085 | } else if (IS_VALLEYVIEW(dev)) { |
| 14086 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14087 | dev_priv->display.get_initial_plane_config = |
| 14088 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14089 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14090 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14091 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14092 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14093 | dev_priv->display.update_primary_plane = |
| 14094 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14095 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14096 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14097 | dev_priv->display.get_initial_plane_config = |
| 14098 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14099 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14100 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14101 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14102 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14103 | dev_priv->display.update_primary_plane = |
| 14104 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14105 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14106 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14107 | /* Returns the core display clock speed */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14108 | if (IS_SKYLAKE(dev)) |
| 14109 | dev_priv->display.get_display_clock_speed = |
| 14110 | skylake_get_display_clock_speed; |
| 14111 | else if (IS_BROADWELL(dev)) |
| 14112 | dev_priv->display.get_display_clock_speed = |
| 14113 | broadwell_get_display_clock_speed; |
| 14114 | else if (IS_HASWELL(dev)) |
| 14115 | dev_priv->display.get_display_clock_speed = |
| 14116 | haswell_get_display_clock_speed; |
| 14117 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 14118 | dev_priv->display.get_display_clock_speed = |
| 14119 | valleyview_get_display_clock_speed; |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 14120 | else if (IS_GEN5(dev)) |
| 14121 | dev_priv->display.get_display_clock_speed = |
| 14122 | ilk_get_display_clock_speed; |
Ville Syrjälä | a7c66cd | 2015-03-31 14:11:56 +0300 | [diff] [blame] | 14123 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
| 14124 | 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] | 14125 | dev_priv->display.get_display_clock_speed = |
| 14126 | i945_get_display_clock_speed; |
| 14127 | else if (IS_I915G(dev)) |
| 14128 | dev_priv->display.get_display_clock_speed = |
| 14129 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 14130 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14131 | dev_priv->display.get_display_clock_speed = |
| 14132 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 14133 | else if (IS_PINEVIEW(dev)) |
| 14134 | dev_priv->display.get_display_clock_speed = |
| 14135 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14136 | else if (IS_I915GM(dev)) |
| 14137 | dev_priv->display.get_display_clock_speed = |
| 14138 | i915gm_get_display_clock_speed; |
| 14139 | else if (IS_I865G(dev)) |
| 14140 | dev_priv->display.get_display_clock_speed = |
| 14141 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 14142 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14143 | dev_priv->display.get_display_clock_speed = |
| 14144 | i855_get_display_clock_speed; |
| 14145 | else /* 852, 830 */ |
| 14146 | dev_priv->display.get_display_clock_speed = |
| 14147 | i830_get_display_clock_speed; |
| 14148 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 14149 | if (IS_GEN5(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14150 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14151 | } else if (IS_GEN6(dev)) { |
| 14152 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14153 | } else if (IS_IVYBRIDGE(dev)) { |
| 14154 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14155 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 14156 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14157 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 14158 | } else if (IS_VALLEYVIEW(dev)) { |
| 14159 | dev_priv->display.modeset_global_resources = |
| 14160 | valleyview_modeset_global_resources; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 14161 | } else if (IS_BROXTON(dev)) { |
| 14162 | dev_priv->display.modeset_global_resources = |
| 14163 | broxton_modeset_global_resources; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14164 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14165 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14166 | switch (INTEL_INFO(dev)->gen) { |
| 14167 | case 2: |
| 14168 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 14169 | break; |
| 14170 | |
| 14171 | case 3: |
| 14172 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 14173 | break; |
| 14174 | |
| 14175 | case 4: |
| 14176 | case 5: |
| 14177 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 14178 | break; |
| 14179 | |
| 14180 | case 6: |
| 14181 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 14182 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14183 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 14184 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14185 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 14186 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 14187 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 14188 | /* Drop through - unsupported since execlist only. */ |
| 14189 | default: |
| 14190 | /* Default just returns -ENODEV to indicate unsupported */ |
| 14191 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14192 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 14193 | |
| 14194 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 14195 | |
| 14196 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14197 | } |
| 14198 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14199 | /* |
| 14200 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 14201 | * resume, or other times. This quirk makes sure that's the case for |
| 14202 | * affected systems. |
| 14203 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 14204 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14205 | { |
| 14206 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14207 | |
| 14208 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14209 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14210 | } |
| 14211 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 14212 | static void quirk_pipeb_force(struct drm_device *dev) |
| 14213 | { |
| 14214 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14215 | |
| 14216 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 14217 | DRM_INFO("applying pipe b force quirk\n"); |
| 14218 | } |
| 14219 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14220 | /* |
| 14221 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 14222 | */ |
| 14223 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 14224 | { |
| 14225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14226 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14227 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14228 | } |
| 14229 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14230 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14231 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 14232 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14233 | */ |
| 14234 | static void quirk_invert_brightness(struct drm_device *dev) |
| 14235 | { |
| 14236 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14237 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14238 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14239 | } |
| 14240 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14241 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 14242 | static void quirk_backlight_present(struct drm_device *dev) |
| 14243 | { |
| 14244 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14245 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 14246 | DRM_INFO("applying backlight present quirk\n"); |
| 14247 | } |
| 14248 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14249 | struct intel_quirk { |
| 14250 | int device; |
| 14251 | int subsystem_vendor; |
| 14252 | int subsystem_device; |
| 14253 | void (*hook)(struct drm_device *dev); |
| 14254 | }; |
| 14255 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14256 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 14257 | struct intel_dmi_quirk { |
| 14258 | void (*hook)(struct drm_device *dev); |
| 14259 | const struct dmi_system_id (*dmi_id_list)[]; |
| 14260 | }; |
| 14261 | |
| 14262 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 14263 | { |
| 14264 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 14265 | return 1; |
| 14266 | } |
| 14267 | |
| 14268 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 14269 | { |
| 14270 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 14271 | { |
| 14272 | .callback = intel_dmi_reverse_brightness, |
| 14273 | .ident = "NCR Corporation", |
| 14274 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 14275 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 14276 | }, |
| 14277 | }, |
| 14278 | { } /* terminating entry */ |
| 14279 | }, |
| 14280 | .hook = quirk_invert_brightness, |
| 14281 | }, |
| 14282 | }; |
| 14283 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 14284 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14285 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 14286 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14287 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14288 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 14289 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 14290 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14291 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 14292 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 14293 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 14294 | /* 830 needs to leave pipe A & dpll A up */ |
| 14295 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 14296 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 14297 | /* 830 needs to leave pipe B & dpll B up */ |
| 14298 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 14299 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14300 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 14301 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 14302 | |
| 14303 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 14304 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14305 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 14306 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 14307 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 14308 | |
| 14309 | /* Acer/eMachines G725 */ |
| 14310 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 14311 | |
| 14312 | /* Acer/eMachines e725 */ |
| 14313 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 14314 | |
| 14315 | /* Acer/Packard Bell NCL20 */ |
| 14316 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 14317 | |
| 14318 | /* Acer Aspire 4736Z */ |
| 14319 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 14320 | |
| 14321 | /* Acer Aspire 5336 */ |
| 14322 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 14323 | |
| 14324 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 14325 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14326 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 14327 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 14328 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 14329 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 14330 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 14331 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 14332 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14333 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 14334 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 14335 | |
| 14336 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 14337 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 14338 | |
| 14339 | /* Dell Chromebook 11 */ |
| 14340 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14341 | }; |
| 14342 | |
| 14343 | static void intel_init_quirks(struct drm_device *dev) |
| 14344 | { |
| 14345 | struct pci_dev *d = dev->pdev; |
| 14346 | int i; |
| 14347 | |
| 14348 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 14349 | struct intel_quirk *q = &intel_quirks[i]; |
| 14350 | |
| 14351 | if (d->device == q->device && |
| 14352 | (d->subsystem_vendor == q->subsystem_vendor || |
| 14353 | q->subsystem_vendor == PCI_ANY_ID) && |
| 14354 | (d->subsystem_device == q->subsystem_device || |
| 14355 | q->subsystem_device == PCI_ANY_ID)) |
| 14356 | q->hook(dev); |
| 14357 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14358 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 14359 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 14360 | intel_dmi_quirks[i].hook(dev); |
| 14361 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14362 | } |
| 14363 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14364 | /* Disable the VGA plane that we never use */ |
| 14365 | static void i915_disable_vga(struct drm_device *dev) |
| 14366 | { |
| 14367 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14368 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14369 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14370 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14371 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14372 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14373 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14374 | sr1 = inb(VGA_SR_DATA); |
| 14375 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 14376 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 14377 | udelay(300); |
| 14378 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14379 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14380 | POSTING_READ(vga_reg); |
| 14381 | } |
| 14382 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14383 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14384 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 14385 | intel_prepare_ddi(dev); |
| 14386 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 14387 | if (IS_VALLEYVIEW(dev)) |
| 14388 | vlv_update_cdclk(dev); |
| 14389 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14390 | intel_init_clock_gating(dev); |
| 14391 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 14392 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14393 | } |
| 14394 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14395 | void intel_modeset_init(struct drm_device *dev) |
| 14396 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14397 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14398 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14399 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14400 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14401 | |
| 14402 | drm_mode_config_init(dev); |
| 14403 | |
| 14404 | dev->mode_config.min_width = 0; |
| 14405 | dev->mode_config.min_height = 0; |
| 14406 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 14407 | dev->mode_config.preferred_depth = 24; |
| 14408 | dev->mode_config.prefer_shadow = 1; |
| 14409 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 14410 | dev->mode_config.allow_fb_modifiers = true; |
| 14411 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 14412 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14413 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14414 | intel_init_quirks(dev); |
| 14415 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 14416 | intel_init_pm(dev); |
| 14417 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 14418 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14419 | return; |
| 14420 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14421 | intel_init_display(dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 14422 | intel_init_audio(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14423 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14424 | if (IS_GEN2(dev)) { |
| 14425 | dev->mode_config.max_width = 2048; |
| 14426 | dev->mode_config.max_height = 2048; |
| 14427 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 14428 | dev->mode_config.max_width = 4096; |
| 14429 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14430 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14431 | dev->mode_config.max_width = 8192; |
| 14432 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14433 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14434 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14435 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 14436 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 14437 | dev->mode_config.cursor_height = 1023; |
| 14438 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14439 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 14440 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 14441 | } else { |
| 14442 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 14443 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 14444 | } |
| 14445 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 14446 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14447 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14448 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14449 | INTEL_INFO(dev)->num_pipes, |
| 14450 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14451 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14452 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14453 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 14454 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14455 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14456 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 14457 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14458 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14459 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14460 | } |
| 14461 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 14462 | intel_init_dpio(dev); |
| 14463 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 14464 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14465 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14466 | /* Just disable it once at startup */ |
| 14467 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14468 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 14469 | |
| 14470 | /* Just in case the BIOS is doing something questionable. */ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 14471 | intel_fbc_disable(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 14472 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14473 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 14474 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14475 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14476 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14477 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14478 | if (!crtc->active) |
| 14479 | continue; |
| 14480 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14481 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14482 | * Note that reserving the BIOS fb up front prevents us |
| 14483 | * from stuffing other stolen allocations like the ring |
| 14484 | * on top. This prevents some ugliness at boot time, and |
| 14485 | * can even allow for smooth boot transitions if the BIOS |
| 14486 | * fb is large enough for the active pipe configuration. |
| 14487 | */ |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14488 | if (dev_priv->display.get_initial_plane_config) { |
| 14489 | dev_priv->display.get_initial_plane_config(crtc, |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14490 | &crtc->plane_config); |
| 14491 | /* |
| 14492 | * If the fb is shared between multiple heads, we'll |
| 14493 | * just get the first one. |
| 14494 | */ |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 14495 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14496 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14497 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14498 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 14499 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14500 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 14501 | { |
| 14502 | struct intel_connector *connector; |
| 14503 | struct drm_connector *crt = NULL; |
| 14504 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14505 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14506 | |
| 14507 | /* We can't just switch on the pipe A, we need to set things up with a |
| 14508 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 14509 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14510 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14511 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 14512 | crt = &connector->base; |
| 14513 | break; |
| 14514 | } |
| 14515 | } |
| 14516 | |
| 14517 | if (!crt) |
| 14518 | return; |
| 14519 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14520 | 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] | 14521 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14522 | } |
| 14523 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14524 | static bool |
| 14525 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 14526 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14527 | struct drm_device *dev = crtc->base.dev; |
| 14528 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14529 | u32 reg, val; |
| 14530 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14531 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14532 | return true; |
| 14533 | |
| 14534 | reg = DSPCNTR(!crtc->plane); |
| 14535 | val = I915_READ(reg); |
| 14536 | |
| 14537 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 14538 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 14539 | return false; |
| 14540 | |
| 14541 | return true; |
| 14542 | } |
| 14543 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14544 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 14545 | { |
| 14546 | struct drm_device *dev = crtc->base.dev; |
| 14547 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14548 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14549 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14550 | /* 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] | 14551 | reg = PIPECONF(crtc->config->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14552 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 14553 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14554 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14555 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 14556 | if (crtc->active) { |
| 14557 | update_scanline_offset(crtc); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14558 | drm_crtc_vblank_on(&crtc->base); |
| 14559 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14560 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14561 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14562 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 14563 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 14564 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14565 | struct intel_connector *connector; |
| 14566 | bool plane; |
| 14567 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14568 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 14569 | crtc->base.base.id); |
| 14570 | |
| 14571 | /* Pipe has the wrong plane attached and the plane is active. |
| 14572 | * Temporarily change the plane mapping and disable everything |
| 14573 | * ... */ |
| 14574 | plane = crtc->plane; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 14575 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14576 | crtc->plane = !plane; |
Maarten Lankhorst | ce22dba | 2015-04-21 17:12:56 +0300 | [diff] [blame] | 14577 | intel_crtc_disable_planes(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14578 | dev_priv->display.crtc_disable(&crtc->base); |
| 14579 | crtc->plane = plane; |
| 14580 | |
| 14581 | /* ... and break all links. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14582 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14583 | if (connector->encoder->base.crtc != &crtc->base) |
| 14584 | continue; |
| 14585 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14586 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14587 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14588 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14589 | /* multiple connectors may have the same encoder: |
| 14590 | * handle them and break crtc link separately */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14591 | for_each_intel_connector(dev, connector) |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14592 | if (connector->encoder->base.crtc == &crtc->base) { |
| 14593 | connector->encoder->base.crtc = NULL; |
| 14594 | connector->encoder->connectors_active = false; |
| 14595 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14596 | |
| 14597 | WARN_ON(crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14598 | crtc->base.state->enable = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14599 | crtc->base.enabled = false; |
| 14600 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14601 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14602 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 14603 | crtc->pipe == PIPE_A && !crtc->active) { |
| 14604 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 14605 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 14606 | * call below we restore the pipe to the right state, but leave |
| 14607 | * the required bits on. */ |
| 14608 | intel_enable_pipe_a(dev); |
| 14609 | } |
| 14610 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14611 | /* Adjust the state of the output pipe according to whether we |
| 14612 | * have active connectors/encoders. */ |
| 14613 | intel_crtc_update_dpms(&crtc->base); |
| 14614 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14615 | if (crtc->active != crtc->base.state->enable) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14616 | struct intel_encoder *encoder; |
| 14617 | |
| 14618 | /* This can happen either due to bugs in the get_hw_state |
| 14619 | * functions or because the pipe is force-enabled due to the |
| 14620 | * pipe A quirk. */ |
| 14621 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 14622 | crtc->base.base.id, |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14623 | crtc->base.state->enable ? "enabled" : "disabled", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14624 | crtc->active ? "enabled" : "disabled"); |
| 14625 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14626 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14627 | crtc->base.enabled = crtc->active; |
| 14628 | |
| 14629 | /* Because we only establish the connector -> encoder -> |
| 14630 | * crtc links if something is active, this means the |
| 14631 | * crtc is now deactivated. Break the links. connector |
| 14632 | * -> encoder links are only establish when things are |
| 14633 | * actually up, hence no need to break them. */ |
| 14634 | WARN_ON(crtc->active); |
| 14635 | |
| 14636 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 14637 | WARN_ON(encoder->connectors_active); |
| 14638 | encoder->base.crtc = NULL; |
| 14639 | } |
| 14640 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14641 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 14642 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14643 | /* |
| 14644 | * We start out with underrun reporting disabled to avoid races. |
| 14645 | * For correct bookkeeping mark this on active crtcs. |
| 14646 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14647 | * Also on gmch platforms we dont have any hardware bits to |
| 14648 | * disable the underrun reporting. Which means we need to start |
| 14649 | * out with underrun reporting disabled also on inactive pipes, |
| 14650 | * since otherwise we'll complain about the garbage we read when |
| 14651 | * e.g. coming up after runtime pm. |
| 14652 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14653 | * No protection against concurrent access is required - at |
| 14654 | * worst a fifo underrun happens which also sets this to false. |
| 14655 | */ |
| 14656 | crtc->cpu_fifo_underrun_disabled = true; |
| 14657 | crtc->pch_fifo_underrun_disabled = true; |
| 14658 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14659 | } |
| 14660 | |
| 14661 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 14662 | { |
| 14663 | struct intel_connector *connector; |
| 14664 | struct drm_device *dev = encoder->base.dev; |
| 14665 | |
| 14666 | /* We need to check both for a crtc link (meaning that the |
| 14667 | * encoder is active and trying to read from a pipe) and the |
| 14668 | * pipe itself being active. */ |
| 14669 | bool has_active_crtc = encoder->base.crtc && |
| 14670 | to_intel_crtc(encoder->base.crtc)->active; |
| 14671 | |
| 14672 | if (encoder->connectors_active && !has_active_crtc) { |
| 14673 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 14674 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14675 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14676 | |
| 14677 | /* Connector is active, but has no active pipe. This is |
| 14678 | * fallout from our resume register restoring. Disable |
| 14679 | * the encoder manually again. */ |
| 14680 | if (encoder->base.crtc) { |
| 14681 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 14682 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14683 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14684 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 14685 | if (encoder->post_disable) |
| 14686 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14687 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14688 | encoder->base.crtc = NULL; |
| 14689 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14690 | |
| 14691 | /* Inconsistent output/port/pipe state happens presumably due to |
| 14692 | * a bug in one of the get_hw_state functions. Or someplace else |
| 14693 | * in our code, like the register restore mess on resume. Clamp |
| 14694 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14695 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14696 | if (connector->encoder != encoder) |
| 14697 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14698 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14699 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14700 | } |
| 14701 | } |
| 14702 | /* Enabled encoders without active connectors will be fixed in |
| 14703 | * the crtc fixup. */ |
| 14704 | } |
| 14705 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14706 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14707 | { |
| 14708 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14709 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14710 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14711 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 14712 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 14713 | i915_disable_vga(dev); |
| 14714 | } |
| 14715 | } |
| 14716 | |
| 14717 | void i915_redisable_vga(struct drm_device *dev) |
| 14718 | { |
| 14719 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14720 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14721 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 14722 | * at a very early point in our resume sequence, where the power well |
| 14723 | * structures are not yet restored. Since this function is at a very |
| 14724 | * paranoid "someone might have enabled VGA while we were not looking" |
| 14725 | * level, just check if the power well is enabled instead of trying to |
| 14726 | * follow the "don't touch the power well if we don't need it" policy |
| 14727 | * the rest of the driver uses. */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14728 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14729 | return; |
| 14730 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14731 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14732 | } |
| 14733 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14734 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 14735 | { |
| 14736 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 14737 | |
| 14738 | if (!crtc->active) |
| 14739 | return false; |
| 14740 | |
| 14741 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 14742 | } |
| 14743 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14744 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14745 | { |
| 14746 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14747 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14748 | struct intel_crtc *crtc; |
| 14749 | struct intel_encoder *encoder; |
| 14750 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14751 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14752 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14753 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 14754 | struct drm_plane *primary = crtc->base.primary; |
| 14755 | struct intel_plane_state *plane_state; |
| 14756 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14757 | memset(crtc->config, 0, sizeof(*crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 14758 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14759 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 14760 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14761 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14762 | crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14763 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14764 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14765 | crtc->base.enabled = crtc->active; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 14766 | |
| 14767 | plane_state = to_intel_plane_state(primary->state); |
| 14768 | plane_state->visible = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14769 | |
| 14770 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 14771 | crtc->base.base.id, |
| 14772 | crtc->active ? "enabled" : "disabled"); |
| 14773 | } |
| 14774 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14775 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14776 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14777 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14778 | pll->on = pll->get_hw_state(dev_priv, pll, |
| 14779 | &pll->config.hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14780 | pll->active = 0; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14781 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14782 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14783 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14784 | pll->active++; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14785 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14786 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14787 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14788 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14789 | 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] | 14790 | pll->name, pll->config.crtc_mask, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14791 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14792 | if (pll->config.crtc_mask) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14793 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14794 | } |
| 14795 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14796 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14797 | pipe = 0; |
| 14798 | |
| 14799 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 14800 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14801 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14802 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14803 | } else { |
| 14804 | encoder->base.crtc = NULL; |
| 14805 | } |
| 14806 | |
| 14807 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14808 | 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] | 14809 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14810 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14811 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14812 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14813 | } |
| 14814 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14815 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14816 | if (connector->get_hw_state(connector)) { |
| 14817 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 14818 | connector->encoder->connectors_active = true; |
| 14819 | connector->base.encoder = &connector->encoder->base; |
| 14820 | } else { |
| 14821 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14822 | connector->base.encoder = NULL; |
| 14823 | } |
| 14824 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 14825 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 14826 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14827 | connector->base.encoder ? "enabled" : "disabled"); |
| 14828 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14829 | } |
| 14830 | |
| 14831 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 14832 | * and i915 state tracking structures. */ |
| 14833 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 14834 | bool force_restore) |
| 14835 | { |
| 14836 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14837 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14838 | struct intel_crtc *crtc; |
| 14839 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14840 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14841 | |
| 14842 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14843 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14844 | /* |
| 14845 | * Now that we have the config, copy it to each CRTC struct |
| 14846 | * Note that this could go away if we move to using crtc_config |
| 14847 | * checking everywhere. |
| 14848 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14849 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 14850 | if (crtc->active && i915.fastboot) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14851 | intel_mode_from_pipe_config(&crtc->base.mode, |
| 14852 | crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14853 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 14854 | crtc->base.base.id); |
| 14855 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 14856 | } |
| 14857 | } |
| 14858 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14859 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14860 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14861 | intel_sanitize_encoder(encoder); |
| 14862 | } |
| 14863 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14864 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14865 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14866 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14867 | intel_dump_pipe_config(crtc, crtc->config, |
| 14868 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14869 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 14870 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 14871 | intel_modeset_update_connector_atomic_state(dev); |
| 14872 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14873 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14874 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14875 | |
| 14876 | if (!pll->on || pll->active) |
| 14877 | continue; |
| 14878 | |
| 14879 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 14880 | |
| 14881 | pll->disable(dev_priv, pll); |
| 14882 | pll->on = false; |
| 14883 | } |
| 14884 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 14885 | if (IS_GEN9(dev)) |
| 14886 | skl_wm_get_hw_state(dev); |
| 14887 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 14888 | ilk_wm_get_hw_state(dev); |
| 14889 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14890 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 14891 | i915_redisable_vga(dev); |
| 14892 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14893 | /* |
| 14894 | * We need to use raw interfaces for restoring state to avoid |
| 14895 | * checking (bogus) intermediate states. |
| 14896 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14897 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 14898 | struct drm_crtc *crtc = |
| 14899 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14900 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14901 | intel_crtc_restore_mode(crtc); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14902 | } |
| 14903 | } else { |
| 14904 | intel_modeset_update_staged_output_state(dev); |
| 14905 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 14906 | |
| 14907 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14908 | } |
| 14909 | |
| 14910 | void intel_modeset_gem_init(struct drm_device *dev) |
| 14911 | { |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14912 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14913 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14914 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 14915 | int ret; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14916 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14917 | mutex_lock(&dev->struct_mutex); |
| 14918 | intel_init_gt_powersave(dev); |
| 14919 | mutex_unlock(&dev->struct_mutex); |
| 14920 | |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14921 | /* |
| 14922 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 14923 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 14924 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 14925 | * indicates as much. |
| 14926 | */ |
| 14927 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 14928 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 14929 | DREF_SSC1_ENABLE); |
| 14930 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 14931 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 14932 | |
| 14933 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14934 | |
| 14935 | /* |
| 14936 | * Make sure any fbs we allocated at startup are properly |
| 14937 | * pinned & fenced. When we do the allocation it's too early |
| 14938 | * for this. |
| 14939 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 14940 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14941 | obj = intel_fb_obj(c->primary->fb); |
| 14942 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14943 | continue; |
| 14944 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 14945 | mutex_lock(&dev->struct_mutex); |
| 14946 | ret = intel_pin_and_fence_fb_obj(c->primary, |
| 14947 | c->primary->fb, |
| 14948 | c->primary->state, |
| 14949 | NULL); |
| 14950 | mutex_unlock(&dev->struct_mutex); |
| 14951 | if (ret) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14952 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 14953 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 14954 | drm_framebuffer_unreference(c->primary->fb); |
| 14955 | c->primary->fb = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 14956 | update_state_fb(c->primary); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14957 | } |
| 14958 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14959 | |
| 14960 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14961 | } |
| 14962 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14963 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 14964 | { |
| 14965 | struct drm_connector *connector = &intel_connector->base; |
| 14966 | |
| 14967 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 14968 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14969 | } |
| 14970 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14971 | void intel_modeset_cleanup(struct drm_device *dev) |
| 14972 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14973 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14974 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14975 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14976 | intel_disable_gt_powersave(dev); |
| 14977 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14978 | intel_backlight_unregister(dev); |
| 14979 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14980 | /* |
| 14981 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14982 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14983 | * experience fancy races otherwise. |
| 14984 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 14985 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 14986 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14987 | /* |
| 14988 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 14989 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 14990 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 14991 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14992 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14993 | mutex_lock(&dev->struct_mutex); |
| 14994 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 14995 | intel_unregister_dsm_handler(); |
| 14996 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 14997 | intel_fbc_disable(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14998 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 14999 | mutex_unlock(&dev->struct_mutex); |
| 15000 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15001 | /* flush any delayed tasks or pending work */ |
| 15002 | flush_scheduled_work(); |
| 15003 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 15004 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 15005 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15006 | struct intel_connector *intel_connector; |
| 15007 | |
| 15008 | intel_connector = to_intel_connector(connector); |
| 15009 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 15010 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 15011 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15012 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15013 | |
| 15014 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15015 | |
| 15016 | mutex_lock(&dev->struct_mutex); |
| 15017 | intel_cleanup_gt_powersave(dev); |
| 15018 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15019 | } |
| 15020 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15021 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 15022 | * Return which encoder is currently attached for connector. |
| 15023 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15024 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15025 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15026 | return &intel_attached_encoder(connector)->base; |
| 15027 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15028 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15029 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 15030 | struct intel_encoder *encoder) |
| 15031 | { |
| 15032 | connector->encoder = encoder; |
| 15033 | drm_mode_connector_attach_encoder(&connector->base, |
| 15034 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15035 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15036 | |
| 15037 | /* |
| 15038 | * set vga decode state - true == enable VGA decode |
| 15039 | */ |
| 15040 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 15041 | { |
| 15042 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 15043 | 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] | 15044 | u16 gmch_ctrl; |
| 15045 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15046 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15047 | DRM_ERROR("failed to read control word\n"); |
| 15048 | return -EIO; |
| 15049 | } |
| 15050 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15051 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15052 | return 0; |
| 15053 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15054 | if (state) |
| 15055 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15056 | else |
| 15057 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15058 | |
| 15059 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15060 | DRM_ERROR("failed to write control word\n"); |
| 15061 | return -EIO; |
| 15062 | } |
| 15063 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15064 | return 0; |
| 15065 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15066 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15067 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15068 | |
| 15069 | u32 power_well_driver; |
| 15070 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15071 | int num_transcoders; |
| 15072 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15073 | struct intel_cursor_error_state { |
| 15074 | u32 control; |
| 15075 | u32 position; |
| 15076 | u32 base; |
| 15077 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15078 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15079 | |
| 15080 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15081 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15082 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15083 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15084 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15085 | |
| 15086 | struct intel_plane_error_state { |
| 15087 | u32 control; |
| 15088 | u32 stride; |
| 15089 | u32 size; |
| 15090 | u32 pos; |
| 15091 | u32 addr; |
| 15092 | u32 surface; |
| 15093 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15094 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15095 | |
| 15096 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15097 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15098 | enum transcoder cpu_transcoder; |
| 15099 | |
| 15100 | u32 conf; |
| 15101 | |
| 15102 | u32 htotal; |
| 15103 | u32 hblank; |
| 15104 | u32 hsync; |
| 15105 | u32 vtotal; |
| 15106 | u32 vblank; |
| 15107 | u32 vsync; |
| 15108 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15109 | }; |
| 15110 | |
| 15111 | struct intel_display_error_state * |
| 15112 | intel_display_capture_error_state(struct drm_device *dev) |
| 15113 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 15114 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15115 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15116 | int transcoders[] = { |
| 15117 | TRANSCODER_A, |
| 15118 | TRANSCODER_B, |
| 15119 | TRANSCODER_C, |
| 15120 | TRANSCODER_EDP, |
| 15121 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15122 | int i; |
| 15123 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15124 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 15125 | return NULL; |
| 15126 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15127 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15128 | if (error == NULL) |
| 15129 | return NULL; |
| 15130 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 15131 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15132 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 15133 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15134 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15135 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15136 | __intel_display_power_is_enabled(dev_priv, |
| 15137 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15138 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15139 | continue; |
| 15140 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 15141 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 15142 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 15143 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15144 | |
| 15145 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 15146 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15147 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 15148 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15149 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 15150 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 15151 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 15152 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15153 | if (INTEL_INFO(dev)->gen >= 4) { |
| 15154 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 15155 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 15156 | } |
| 15157 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15158 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15159 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 15160 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15161 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15162 | } |
| 15163 | |
| 15164 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 15165 | if (HAS_DDI(dev_priv->dev)) |
| 15166 | error->num_transcoders++; /* Account for eDP. */ |
| 15167 | |
| 15168 | for (i = 0; i < error->num_transcoders; i++) { |
| 15169 | enum transcoder cpu_transcoder = transcoders[i]; |
| 15170 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15171 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15172 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 15173 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15174 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15175 | continue; |
| 15176 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15177 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 15178 | |
| 15179 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 15180 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 15181 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 15182 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 15183 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 15184 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 15185 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15186 | } |
| 15187 | |
| 15188 | return error; |
| 15189 | } |
| 15190 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15191 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 15192 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15193 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15194 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15195 | struct drm_device *dev, |
| 15196 | struct intel_display_error_state *error) |
| 15197 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15198 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15199 | int i; |
| 15200 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15201 | if (!error) |
| 15202 | return; |
| 15203 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15204 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 15205 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15206 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15207 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15208 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15209 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15210 | err_printf(m, " Power: %s\n", |
| 15211 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15212 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15213 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15214 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15215 | err_printf(m, "Plane [%d]:\n", i); |
| 15216 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 15217 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15218 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15219 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 15220 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15221 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 15222 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15223 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15224 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15225 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 15226 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15227 | } |
| 15228 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15229 | err_printf(m, "Cursor [%d]:\n", i); |
| 15230 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 15231 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 15232 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15233 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15234 | |
| 15235 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 15236 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15237 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15238 | err_printf(m, " Power: %s\n", |
| 15239 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15240 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 15241 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 15242 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 15243 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 15244 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 15245 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 15246 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 15247 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15248 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15249 | |
| 15250 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 15251 | { |
| 15252 | struct intel_crtc *crtc; |
| 15253 | |
| 15254 | for_each_intel_crtc(dev, crtc) { |
| 15255 | struct intel_unpin_work *work; |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15256 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 15257 | spin_lock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15258 | |
| 15259 | work = crtc->unpin_work; |
| 15260 | |
| 15261 | if (work && work->event && |
| 15262 | work->event->base.file_priv == file) { |
| 15263 | kfree(work->event); |
| 15264 | work->event = NULL; |
| 15265 | } |
| 15266 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 15267 | spin_unlock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15268 | } |
| 15269 | } |