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 for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 49 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 50 | DRM_FORMAT_C8, |
| 51 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 52 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 53 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 57 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 58 | DRM_FORMAT_C8, |
| 59 | DRM_FORMAT_RGB565, |
| 60 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 61 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 62 | DRM_FORMAT_XRGB2101010, |
| 63 | DRM_FORMAT_XBGR2101010, |
| 64 | }; |
| 65 | |
| 66 | static const uint32_t skl_primary_formats[] = { |
| 67 | DRM_FORMAT_C8, |
| 68 | DRM_FORMAT_RGB565, |
| 69 | DRM_FORMAT_XRGB8888, |
| 70 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 71 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 72 | DRM_FORMAT_ABGR8888, |
| 73 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 74 | DRM_FORMAT_XBGR2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 77 | /* Cursor formats */ |
| 78 | static const uint32_t intel_cursor_formats[] = { |
| 79 | DRM_FORMAT_ARGB8888, |
| 80 | }; |
| 81 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 82 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 83 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 84 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 85 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 86 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 87 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 88 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 89 | static int intel_framebuffer_init(struct drm_device *dev, |
| 90 | struct intel_framebuffer *ifb, |
| 91 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 92 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 93 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 94 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 95 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 96 | struct intel_link_m_n *m_n, |
| 97 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 98 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 99 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
| 100 | static void intel_set_pipe_csc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 101 | static void vlv_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); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 103 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 104 | const struct intel_crtc_state *pipe_config); |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 105 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 106 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 107 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 108 | struct intel_crtc_state *crtc_state); |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 109 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 110 | int num_connectors); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 111 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 112 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 113 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 114 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 115 | } intel_range_t; |
| 116 | |
| 117 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 118 | int dot_limit; |
| 119 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 120 | } intel_p2_t; |
| 121 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 122 | typedef struct intel_limit intel_limit_t; |
| 123 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 124 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 125 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 126 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 127 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 128 | int |
| 129 | intel_pch_rawclk(struct drm_device *dev) |
| 130 | { |
| 131 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 132 | |
| 133 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 134 | |
| 135 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 136 | } |
| 137 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 138 | static inline u32 /* units of 100MHz */ |
| 139 | intel_fdi_link_freq(struct drm_device *dev) |
| 140 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 141 | if (IS_GEN5(dev)) { |
| 142 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 143 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 144 | } else |
| 145 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 148 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 149 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 150 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 151 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 152 | .m = { .min = 96, .max = 140 }, |
| 153 | .m1 = { .min = 18, .max = 26 }, |
| 154 | .m2 = { .min = 6, .max = 16 }, |
| 155 | .p = { .min = 4, .max = 128 }, |
| 156 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 157 | .p2 = { .dot_limit = 165000, |
| 158 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 161 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 162 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 163 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 164 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 165 | .m = { .min = 96, .max = 140 }, |
| 166 | .m1 = { .min = 18, .max = 26 }, |
| 167 | .m2 = { .min = 6, .max = 16 }, |
| 168 | .p = { .min = 4, .max = 128 }, |
| 169 | .p1 = { .min = 2, .max = 33 }, |
| 170 | .p2 = { .dot_limit = 165000, |
| 171 | .p2_slow = 4, .p2_fast = 4 }, |
| 172 | }; |
| 173 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 174 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 175 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 176 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 177 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 178 | .m = { .min = 96, .max = 140 }, |
| 179 | .m1 = { .min = 18, .max = 26 }, |
| 180 | .m2 = { .min = 6, .max = 16 }, |
| 181 | .p = { .min = 4, .max = 128 }, |
| 182 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 183 | .p2 = { .dot_limit = 165000, |
| 184 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 185 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 186 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 187 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 188 | .dot = { .min = 20000, .max = 400000 }, |
| 189 | .vco = { .min = 1400000, .max = 2800000 }, |
| 190 | .n = { .min = 1, .max = 6 }, |
| 191 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 192 | .m1 = { .min = 8, .max = 18 }, |
| 193 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 194 | .p = { .min = 5, .max = 80 }, |
| 195 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 196 | .p2 = { .dot_limit = 200000, |
| 197 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 201 | .dot = { .min = 20000, .max = 400000 }, |
| 202 | .vco = { .min = 1400000, .max = 2800000 }, |
| 203 | .n = { .min = 1, .max = 6 }, |
| 204 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 205 | .m1 = { .min = 8, .max = 18 }, |
| 206 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 207 | .p = { .min = 7, .max = 98 }, |
| 208 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 209 | .p2 = { .dot_limit = 112000, |
| 210 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 213 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 214 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 215 | .dot = { .min = 25000, .max = 270000 }, |
| 216 | .vco = { .min = 1750000, .max = 3500000}, |
| 217 | .n = { .min = 1, .max = 4 }, |
| 218 | .m = { .min = 104, .max = 138 }, |
| 219 | .m1 = { .min = 17, .max = 23 }, |
| 220 | .m2 = { .min = 5, .max = 11 }, |
| 221 | .p = { .min = 10, .max = 30 }, |
| 222 | .p1 = { .min = 1, .max = 3}, |
| 223 | .p2 = { .dot_limit = 270000, |
| 224 | .p2_slow = 10, |
| 225 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 226 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 230 | .dot = { .min = 22000, .max = 400000 }, |
| 231 | .vco = { .min = 1750000, .max = 3500000}, |
| 232 | .n = { .min = 1, .max = 4 }, |
| 233 | .m = { .min = 104, .max = 138 }, |
| 234 | .m1 = { .min = 16, .max = 23 }, |
| 235 | .m2 = { .min = 5, .max = 11 }, |
| 236 | .p = { .min = 5, .max = 80 }, |
| 237 | .p1 = { .min = 1, .max = 8}, |
| 238 | .p2 = { .dot_limit = 165000, |
| 239 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 243 | .dot = { .min = 20000, .max = 115000 }, |
| 244 | .vco = { .min = 1750000, .max = 3500000 }, |
| 245 | .n = { .min = 1, .max = 3 }, |
| 246 | .m = { .min = 104, .max = 138 }, |
| 247 | .m1 = { .min = 17, .max = 23 }, |
| 248 | .m2 = { .min = 5, .max = 11 }, |
| 249 | .p = { .min = 28, .max = 112 }, |
| 250 | .p1 = { .min = 2, .max = 8 }, |
| 251 | .p2 = { .dot_limit = 0, |
| 252 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 253 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 257 | .dot = { .min = 80000, .max = 224000 }, |
| 258 | .vco = { .min = 1750000, .max = 3500000 }, |
| 259 | .n = { .min = 1, .max = 3 }, |
| 260 | .m = { .min = 104, .max = 138 }, |
| 261 | .m1 = { .min = 17, .max = 23 }, |
| 262 | .m2 = { .min = 5, .max = 11 }, |
| 263 | .p = { .min = 14, .max = 42 }, |
| 264 | .p1 = { .min = 2, .max = 6 }, |
| 265 | .p2 = { .dot_limit = 0, |
| 266 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 267 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 270 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 271 | .dot = { .min = 20000, .max = 400000}, |
| 272 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 273 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 274 | .n = { .min = 3, .max = 6 }, |
| 275 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 276 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 277 | .m1 = { .min = 0, .max = 0 }, |
| 278 | .m2 = { .min = 0, .max = 254 }, |
| 279 | .p = { .min = 5, .max = 80 }, |
| 280 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 281 | .p2 = { .dot_limit = 200000, |
| 282 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 285 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 286 | .dot = { .min = 20000, .max = 400000 }, |
| 287 | .vco = { .min = 1700000, .max = 3500000 }, |
| 288 | .n = { .min = 3, .max = 6 }, |
| 289 | .m = { .min = 2, .max = 256 }, |
| 290 | .m1 = { .min = 0, .max = 0 }, |
| 291 | .m2 = { .min = 0, .max = 254 }, |
| 292 | .p = { .min = 7, .max = 112 }, |
| 293 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 294 | .p2 = { .dot_limit = 112000, |
| 295 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 298 | /* Ironlake / Sandybridge |
| 299 | * |
| 300 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 301 | * the range value for them is (actual_value - 2). |
| 302 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 303 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 304 | .dot = { .min = 25000, .max = 350000 }, |
| 305 | .vco = { .min = 1760000, .max = 3510000 }, |
| 306 | .n = { .min = 1, .max = 5 }, |
| 307 | .m = { .min = 79, .max = 127 }, |
| 308 | .m1 = { .min = 12, .max = 22 }, |
| 309 | .m2 = { .min = 5, .max = 9 }, |
| 310 | .p = { .min = 5, .max = 80 }, |
| 311 | .p1 = { .min = 1, .max = 8 }, |
| 312 | .p2 = { .dot_limit = 225000, |
| 313 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 316 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 317 | .dot = { .min = 25000, .max = 350000 }, |
| 318 | .vco = { .min = 1760000, .max = 3510000 }, |
| 319 | .n = { .min = 1, .max = 3 }, |
| 320 | .m = { .min = 79, .max = 118 }, |
| 321 | .m1 = { .min = 12, .max = 22 }, |
| 322 | .m2 = { .min = 5, .max = 9 }, |
| 323 | .p = { .min = 28, .max = 112 }, |
| 324 | .p1 = { .min = 2, .max = 8 }, |
| 325 | .p2 = { .dot_limit = 225000, |
| 326 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 330 | .dot = { .min = 25000, .max = 350000 }, |
| 331 | .vco = { .min = 1760000, .max = 3510000 }, |
| 332 | .n = { .min = 1, .max = 3 }, |
| 333 | .m = { .min = 79, .max = 127 }, |
| 334 | .m1 = { .min = 12, .max = 22 }, |
| 335 | .m2 = { .min = 5, .max = 9 }, |
| 336 | .p = { .min = 14, .max = 56 }, |
| 337 | .p1 = { .min = 2, .max = 8 }, |
| 338 | .p2 = { .dot_limit = 225000, |
| 339 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 340 | }; |
| 341 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 342 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 343 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 344 | .dot = { .min = 25000, .max = 350000 }, |
| 345 | .vco = { .min = 1760000, .max = 3510000 }, |
| 346 | .n = { .min = 1, .max = 2 }, |
| 347 | .m = { .min = 79, .max = 126 }, |
| 348 | .m1 = { .min = 12, .max = 22 }, |
| 349 | .m2 = { .min = 5, .max = 9 }, |
| 350 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 351 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 352 | .p2 = { .dot_limit = 225000, |
| 353 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 357 | .dot = { .min = 25000, .max = 350000 }, |
| 358 | .vco = { .min = 1760000, .max = 3510000 }, |
| 359 | .n = { .min = 1, .max = 3 }, |
| 360 | .m = { .min = 79, .max = 126 }, |
| 361 | .m1 = { .min = 12, .max = 22 }, |
| 362 | .m2 = { .min = 5, .max = 9 }, |
| 363 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 364 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 365 | .p2 = { .dot_limit = 225000, |
| 366 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 367 | }; |
| 368 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 369 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 370 | /* |
| 371 | * These are the data rate limits (measured in fast clocks) |
| 372 | * since those are the strictest limits we have. The fast |
| 373 | * clock and actual rate limits are more relaxed, so checking |
| 374 | * them would make no difference. |
| 375 | */ |
| 376 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 377 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 378 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 379 | .m1 = { .min = 2, .max = 3 }, |
| 380 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 381 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 382 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 385 | static const intel_limit_t intel_limits_chv = { |
| 386 | /* |
| 387 | * These are the data rate limits (measured in fast clocks) |
| 388 | * since those are the strictest limits we have. The fast |
| 389 | * clock and actual rate limits are more relaxed, so checking |
| 390 | * them would make no difference. |
| 391 | */ |
| 392 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 393 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 394 | .n = { .min = 1, .max = 1 }, |
| 395 | .m1 = { .min = 2, .max = 2 }, |
| 396 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 397 | .p1 = { .min = 2, .max = 4 }, |
| 398 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 399 | }; |
| 400 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 401 | static const intel_limit_t intel_limits_bxt = { |
| 402 | /* FIXME: find real dot limits */ |
| 403 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 404 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 405 | .n = { .min = 1, .max = 1 }, |
| 406 | .m1 = { .min = 2, .max = 2 }, |
| 407 | /* FIXME: find real m2 limits */ |
| 408 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 409 | .p1 = { .min = 2, .max = 4 }, |
| 410 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 411 | }; |
| 412 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 413 | static bool |
| 414 | needs_modeset(struct drm_crtc_state *state) |
| 415 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 416 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 419 | /** |
| 420 | * Returns whether any output on the specified pipe is of the specified type |
| 421 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 422 | 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] | 423 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 424 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 425 | struct intel_encoder *encoder; |
| 426 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 427 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 428 | if (encoder->type == type) |
| 429 | return true; |
| 430 | |
| 431 | return false; |
| 432 | } |
| 433 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 434 | /** |
| 435 | * Returns whether any output on the specified pipe will have the specified |
| 436 | * type after a staged modeset is complete, i.e., the same as |
| 437 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 438 | * encoder->crtc. |
| 439 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 440 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 441 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 442 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 443 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 444 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 445 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 446 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 447 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 448 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 449 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 450 | if (connector_state->crtc != crtc_state->base.crtc) |
| 451 | continue; |
| 452 | |
| 453 | num_connectors++; |
| 454 | |
| 455 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 456 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 457 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 461 | |
| 462 | return false; |
| 463 | } |
| 464 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 465 | static const intel_limit_t * |
| 466 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 467 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 468 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 469 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 470 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 471 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 472 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 473 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 474 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 475 | else |
| 476 | limit = &intel_limits_ironlake_dual_lvds; |
| 477 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 478 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 479 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 480 | else |
| 481 | limit = &intel_limits_ironlake_single_lvds; |
| 482 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 483 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 484 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 485 | |
| 486 | return limit; |
| 487 | } |
| 488 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 489 | static const intel_limit_t * |
| 490 | intel_g4x_limit(struct intel_crtc_state *crtc_state) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 491 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 492 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 493 | const intel_limit_t *limit; |
| 494 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 495 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 496 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 497 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 498 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 499 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 500 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 501 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 502 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 503 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 504 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 505 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 506 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 507 | |
| 508 | return limit; |
| 509 | } |
| 510 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 511 | static const intel_limit_t * |
| 512 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 513 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 514 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 515 | const intel_limit_t *limit; |
| 516 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 517 | if (IS_BROXTON(dev)) |
| 518 | limit = &intel_limits_bxt; |
| 519 | else if (HAS_PCH_SPLIT(dev)) |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 520 | limit = intel_ironlake_limit(crtc_state, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 521 | else if (IS_G4X(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 522 | limit = intel_g4x_limit(crtc_state); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 523 | } else if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 524 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 525 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 526 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 527 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 528 | } else if (IS_CHERRYVIEW(dev)) { |
| 529 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 530 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 531 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 532 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 533 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 534 | limit = &intel_limits_i9xx_lvds; |
| 535 | else |
| 536 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 537 | } else { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 538 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 539 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 540 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 541 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 542 | else |
| 543 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 544 | } |
| 545 | return limit; |
| 546 | } |
| 547 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 548 | /* |
| 549 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 550 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 551 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 552 | * The helpers' return value is the rate of the clock that is fed to the |
| 553 | * display engine's pipe which can be the above fast dot clock rate or a |
| 554 | * divided-down version of it. |
| 555 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 556 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 557 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 558 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 559 | clock->m = clock->m2 + 2; |
| 560 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 561 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 562 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 563 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 564 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 565 | |
| 566 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 567 | } |
| 568 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 569 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 570 | { |
| 571 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 572 | } |
| 573 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 574 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 575 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 576 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 577 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 578 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 579 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 580 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 581 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 582 | |
| 583 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 586 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 587 | { |
| 588 | clock->m = clock->m1 * clock->m2; |
| 589 | clock->p = clock->p1 * clock->p2; |
| 590 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 591 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 592 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 593 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 594 | |
| 595 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 596 | } |
| 597 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 598 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 599 | { |
| 600 | clock->m = clock->m1 * clock->m2; |
| 601 | clock->p = clock->p1 * clock->p2; |
| 602 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 603 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 604 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 605 | clock->n << 22); |
| 606 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 607 | |
| 608 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 609 | } |
| 610 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 611 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | /** |
| 613 | * Returns whether the given set of divisors are valid for a given refclk with |
| 614 | * the given connectors. |
| 615 | */ |
| 616 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 617 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 618 | const intel_limit_t *limit, |
| 619 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 620 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 621 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 622 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 623 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 624 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 625 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 626 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 627 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 628 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 629 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 630 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 631 | if (clock->m1 <= clock->m2) |
| 632 | INTELPllInvalid("m1 <= m2\n"); |
| 633 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 634 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 635 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 636 | INTELPllInvalid("p out of range\n"); |
| 637 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 638 | INTELPllInvalid("m out of range\n"); |
| 639 | } |
| 640 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 641 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 642 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 644 | * connector, etc., rather than just a single range. |
| 645 | */ |
| 646 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 647 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 648 | |
| 649 | return true; |
| 650 | } |
| 651 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 652 | static int |
| 653 | i9xx_select_p2_div(const intel_limit_t *limit, |
| 654 | const struct intel_crtc_state *crtc_state, |
| 655 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 656 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 657 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 659 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 660 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 661 | * For LVDS just rely on its current settings for dual-channel. |
| 662 | * We haven't figured out how to reliably set up different |
| 663 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 664 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 665 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 666 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 667 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 668 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 669 | } else { |
| 670 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 671 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 672 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 673 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 674 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static bool |
| 678 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 679 | struct intel_crtc_state *crtc_state, |
| 680 | int target, int refclk, intel_clock_t *match_clock, |
| 681 | intel_clock_t *best_clock) |
| 682 | { |
| 683 | struct drm_device *dev = crtc_state->base.crtc->dev; |
| 684 | intel_clock_t clock; |
| 685 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 686 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 687 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 688 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 689 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 690 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 691 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 692 | clock.m1++) { |
| 693 | for (clock.m2 = limit->m2.min; |
| 694 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 695 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 696 | break; |
| 697 | for (clock.n = limit->n.min; |
| 698 | clock.n <= limit->n.max; clock.n++) { |
| 699 | for (clock.p1 = limit->p1.min; |
| 700 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 701 | int this_err; |
| 702 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 703 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 704 | if (!intel_PLL_is_valid(dev, limit, |
| 705 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 706 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 707 | if (match_clock && |
| 708 | clock.p != match_clock->p) |
| 709 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 710 | |
| 711 | this_err = abs(clock.dot - target); |
| 712 | if (this_err < err) { |
| 713 | *best_clock = clock; |
| 714 | err = this_err; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | return (err != target); |
| 722 | } |
| 723 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 724 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 725 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 726 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 727 | int target, int refclk, intel_clock_t *match_clock, |
| 728 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 729 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 730 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 731 | intel_clock_t clock; |
| 732 | int err = target; |
| 733 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 734 | memset(best_clock, 0, sizeof(*best_clock)); |
| 735 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 736 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 737 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 738 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 739 | clock.m1++) { |
| 740 | for (clock.m2 = limit->m2.min; |
| 741 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 742 | for (clock.n = limit->n.min; |
| 743 | clock.n <= limit->n.max; clock.n++) { |
| 744 | for (clock.p1 = limit->p1.min; |
| 745 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 746 | int this_err; |
| 747 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 748 | pnv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 749 | if (!intel_PLL_is_valid(dev, limit, |
| 750 | &clock)) |
| 751 | continue; |
| 752 | if (match_clock && |
| 753 | clock.p != match_clock->p) |
| 754 | continue; |
| 755 | |
| 756 | this_err = abs(clock.dot - target); |
| 757 | if (this_err < err) { |
| 758 | *best_clock = clock; |
| 759 | err = this_err; |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | return (err != target); |
| 767 | } |
| 768 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 769 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 770 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 771 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 772 | int target, int refclk, intel_clock_t *match_clock, |
| 773 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 774 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 775 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 776 | intel_clock_t clock; |
| 777 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 778 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 779 | /* approximately equals target * 0.00585 */ |
| 780 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 781 | |
| 782 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 783 | |
| 784 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 785 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 786 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 787 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 788 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 789 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 790 | for (clock.m1 = limit->m1.max; |
| 791 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 792 | for (clock.m2 = limit->m2.max; |
| 793 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 794 | for (clock.p1 = limit->p1.max; |
| 795 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 796 | int this_err; |
| 797 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 798 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 799 | if (!intel_PLL_is_valid(dev, limit, |
| 800 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 801 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 802 | |
| 803 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 804 | if (this_err < err_most) { |
| 805 | *best_clock = clock; |
| 806 | err_most = this_err; |
| 807 | max_n = clock.n; |
| 808 | found = true; |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 814 | return found; |
| 815 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 816 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 817 | /* |
| 818 | * Check if the calculated PLL configuration is more optimal compared to the |
| 819 | * best configuration and error found so far. Return the calculated error. |
| 820 | */ |
| 821 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 822 | const intel_clock_t *calculated_clock, |
| 823 | const intel_clock_t *best_clock, |
| 824 | unsigned int best_error_ppm, |
| 825 | unsigned int *error_ppm) |
| 826 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 827 | /* |
| 828 | * For CHV ignore the error and consider only the P value. |
| 829 | * Prefer a bigger P value based on HW requirements. |
| 830 | */ |
| 831 | if (IS_CHERRYVIEW(dev)) { |
| 832 | *error_ppm = 0; |
| 833 | |
| 834 | return calculated_clock->p > best_clock->p; |
| 835 | } |
| 836 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 837 | if (WARN_ON_ONCE(!target_freq)) |
| 838 | return false; |
| 839 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 840 | *error_ppm = div_u64(1000000ULL * |
| 841 | abs(target_freq - calculated_clock->dot), |
| 842 | target_freq); |
| 843 | /* |
| 844 | * Prefer a better P value over a better (smaller) error if the error |
| 845 | * is small. Ensure this preference for future configurations too by |
| 846 | * setting the error to 0. |
| 847 | */ |
| 848 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 849 | *error_ppm = 0; |
| 850 | |
| 851 | return true; |
| 852 | } |
| 853 | |
| 854 | return *error_ppm + 10 < best_error_ppm; |
| 855 | } |
| 856 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 857 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 858 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 859 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 860 | int target, int refclk, intel_clock_t *match_clock, |
| 861 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 862 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 863 | 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] | 864 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 865 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 866 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 867 | /* min update 19.2 MHz */ |
| 868 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 869 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 870 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 871 | target *= 5; /* fast clock */ |
| 872 | |
| 873 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 874 | |
| 875 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 876 | 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] | 877 | 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] | 878 | 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] | 879 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 880 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 881 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 882 | 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] | 883 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 884 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 885 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 886 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 887 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 888 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 889 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 890 | if (!intel_PLL_is_valid(dev, limit, |
| 891 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 892 | continue; |
| 893 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 894 | if (!vlv_PLL_is_optimal(dev, target, |
| 895 | &clock, |
| 896 | best_clock, |
| 897 | bestppm, &ppm)) |
| 898 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 899 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 900 | *best_clock = clock; |
| 901 | bestppm = ppm; |
| 902 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } |
| 906 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 907 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 908 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 909 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 910 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 911 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 912 | chv_find_best_dpll(const intel_limit_t *limit, |
| 913 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 914 | int target, int refclk, intel_clock_t *match_clock, |
| 915 | intel_clock_t *best_clock) |
| 916 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 917 | 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] | 918 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 919 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 920 | intel_clock_t clock; |
| 921 | uint64_t m2; |
| 922 | int found = false; |
| 923 | |
| 924 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 925 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 926 | |
| 927 | /* |
| 928 | * Based on hardware doc, the n always set to 1, and m1 always |
| 929 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 930 | * revisit this because n may not 1 anymore. |
| 931 | */ |
| 932 | clock.n = 1, clock.m1 = 2; |
| 933 | target *= 5; /* fast clock */ |
| 934 | |
| 935 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 936 | for (clock.p2 = limit->p2.p2_fast; |
| 937 | clock.p2 >= limit->p2.p2_slow; |
| 938 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 939 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 940 | |
| 941 | clock.p = clock.p1 * clock.p2; |
| 942 | |
| 943 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 944 | clock.n) << 22, refclk * clock.m1); |
| 945 | |
| 946 | if (m2 > INT_MAX/clock.m1) |
| 947 | continue; |
| 948 | |
| 949 | clock.m2 = m2; |
| 950 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 951 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 952 | |
| 953 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 954 | continue; |
| 955 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 956 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 957 | best_error_ppm, &error_ppm)) |
| 958 | continue; |
| 959 | |
| 960 | *best_clock = clock; |
| 961 | best_error_ppm = error_ppm; |
| 962 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | return found; |
| 967 | } |
| 968 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 969 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
| 970 | intel_clock_t *best_clock) |
| 971 | { |
| 972 | int refclk = i9xx_get_refclk(crtc_state, 0); |
| 973 | |
| 974 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, |
| 975 | target_clock, refclk, NULL, best_clock); |
| 976 | } |
| 977 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 978 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 979 | { |
| 980 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 981 | |
| 982 | /* Be paranoid as we can arrive here with only partial |
| 983 | * state retrieved from the hardware during setup. |
| 984 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 985 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 986 | * as Haswell has gained clock readout/fastboot support. |
| 987 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 988 | * 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] | 989 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 990 | * |
| 991 | * FIXME: The intel_crtc->active here should be switched to |
| 992 | * crtc->state->active once we have proper CRTC states wired up |
| 993 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 994 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 995 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 996 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 997 | } |
| 998 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 999 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1000 | enum pipe pipe) |
| 1001 | { |
| 1002 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1003 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1004 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1005 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1006 | } |
| 1007 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1008 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 1009 | { |
| 1010 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1011 | u32 reg = PIPEDSL(pipe); |
| 1012 | u32 line1, line2; |
| 1013 | u32 line_mask; |
| 1014 | |
| 1015 | if (IS_GEN2(dev)) |
| 1016 | line_mask = DSL_LINEMASK_GEN2; |
| 1017 | else |
| 1018 | line_mask = DSL_LINEMASK_GEN3; |
| 1019 | |
| 1020 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1021 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1022 | line2 = I915_READ(reg) & line_mask; |
| 1023 | |
| 1024 | return line1 == line2; |
| 1025 | } |
| 1026 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1027 | /* |
| 1028 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1029 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1030 | * |
| 1031 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1032 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1033 | * see an interrupt when the pipe is disabled. |
| 1034 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1035 | * On Gen4 and above: |
| 1036 | * wait for the pipe register state bit to turn off |
| 1037 | * |
| 1038 | * Otherwise: |
| 1039 | * wait for the display line value to settle (it usually |
| 1040 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1041 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1042 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1043 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1044 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1045 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1046 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1047 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1048 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1049 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1050 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1051 | int reg = PIPECONF(cpu_transcoder); |
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 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1054 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1055 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1056 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1057 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1058 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1059 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1060 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1061 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1064 | static const char *state_string(bool enabled) |
| 1065 | { |
| 1066 | return enabled ? "on" : "off"; |
| 1067 | } |
| 1068 | |
| 1069 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1070 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1071 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1072 | { |
| 1073 | int reg; |
| 1074 | u32 val; |
| 1075 | bool cur_state; |
| 1076 | |
| 1077 | reg = DPLL(pipe); |
| 1078 | val = I915_READ(reg); |
| 1079 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1080 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1081 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1082 | state_string(state), state_string(cur_state)); |
| 1083 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1084 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1085 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1086 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1087 | { |
| 1088 | u32 val; |
| 1089 | bool cur_state; |
| 1090 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1091 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1092 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1093 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1094 | |
| 1095 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1096 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1097 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1098 | state_string(state), state_string(cur_state)); |
| 1099 | } |
| 1100 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1101 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1102 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1103 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1104 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1105 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1106 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1107 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1108 | if (crtc->config->shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1109 | return NULL; |
| 1110 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1111 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1112 | } |
| 1113 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1114 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1115 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1116 | struct intel_shared_dpll *pll, |
| 1117 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1118 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1119 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1120 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1121 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1122 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1123 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1124 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1125 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1126 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1127 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1128 | "%s assertion failure (expected %s, current %s)\n", |
| 1129 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1130 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1131 | |
| 1132 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1133 | enum pipe pipe, bool state) |
| 1134 | { |
| 1135 | int reg; |
| 1136 | u32 val; |
| 1137 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1138 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1139 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1140 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1141 | if (HAS_DDI(dev_priv->dev)) { |
| 1142 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1143 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1144 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1145 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1146 | } else { |
| 1147 | reg = FDI_TX_CTL(pipe); |
| 1148 | val = I915_READ(reg); |
| 1149 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1150 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1151 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1152 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1153 | state_string(state), state_string(cur_state)); |
| 1154 | } |
| 1155 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1156 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1157 | |
| 1158 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1159 | enum pipe pipe, bool state) |
| 1160 | { |
| 1161 | int reg; |
| 1162 | u32 val; |
| 1163 | bool cur_state; |
| 1164 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1165 | reg = FDI_RX_CTL(pipe); |
| 1166 | val = I915_READ(reg); |
| 1167 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1168 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1169 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1170 | state_string(state), state_string(cur_state)); |
| 1171 | } |
| 1172 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1173 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1174 | |
| 1175 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1176 | enum pipe pipe) |
| 1177 | { |
| 1178 | int reg; |
| 1179 | u32 val; |
| 1180 | |
| 1181 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1182 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1183 | return; |
| 1184 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1185 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1186 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1187 | return; |
| 1188 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1189 | reg = FDI_TX_CTL(pipe); |
| 1190 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1191 | 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] | 1192 | } |
| 1193 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1194 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1195 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1196 | { |
| 1197 | int reg; |
| 1198 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1199 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1200 | |
| 1201 | reg = FDI_RX_CTL(pipe); |
| 1202 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1203 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1204 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1205 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1206 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1209 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1210 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1211 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1212 | struct drm_device *dev = dev_priv->dev; |
| 1213 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1214 | u32 val; |
| 1215 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1216 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1217 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1218 | if (WARN_ON(HAS_DDI(dev))) |
| 1219 | return; |
| 1220 | |
| 1221 | if (HAS_PCH_SPLIT(dev)) { |
| 1222 | u32 port_sel; |
| 1223 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1224 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1225 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1226 | |
| 1227 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1228 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1229 | panel_pipe = PIPE_B; |
| 1230 | /* XXX: else fix for eDP */ |
| 1231 | } else if (IS_VALLEYVIEW(dev)) { |
| 1232 | /* presumably write lock depends on pipe, not port select */ |
| 1233 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1234 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1235 | } else { |
| 1236 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1237 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1238 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | val = I915_READ(pp_reg); |
| 1242 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1243 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1244 | locked = false; |
| 1245 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1246 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1247 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1248 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1249 | } |
| 1250 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1251 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1252 | enum pipe pipe, bool state) |
| 1253 | { |
| 1254 | struct drm_device *dev = dev_priv->dev; |
| 1255 | bool cur_state; |
| 1256 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1257 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1258 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1259 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1260 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1261 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1262 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1263 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1264 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1265 | } |
| 1266 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1267 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1268 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1269 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1270 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1271 | { |
| 1272 | int reg; |
| 1273 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1274 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1275 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1276 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1277 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1278 | /* if we need the pipe quirk it must be always on */ |
| 1279 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1280 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1281 | state = true; |
| 1282 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1283 | if (!intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1284 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1285 | cur_state = false; |
| 1286 | } else { |
| 1287 | reg = PIPECONF(cpu_transcoder); |
| 1288 | val = I915_READ(reg); |
| 1289 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1290 | } |
| 1291 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1292 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1293 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1294 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1297 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1298 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1299 | { |
| 1300 | int reg; |
| 1301 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1302 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1303 | |
| 1304 | reg = DSPCNTR(plane); |
| 1305 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1306 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1307 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1308 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1309 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1312 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1313 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1314 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1315 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1316 | enum pipe pipe) |
| 1317 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1318 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1319 | int reg, i; |
| 1320 | u32 val; |
| 1321 | int cur_pipe; |
| 1322 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1323 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1324 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1325 | reg = DSPCNTR(pipe); |
| 1326 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1327 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1328 | "plane %c assertion failure, should be disabled but not\n", |
| 1329 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1330 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1331 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1332 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1333 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1334 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1335 | reg = DSPCNTR(i); |
| 1336 | val = I915_READ(reg); |
| 1337 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1338 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1339 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1340 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1341 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1345 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1346 | enum pipe pipe) |
| 1347 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1348 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1349 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1350 | u32 val; |
| 1351 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1352 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1353 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1354 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1355 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1356 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1357 | sprite, pipe_name(pipe)); |
| 1358 | } |
| 1359 | } else if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1360 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1361 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1362 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1363 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1364 | "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] | 1365 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1366 | } |
| 1367 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1368 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1369 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1370 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1371 | "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] | 1372 | plane_name(pipe), pipe_name(pipe)); |
| 1373 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1374 | reg = DVSCNTR(pipe); |
| 1375 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1376 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1377 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1378 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1382 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1383 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1384 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1385 | drm_crtc_vblank_put(crtc); |
| 1386 | } |
| 1387 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1388 | 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] | 1389 | { |
| 1390 | u32 val; |
| 1391 | bool enabled; |
| 1392 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1393 | 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] | 1394 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1395 | val = I915_READ(PCH_DREF_CONTROL); |
| 1396 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1397 | DREF_SUPERSPREAD_SOURCE_MASK)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1398 | 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] | 1399 | } |
| 1400 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1401 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1402 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1403 | { |
| 1404 | int reg; |
| 1405 | u32 val; |
| 1406 | bool enabled; |
| 1407 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1408 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1409 | val = I915_READ(reg); |
| 1410 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1411 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1412 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1413 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1416 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1417 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1418 | { |
| 1419 | if ((val & DP_PORT_EN) == 0) |
| 1420 | return false; |
| 1421 | |
| 1422 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1423 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1424 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1425 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1426 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1427 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1428 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1429 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1430 | } else { |
| 1431 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1432 | return false; |
| 1433 | } |
| 1434 | return true; |
| 1435 | } |
| 1436 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1437 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1438 | enum pipe pipe, u32 val) |
| 1439 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1440 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1441 | return false; |
| 1442 | |
| 1443 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1444 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1445 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1446 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1447 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1448 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1449 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1450 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1451 | return false; |
| 1452 | } |
| 1453 | return true; |
| 1454 | } |
| 1455 | |
| 1456 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1457 | enum pipe pipe, u32 val) |
| 1458 | { |
| 1459 | if ((val & LVDS_PORT_EN) == 0) |
| 1460 | return false; |
| 1461 | |
| 1462 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1463 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1464 | return false; |
| 1465 | } else { |
| 1466 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1467 | return false; |
| 1468 | } |
| 1469 | return true; |
| 1470 | } |
| 1471 | |
| 1472 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1473 | enum pipe pipe, u32 val) |
| 1474 | { |
| 1475 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1476 | return false; |
| 1477 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1478 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1479 | return false; |
| 1480 | } else { |
| 1481 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1482 | return false; |
| 1483 | } |
| 1484 | return true; |
| 1485 | } |
| 1486 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1487 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1488 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1489 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1490 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1491 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1492 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1493 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1494 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1495 | 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] | 1496 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1497 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1501 | enum pipe pipe, int reg) |
| 1502 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1503 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1504 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1505 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1506 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1507 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1508 | 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] | 1509 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1510 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1514 | enum pipe pipe) |
| 1515 | { |
| 1516 | int reg; |
| 1517 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1518 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1519 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1520 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1521 | 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] | 1522 | |
| 1523 | reg = PCH_ADPA; |
| 1524 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1525 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1526 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1527 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1528 | |
| 1529 | reg = PCH_LVDS; |
| 1530 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1531 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1532 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1533 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1534 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1535 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1536 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1537 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1540 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1541 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1542 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1543 | struct drm_device *dev = crtc->base.dev; |
| 1544 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1545 | int reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1546 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1547 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1548 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1549 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1550 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1551 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1552 | |
| 1553 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1554 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1555 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1556 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1557 | I915_WRITE(reg, dpll); |
| 1558 | POSTING_READ(reg); |
| 1559 | udelay(150); |
| 1560 | |
| 1561 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1562 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1563 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1564 | 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] | 1565 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1566 | |
| 1567 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1568 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1569 | POSTING_READ(reg); |
| 1570 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1571 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1572 | POSTING_READ(reg); |
| 1573 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1574 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1575 | POSTING_READ(reg); |
| 1576 | udelay(150); /* wait for warmup */ |
| 1577 | } |
| 1578 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1579 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1580 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1581 | { |
| 1582 | struct drm_device *dev = crtc->base.dev; |
| 1583 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1584 | int pipe = crtc->pipe; |
| 1585 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1586 | u32 tmp; |
| 1587 | |
| 1588 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1589 | |
| 1590 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1591 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1592 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1593 | |
| 1594 | /* Enable back the 10bit clock to display controller */ |
| 1595 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1596 | tmp |= DPIO_DCLKP_EN; |
| 1597 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1598 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1599 | mutex_unlock(&dev_priv->sb_lock); |
| 1600 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1601 | /* |
| 1602 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1603 | */ |
| 1604 | udelay(1); |
| 1605 | |
| 1606 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1607 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1608 | |
| 1609 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1610 | 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] | 1611 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1612 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1613 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1614 | 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] | 1615 | POSTING_READ(DPLL_MD(pipe)); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1616 | } |
| 1617 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1618 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1619 | { |
| 1620 | struct intel_crtc *crtc; |
| 1621 | int count = 0; |
| 1622 | |
| 1623 | for_each_intel_crtc(dev, crtc) |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1624 | count += crtc->base.state->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1625 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1626 | |
| 1627 | return count; |
| 1628 | } |
| 1629 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1630 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1631 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1632 | struct drm_device *dev = crtc->base.dev; |
| 1633 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1634 | int reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1635 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1636 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1637 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1638 | |
| 1639 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1640 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1641 | |
| 1642 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1643 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1644 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1645 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1646 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1647 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1648 | /* |
| 1649 | * It appears to be important that we don't enable this |
| 1650 | * for the current pipe before otherwise configuring the |
| 1651 | * PLL. No idea how this should be handled if multiple |
| 1652 | * DVO outputs are enabled simultaneosly. |
| 1653 | */ |
| 1654 | dpll |= DPLL_DVO_2X_MODE; |
| 1655 | I915_WRITE(DPLL(!crtc->pipe), |
| 1656 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1657 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1658 | |
| 1659 | /* Wait for the clocks to stabilize. */ |
| 1660 | POSTING_READ(reg); |
| 1661 | udelay(150); |
| 1662 | |
| 1663 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1664 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1665 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1666 | } else { |
| 1667 | /* The pixel multiplier can only be updated once the |
| 1668 | * DPLL is enabled and the clocks are stable. |
| 1669 | * |
| 1670 | * So write it again. |
| 1671 | */ |
| 1672 | I915_WRITE(reg, dpll); |
| 1673 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1674 | |
| 1675 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1676 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1677 | POSTING_READ(reg); |
| 1678 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1679 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1680 | POSTING_READ(reg); |
| 1681 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1682 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1683 | POSTING_READ(reg); |
| 1684 | udelay(150); /* wait for warmup */ |
| 1685 | } |
| 1686 | |
| 1687 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1688 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1689 | * @dev_priv: i915 private structure |
| 1690 | * @pipe: pipe PLL to disable |
| 1691 | * |
| 1692 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1693 | * |
| 1694 | * Note! This is for pre-ILK only. |
| 1695 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1696 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1697 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1698 | struct drm_device *dev = crtc->base.dev; |
| 1699 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1700 | enum pipe pipe = crtc->pipe; |
| 1701 | |
| 1702 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1703 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1704 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1705 | !intel_num_dvo_pipes(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1706 | I915_WRITE(DPLL(PIPE_B), |
| 1707 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1708 | I915_WRITE(DPLL(PIPE_A), |
| 1709 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1710 | } |
| 1711 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1712 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1713 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1714 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1715 | return; |
| 1716 | |
| 1717 | /* Make sure the pipe isn't still relying on us */ |
| 1718 | assert_pipe_disabled(dev_priv, pipe); |
| 1719 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1720 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1721 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1722 | } |
| 1723 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1724 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1725 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1726 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1727 | |
| 1728 | /* Make sure the pipe isn't still relying on us */ |
| 1729 | assert_pipe_disabled(dev_priv, pipe); |
| 1730 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1731 | /* |
| 1732 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1733 | * The latter is needed for VGA hotplug / manual detection. |
| 1734 | */ |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1735 | val = DPLL_VGA_MODE_DIS; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1736 | if (pipe == PIPE_B) |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1737 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1738 | I915_WRITE(DPLL(pipe), val); |
| 1739 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1740 | |
| 1741 | } |
| 1742 | |
| 1743 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1744 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1745 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1746 | u32 val; |
| 1747 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1748 | /* Make sure the pipe isn't still relying on us */ |
| 1749 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1750 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1751 | /* Set PLL en = 0 */ |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1752 | val = DPLL_SSC_REF_CLK_CHV | |
| 1753 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1754 | if (pipe != PIPE_A) |
| 1755 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1756 | I915_WRITE(DPLL(pipe), val); |
| 1757 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1758 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1759 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1760 | |
| 1761 | /* Disable 10bit clock to display controller */ |
| 1762 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1763 | val &= ~DPIO_DCLKP_EN; |
| 1764 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1765 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1766 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1769 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1770 | struct intel_digital_port *dport, |
| 1771 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1772 | { |
| 1773 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1774 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1775 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1776 | switch (dport->port) { |
| 1777 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1778 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1779 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1780 | break; |
| 1781 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1782 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1783 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1784 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1785 | break; |
| 1786 | case PORT_D: |
| 1787 | port_mask = DPLL_PORTD_READY_MASK; |
| 1788 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1789 | break; |
| 1790 | default: |
| 1791 | BUG(); |
| 1792 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1793 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1794 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
| 1795 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
| 1796 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1799 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1800 | { |
| 1801 | struct drm_device *dev = crtc->base.dev; |
| 1802 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1803 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1804 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1805 | if (WARN_ON(pll == NULL)) |
| 1806 | return; |
| 1807 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1808 | WARN_ON(!pll->config.crtc_mask); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1809 | if (pll->active == 0) { |
| 1810 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1811 | WARN_ON(pll->on); |
| 1812 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1813 | |
| 1814 | pll->mode_set(dev_priv, pll); |
| 1815 | } |
| 1816 | } |
| 1817 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1818 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1819 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1820 | * @dev_priv: i915 private structure |
| 1821 | * @pipe: pipe PLL to enable |
| 1822 | * |
| 1823 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1824 | * drives the transcoder clock. |
| 1825 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1826 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1827 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1828 | struct drm_device *dev = crtc->base.dev; |
| 1829 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1830 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1831 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1832 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1833 | return; |
| 1834 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1835 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1836 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1837 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1838 | 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] | 1839 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1840 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1841 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1842 | if (pll->active++) { |
| 1843 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1844 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1845 | return; |
| 1846 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1847 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1848 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1849 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1850 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1851 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1852 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1853 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1854 | } |
| 1855 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1856 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1857 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1858 | struct drm_device *dev = crtc->base.dev; |
| 1859 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1860 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1861 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1862 | /* PCH only available on ILK+ */ |
Jesse Barnes | 80aa931 | 2015-08-03 13:09:11 -0700 | [diff] [blame] | 1863 | if (INTEL_INFO(dev)->gen < 5) |
| 1864 | return; |
| 1865 | |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 1866 | if (pll == NULL) |
| 1867 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1868 | |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 1869 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1870 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1871 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1872 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1873 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1874 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1875 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1876 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1877 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1878 | return; |
| 1879 | } |
| 1880 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1881 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1882 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1883 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1884 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1885 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1886 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1887 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1888 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1889 | |
| 1890 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1891 | } |
| 1892 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1893 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1894 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1895 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1896 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1897 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1898 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1899 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1900 | |
| 1901 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1902 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1903 | |
| 1904 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1905 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1906 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1907 | |
| 1908 | /* FDI must be feeding us bits for PCH ports */ |
| 1909 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1910 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1911 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1912 | if (HAS_PCH_CPT(dev)) { |
| 1913 | /* Workaround: Set the timing override bit before enabling the |
| 1914 | * pch transcoder. */ |
| 1915 | reg = TRANS_CHICKEN2(pipe); |
| 1916 | val = I915_READ(reg); |
| 1917 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1918 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1919 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1920 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1921 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1922 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1923 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1924 | |
| 1925 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1926 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1927 | * Make the BPC in transcoder be consistent with |
| 1928 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1929 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1930 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1931 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1932 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
| 1933 | val |= PIPECONF_8BPC; |
| 1934 | else |
| 1935 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1936 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1937 | |
| 1938 | val &= ~TRANS_INTERLACE_MASK; |
| 1939 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1940 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1941 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1942 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1943 | else |
| 1944 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1945 | else |
| 1946 | val |= TRANS_PROGRESSIVE; |
| 1947 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1948 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1949 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1950 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1951 | } |
| 1952 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1953 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1954 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1955 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1956 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1957 | |
| 1958 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1959 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1960 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1961 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1962 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1963 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1964 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1965 | /* Workaround: set timing override bit. */ |
| 1966 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1967 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1968 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 1969 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1970 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1971 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1972 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1973 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1974 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1975 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1976 | else |
| 1977 | val |= TRANS_PROGRESSIVE; |
| 1978 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1979 | I915_WRITE(LPT_TRANSCONF, val); |
| 1980 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1981 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1982 | } |
| 1983 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1984 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1985 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1986 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1987 | struct drm_device *dev = dev_priv->dev; |
| 1988 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1989 | |
| 1990 | /* FDI relies on the transcoder */ |
| 1991 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1992 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1993 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1994 | /* Ports must be off as well */ |
| 1995 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1996 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1997 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1998 | val = I915_READ(reg); |
| 1999 | val &= ~TRANS_ENABLE; |
| 2000 | I915_WRITE(reg, val); |
| 2001 | /* wait for PCH transcoder off, transcoder state */ |
| 2002 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2003 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2004 | |
| 2005 | if (!HAS_PCH_IBX(dev)) { |
| 2006 | /* Workaround: Clear the timing override chicken bit again. */ |
| 2007 | reg = TRANS_CHICKEN2(pipe); |
| 2008 | val = I915_READ(reg); |
| 2009 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 2010 | I915_WRITE(reg, val); |
| 2011 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2012 | } |
| 2013 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 2014 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2015 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2016 | u32 val; |
| 2017 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2018 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2019 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2020 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2021 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2022 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 2023 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2024 | |
| 2025 | /* Workaround: clear timing override bit. */ |
| 2026 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2027 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2028 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2032 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2033 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2034 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2035 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2036 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2037 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 2038 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2039 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2040 | struct drm_device *dev = crtc->base.dev; |
| 2041 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2042 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2043 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 2044 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2045 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2046 | int reg; |
| 2047 | u32 val; |
| 2048 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2049 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 2050 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2051 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2052 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2053 | assert_sprites_disabled(dev_priv, pipe); |
| 2054 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2055 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2056 | pch_transcoder = TRANSCODER_A; |
| 2057 | else |
| 2058 | pch_transcoder = pipe; |
| 2059 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2060 | /* |
| 2061 | * A pipe without a PLL won't actually be able to drive bits from |
| 2062 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2063 | * need the check. |
| 2064 | */ |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 2065 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2066 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2067 | assert_dsi_pll_enabled(dev_priv); |
| 2068 | else |
| 2069 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2070 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2071 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2072 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2073 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2074 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2075 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2076 | } |
| 2077 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2078 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2079 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2080 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2081 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2082 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2083 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2084 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2085 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2086 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2087 | |
| 2088 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2089 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2093 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2094 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2095 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2096 | * Disable the pipe of @crtc, making sure that various hardware |
| 2097 | * specific requirements are met, if applicable, e.g. plane |
| 2098 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2099 | * |
| 2100 | * Will wait until the pipe has shut down before returning. |
| 2101 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2102 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2103 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2104 | 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] | 2105 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2106 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2107 | int reg; |
| 2108 | u32 val; |
| 2109 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2110 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 2111 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2112 | /* |
| 2113 | * Make sure planes won't keep trying to pump pixels to us, |
| 2114 | * or we might hang the display. |
| 2115 | */ |
| 2116 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2117 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2118 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2119 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2120 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2121 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2122 | if ((val & PIPECONF_ENABLE) == 0) |
| 2123 | return; |
| 2124 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2125 | /* |
| 2126 | * Double wide has implications for planes |
| 2127 | * so best keep it disabled when not needed. |
| 2128 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2129 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2130 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2131 | |
| 2132 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2133 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2134 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2135 | val &= ~PIPECONF_ENABLE; |
| 2136 | |
| 2137 | I915_WRITE(reg, val); |
| 2138 | if ((val & PIPECONF_ENABLE) == 0) |
| 2139 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2142 | static bool need_vtd_wa(struct drm_device *dev) |
| 2143 | { |
| 2144 | #ifdef CONFIG_INTEL_IOMMU |
| 2145 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2146 | return true; |
| 2147 | #endif |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2151 | unsigned int |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2152 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
| 2153 | uint64_t fb_format_modifier) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2154 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2155 | unsigned int tile_height; |
| 2156 | uint32_t pixel_bytes; |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2157 | |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2158 | switch (fb_format_modifier) { |
| 2159 | case DRM_FORMAT_MOD_NONE: |
| 2160 | tile_height = 1; |
| 2161 | break; |
| 2162 | case I915_FORMAT_MOD_X_TILED: |
| 2163 | tile_height = IS_GEN2(dev) ? 16 : 8; |
| 2164 | break; |
| 2165 | case I915_FORMAT_MOD_Y_TILED: |
| 2166 | tile_height = 32; |
| 2167 | break; |
| 2168 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2169 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
| 2170 | switch (pixel_bytes) { |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2171 | default: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2172 | case 1: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2173 | tile_height = 64; |
| 2174 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2175 | case 2: |
| 2176 | case 4: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2177 | tile_height = 32; |
| 2178 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2179 | case 8: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2180 | tile_height = 16; |
| 2181 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2182 | case 16: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2183 | WARN_ONCE(1, |
| 2184 | "128-bit pixels are not supported for display!"); |
| 2185 | tile_height = 16; |
| 2186 | break; |
| 2187 | } |
| 2188 | break; |
| 2189 | default: |
| 2190 | MISSING_CASE(fb_format_modifier); |
| 2191 | tile_height = 1; |
| 2192 | break; |
| 2193 | } |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 2194 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2195 | return tile_height; |
| 2196 | } |
| 2197 | |
| 2198 | unsigned int |
| 2199 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
| 2200 | uint32_t pixel_format, uint64_t fb_format_modifier) |
| 2201 | { |
| 2202 | return ALIGN(height, intel_tile_height(dev, pixel_format, |
| 2203 | fb_format_modifier)); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2206 | static int |
| 2207 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, |
| 2208 | const struct drm_plane_state *plane_state) |
| 2209 | { |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2210 | struct intel_rotation_info *info = &view->rotation_info; |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 2211 | unsigned int tile_height, tile_pitch; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2212 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2213 | *view = i915_ggtt_view_normal; |
| 2214 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2215 | if (!plane_state) |
| 2216 | return 0; |
| 2217 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2218 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2219 | return 0; |
| 2220 | |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2221 | *view = i915_ggtt_view_rotated; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2222 | |
| 2223 | info->height = fb->height; |
| 2224 | info->pixel_format = fb->pixel_format; |
| 2225 | info->pitch = fb->pitches[0]; |
| 2226 | info->fb_modifier = fb->modifier[0]; |
| 2227 | |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 2228 | tile_height = intel_tile_height(fb->dev, fb->pixel_format, |
| 2229 | fb->modifier[0]); |
| 2230 | tile_pitch = PAGE_SIZE / tile_height; |
| 2231 | info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch); |
| 2232 | info->height_pages = DIV_ROUND_UP(fb->height, tile_height); |
| 2233 | info->size = info->width_pages * info->height_pages * PAGE_SIZE; |
| 2234 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2235 | return 0; |
| 2236 | } |
| 2237 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2238 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
| 2239 | { |
| 2240 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2241 | return 256 * 1024; |
Ville Syrjälä | 985b8bb | 2015-06-11 16:31:15 +0300 | [diff] [blame] | 2242 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
| 2243 | IS_VALLEYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2244 | return 128 * 1024; |
| 2245 | else if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2246 | return 4 * 1024; |
| 2247 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2248 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2249 | } |
| 2250 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2251 | int |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2252 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
| 2253 | struct drm_framebuffer *fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2254 | const struct drm_plane_state *plane_state, |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 2255 | struct intel_engine_cs *pipelined, |
| 2256 | struct drm_i915_gem_request **pipelined_request) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2257 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2258 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2259 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2260 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2261 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2262 | u32 alignment; |
| 2263 | int ret; |
| 2264 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2265 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2266 | |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2267 | switch (fb->modifier[0]) { |
| 2268 | case DRM_FORMAT_MOD_NONE: |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2269 | alignment = intel_linear_alignment(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2270 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2271 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2272 | if (INTEL_INFO(dev)->gen >= 9) |
| 2273 | alignment = 256 * 1024; |
| 2274 | else { |
| 2275 | /* pin() will align the object as required by fence */ |
| 2276 | alignment = 0; |
| 2277 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2278 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2279 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | 1327b9a | 2015-02-27 11:15:20 +0000 | [diff] [blame] | 2280 | case I915_FORMAT_MOD_Yf_TILED: |
| 2281 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, |
| 2282 | "Y tiling bo slipped through, driver bug!\n")) |
| 2283 | return -EINVAL; |
| 2284 | alignment = 1 * 1024 * 1024; |
| 2285 | break; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2286 | default: |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2287 | MISSING_CASE(fb->modifier[0]); |
| 2288 | return -EINVAL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2289 | } |
| 2290 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2291 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2292 | if (ret) |
| 2293 | return ret; |
| 2294 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2295 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2296 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2297 | * we should always have valid PTE following the scanout preventing |
| 2298 | * the VT-d warning. |
| 2299 | */ |
| 2300 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2301 | alignment = 256 * 1024; |
| 2302 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2303 | /* |
| 2304 | * Global gtt pte registers are special registers which actually forward |
| 2305 | * writes to a chunk of system memory. Which means that there is no risk |
| 2306 | * that the register values disappear as soon as we call |
| 2307 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2308 | * pin/unpin/fence and not more. |
| 2309 | */ |
| 2310 | intel_runtime_pm_get(dev_priv); |
| 2311 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2312 | dev_priv->mm.interruptible = false; |
Tvrtko Ursulin | e661733 | 2015-03-23 11:10:33 +0000 | [diff] [blame] | 2313 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 2314 | pipelined_request, &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2315 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2316 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2317 | |
| 2318 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2319 | * fence, whereas 965+ only requires a fence if using |
| 2320 | * framebuffer compression. For simplicity, we always install |
| 2321 | * a fence as the cost is not that onerous. |
| 2322 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2323 | ret = i915_gem_object_get_fence(obj); |
Maarten Lankhorst | 842315e | 2015-08-05 12:37:11 +0200 | [diff] [blame] | 2324 | if (ret == -EDEADLK) { |
| 2325 | /* |
| 2326 | * -EDEADLK means there are no free fences |
| 2327 | * no pending flips. |
| 2328 | * |
| 2329 | * This is propagated to atomic, but it uses |
| 2330 | * -EDEADLK to force a locking recovery, so |
| 2331 | * change the returned error to -EBUSY. |
| 2332 | */ |
| 2333 | ret = -EBUSY; |
| 2334 | goto err_unpin; |
| 2335 | } else if (ret) |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2336 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2337 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2338 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2339 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2340 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2341 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2342 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2343 | |
| 2344 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2345 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2346 | err_interruptible: |
| 2347 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2348 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2349 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2350 | } |
| 2351 | |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2352 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
| 2353 | const struct drm_plane_state *plane_state) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2354 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2355 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2356 | struct i915_ggtt_view view; |
| 2357 | int ret; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2358 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2359 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2360 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2361 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2362 | WARN_ONCE(ret, "Couldn't get view from plane state!"); |
| 2363 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2364 | i915_gem_object_unpin_fence(obj); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2365 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2368 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2369 | * is assumed to be a power-of-two. */ |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2370 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
| 2371 | int *x, int *y, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2372 | unsigned int tiling_mode, |
| 2373 | unsigned int cpp, |
| 2374 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2375 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2376 | if (tiling_mode != I915_TILING_NONE) { |
| 2377 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2378 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2379 | tile_rows = *y / 8; |
| 2380 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2381 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2382 | tiles = *x / (512/cpp); |
| 2383 | *x %= 512/cpp; |
| 2384 | |
| 2385 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2386 | } else { |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2387 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2388 | unsigned int offset; |
| 2389 | |
| 2390 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2391 | *y = (offset & alignment) / pitch; |
| 2392 | *x = ((offset & alignment) - *y * pitch) / cpp; |
| 2393 | return offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2394 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2395 | } |
| 2396 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2397 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2398 | { |
| 2399 | switch (format) { |
| 2400 | case DISPPLANE_8BPP: |
| 2401 | return DRM_FORMAT_C8; |
| 2402 | case DISPPLANE_BGRX555: |
| 2403 | return DRM_FORMAT_XRGB1555; |
| 2404 | case DISPPLANE_BGRX565: |
| 2405 | return DRM_FORMAT_RGB565; |
| 2406 | default: |
| 2407 | case DISPPLANE_BGRX888: |
| 2408 | return DRM_FORMAT_XRGB8888; |
| 2409 | case DISPPLANE_RGBX888: |
| 2410 | return DRM_FORMAT_XBGR8888; |
| 2411 | case DISPPLANE_BGRX101010: |
| 2412 | return DRM_FORMAT_XRGB2101010; |
| 2413 | case DISPPLANE_RGBX101010: |
| 2414 | return DRM_FORMAT_XBGR2101010; |
| 2415 | } |
| 2416 | } |
| 2417 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2418 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2419 | { |
| 2420 | switch (format) { |
| 2421 | case PLANE_CTL_FORMAT_RGB_565: |
| 2422 | return DRM_FORMAT_RGB565; |
| 2423 | default: |
| 2424 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2425 | if (rgb_order) { |
| 2426 | if (alpha) |
| 2427 | return DRM_FORMAT_ABGR8888; |
| 2428 | else |
| 2429 | return DRM_FORMAT_XBGR8888; |
| 2430 | } else { |
| 2431 | if (alpha) |
| 2432 | return DRM_FORMAT_ARGB8888; |
| 2433 | else |
| 2434 | return DRM_FORMAT_XRGB8888; |
| 2435 | } |
| 2436 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2437 | if (rgb_order) |
| 2438 | return DRM_FORMAT_XBGR2101010; |
| 2439 | else |
| 2440 | return DRM_FORMAT_XRGB2101010; |
| 2441 | } |
| 2442 | } |
| 2443 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2444 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2445 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2446 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2447 | { |
| 2448 | struct drm_device *dev = crtc->base.dev; |
| 2449 | struct drm_i915_gem_object *obj = NULL; |
| 2450 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2451 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2452 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2453 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2454 | PAGE_SIZE); |
| 2455 | |
| 2456 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2457 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2458 | if (plane_config->size == 0) |
| 2459 | return false; |
| 2460 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2461 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2462 | base_aligned, |
| 2463 | base_aligned, |
| 2464 | size_aligned); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2465 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2466 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2467 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2468 | obj->tiling_mode = plane_config->tiling; |
| 2469 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2470 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2471 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2472 | mode_cmd.pixel_format = fb->pixel_format; |
| 2473 | mode_cmd.width = fb->width; |
| 2474 | mode_cmd.height = fb->height; |
| 2475 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2476 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2477 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2478 | |
| 2479 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2480 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2481 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2482 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2483 | goto out_unref_obj; |
| 2484 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2485 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2486 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2487 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2488 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2489 | |
| 2490 | out_unref_obj: |
| 2491 | drm_gem_object_unreference(&obj->base); |
| 2492 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2493 | return false; |
| 2494 | } |
| 2495 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2496 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2497 | static void |
| 2498 | update_state_fb(struct drm_plane *plane) |
| 2499 | { |
| 2500 | if (plane->fb == plane->state->fb) |
| 2501 | return; |
| 2502 | |
| 2503 | if (plane->state->fb) |
| 2504 | drm_framebuffer_unreference(plane->state->fb); |
| 2505 | plane->state->fb = plane->fb; |
| 2506 | if (plane->state->fb) |
| 2507 | drm_framebuffer_reference(plane->state->fb); |
| 2508 | } |
| 2509 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2510 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2511 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2512 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2513 | { |
| 2514 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2515 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2516 | struct drm_crtc *c; |
| 2517 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2518 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2519 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2520 | struct drm_plane_state *plane_state = primary->state; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2521 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2522 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2523 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2524 | return; |
| 2525 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2526 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2527 | fb = &plane_config->fb->base; |
| 2528 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2529 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2530 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2531 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2532 | |
| 2533 | /* |
| 2534 | * Failed to alloc the obj, check to see if we should share |
| 2535 | * an fb with another CRTC instead |
| 2536 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2537 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2538 | i = to_intel_crtc(c); |
| 2539 | |
| 2540 | if (c == &intel_crtc->base) |
| 2541 | continue; |
| 2542 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2543 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2544 | continue; |
| 2545 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2546 | fb = c->primary->fb; |
| 2547 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2548 | continue; |
| 2549 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2550 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2551 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2552 | drm_framebuffer_reference(fb); |
| 2553 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2554 | } |
| 2555 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2556 | |
| 2557 | return; |
| 2558 | |
| 2559 | valid_fb: |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2560 | plane_state->src_x = plane_state->src_y = 0; |
| 2561 | plane_state->src_w = fb->width << 16; |
| 2562 | plane_state->src_h = fb->height << 16; |
| 2563 | |
| 2564 | plane_state->crtc_x = plane_state->src_y = 0; |
| 2565 | plane_state->crtc_w = fb->width; |
| 2566 | plane_state->crtc_h = fb->height; |
| 2567 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2568 | obj = intel_fb_obj(fb); |
| 2569 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2570 | dev_priv->preserve_bios_swizzle = true; |
| 2571 | |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2572 | drm_framebuffer_reference(fb); |
| 2573 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2574 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2575 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 2576 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2577 | } |
| 2578 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2579 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2580 | struct drm_framebuffer *fb, |
| 2581 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2582 | { |
| 2583 | struct drm_device *dev = crtc->dev; |
| 2584 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2585 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2586 | struct drm_plane *primary = crtc->primary; |
| 2587 | bool visible = to_intel_plane_state(primary->state)->visible; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2588 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2589 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2590 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2591 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2592 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2593 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2594 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2595 | if (!visible || !fb) { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2596 | I915_WRITE(reg, 0); |
| 2597 | if (INTEL_INFO(dev)->gen >= 4) |
| 2598 | I915_WRITE(DSPSURF(plane), 0); |
| 2599 | else |
| 2600 | I915_WRITE(DSPADDR(plane), 0); |
| 2601 | POSTING_READ(reg); |
| 2602 | return; |
| 2603 | } |
| 2604 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2605 | obj = intel_fb_obj(fb); |
| 2606 | if (WARN_ON(obj == NULL)) |
| 2607 | return; |
| 2608 | |
| 2609 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2610 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2611 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2612 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2613 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2614 | |
| 2615 | if (INTEL_INFO(dev)->gen < 4) { |
| 2616 | if (intel_crtc->pipe == PIPE_B) |
| 2617 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2618 | |
| 2619 | /* pipesrc and dspsize control the size that is scaled from, |
| 2620 | * which should always be the user's requested size. |
| 2621 | */ |
| 2622 | I915_WRITE(DSPSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2623 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2624 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2625 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2626 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2627 | I915_WRITE(PRIMSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2628 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2629 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2630 | I915_WRITE(PRIMPOS(plane), 0); |
| 2631 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2632 | } |
| 2633 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2634 | switch (fb->pixel_format) { |
| 2635 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2636 | dspcntr |= DISPPLANE_8BPP; |
| 2637 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2638 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2639 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2640 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2641 | case DRM_FORMAT_RGB565: |
| 2642 | dspcntr |= DISPPLANE_BGRX565; |
| 2643 | break; |
| 2644 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2645 | dspcntr |= DISPPLANE_BGRX888; |
| 2646 | break; |
| 2647 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2648 | dspcntr |= DISPPLANE_RGBX888; |
| 2649 | break; |
| 2650 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2651 | dspcntr |= DISPPLANE_BGRX101010; |
| 2652 | break; |
| 2653 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2654 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2655 | break; |
| 2656 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2657 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2658 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2659 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2660 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2661 | obj->tiling_mode != I915_TILING_NONE) |
| 2662 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2663 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2664 | if (IS_G4X(dev)) |
| 2665 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2666 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2667 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2668 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2669 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2670 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2671 | intel_gen4_compute_page_offset(dev_priv, |
| 2672 | &x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2673 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2674 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2675 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2676 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2677 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2678 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2679 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2680 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2681 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2682 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2683 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2684 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2685 | |
| 2686 | /* Finding the last pixel of the last line of the display |
| 2687 | data and adding to linear_offset*/ |
| 2688 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2689 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2690 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | I915_WRITE(reg, dspcntr); |
| 2694 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2695 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2696 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2697 | I915_WRITE(DSPSURF(plane), |
| 2698 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2699 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2700 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2701 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2702 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2703 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2706 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2707 | struct drm_framebuffer *fb, |
| 2708 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2709 | { |
| 2710 | struct drm_device *dev = crtc->dev; |
| 2711 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2712 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2713 | struct drm_plane *primary = crtc->primary; |
| 2714 | bool visible = to_intel_plane_state(primary->state)->visible; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2715 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2716 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2717 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2718 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2719 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2720 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2721 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2722 | if (!visible || !fb) { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2723 | I915_WRITE(reg, 0); |
| 2724 | I915_WRITE(DSPSURF(plane), 0); |
| 2725 | POSTING_READ(reg); |
| 2726 | return; |
| 2727 | } |
| 2728 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2729 | obj = intel_fb_obj(fb); |
| 2730 | if (WARN_ON(obj == NULL)) |
| 2731 | return; |
| 2732 | |
| 2733 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2734 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2735 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2736 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2737 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2738 | |
| 2739 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2740 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2741 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2742 | switch (fb->pixel_format) { |
| 2743 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2744 | dspcntr |= DISPPLANE_8BPP; |
| 2745 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2746 | case DRM_FORMAT_RGB565: |
| 2747 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2748 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2749 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2750 | dspcntr |= DISPPLANE_BGRX888; |
| 2751 | break; |
| 2752 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2753 | dspcntr |= DISPPLANE_RGBX888; |
| 2754 | break; |
| 2755 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2756 | dspcntr |= DISPPLANE_BGRX101010; |
| 2757 | break; |
| 2758 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2759 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2760 | break; |
| 2761 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2762 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2766 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2767 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2768 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2769 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2770 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2771 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2772 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2773 | intel_gen4_compute_page_offset(dev_priv, |
| 2774 | &x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2775 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2776 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2777 | linear_offset -= intel_crtc->dspaddr_offset; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2778 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2779 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2780 | |
| 2781 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2782 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2783 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2784 | |
| 2785 | /* Finding the last pixel of the last line of the display |
| 2786 | data and adding to linear_offset*/ |
| 2787 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2788 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2789 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2790 | } |
| 2791 | } |
| 2792 | |
| 2793 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2794 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2795 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2796 | I915_WRITE(DSPSURF(plane), |
| 2797 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2798 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2799 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2800 | } else { |
| 2801 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2802 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2803 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2804 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2807 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
| 2808 | uint32_t pixel_format) |
| 2809 | { |
| 2810 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; |
| 2811 | |
| 2812 | /* |
| 2813 | * The stride is either expressed as a multiple of 64 bytes |
| 2814 | * chunks for linear buffers or in number of tiles for tiled |
| 2815 | * buffers. |
| 2816 | */ |
| 2817 | switch (fb_modifier) { |
| 2818 | case DRM_FORMAT_MOD_NONE: |
| 2819 | return 64; |
| 2820 | case I915_FORMAT_MOD_X_TILED: |
| 2821 | if (INTEL_INFO(dev)->gen == 2) |
| 2822 | return 128; |
| 2823 | return 512; |
| 2824 | case I915_FORMAT_MOD_Y_TILED: |
| 2825 | /* No need to check for old gens and Y tiling since this is |
| 2826 | * about the display engine and those will be blocked before |
| 2827 | * we get here. |
| 2828 | */ |
| 2829 | return 128; |
| 2830 | case I915_FORMAT_MOD_Yf_TILED: |
| 2831 | if (bits_per_pixel == 8) |
| 2832 | return 64; |
| 2833 | else |
| 2834 | return 128; |
| 2835 | default: |
| 2836 | MISSING_CASE(fb_modifier); |
| 2837 | return 64; |
| 2838 | } |
| 2839 | } |
| 2840 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2841 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2842 | struct drm_i915_gem_object *obj) |
| 2843 | { |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2844 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2845 | |
| 2846 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2847 | view = &i915_ggtt_view_rotated; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2848 | |
| 2849 | return i915_gem_obj_ggtt_offset_view(obj, view); |
| 2850 | } |
| 2851 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2852 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 2853 | { |
| 2854 | struct drm_device *dev = intel_crtc->base.dev; |
| 2855 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2856 | |
| 2857 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 2858 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 2859 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2860 | } |
| 2861 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2862 | /* |
| 2863 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 2864 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 2865 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2866 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2867 | struct intel_crtc_scaler_state *scaler_state; |
| 2868 | int i; |
| 2869 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2870 | scaler_state = &intel_crtc->config->scaler_state; |
| 2871 | |
| 2872 | /* loop through and disable scalers that aren't in use */ |
| 2873 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2874 | if (!scaler_state->scalers[i].in_use) |
| 2875 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2876 | } |
| 2877 | } |
| 2878 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2879 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 2880 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2881 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 2882 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2883 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2884 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2885 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2886 | case DRM_FORMAT_XBGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2887 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2888 | case DRM_FORMAT_XRGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2889 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2890 | /* |
| 2891 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 2892 | * to be already pre-multiplied. We need to add a knob (or a different |
| 2893 | * DRM_FORMAT) for user-space to configure that. |
| 2894 | */ |
| 2895 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2896 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2897 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2898 | case DRM_FORMAT_ARGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2899 | return PLANE_CTL_FORMAT_XRGB_8888 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2900 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2901 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2902 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2903 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2904 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2905 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2906 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2907 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2908 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2909 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2910 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2911 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2912 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2913 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 2914 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2915 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2916 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2917 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 2921 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2922 | switch (fb_modifier) { |
| 2923 | case DRM_FORMAT_MOD_NONE: |
| 2924 | break; |
| 2925 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2926 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2927 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2928 | return PLANE_CTL_TILED_Y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2929 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2930 | return PLANE_CTL_TILED_YF; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2931 | default: |
| 2932 | MISSING_CASE(fb_modifier); |
| 2933 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2934 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2935 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 2939 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2940 | switch (rotation) { |
| 2941 | case BIT(DRM_ROTATE_0): |
| 2942 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2943 | /* |
| 2944 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 2945 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 2946 | */ |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2947 | case BIT(DRM_ROTATE_90): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2948 | return PLANE_CTL_ROTATE_270; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2949 | case BIT(DRM_ROTATE_180): |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2950 | return PLANE_CTL_ROTATE_180; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2951 | case BIT(DRM_ROTATE_270): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2952 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2953 | default: |
| 2954 | MISSING_CASE(rotation); |
| 2955 | } |
| 2956 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2957 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2960 | static void skylake_update_primary_plane(struct drm_crtc *crtc, |
| 2961 | struct drm_framebuffer *fb, |
| 2962 | int x, int y) |
| 2963 | { |
| 2964 | struct drm_device *dev = crtc->dev; |
| 2965 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2966 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2967 | struct drm_plane *plane = crtc->primary; |
| 2968 | bool visible = to_intel_plane_state(plane->state)->visible; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2969 | struct drm_i915_gem_object *obj; |
| 2970 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 2971 | u32 plane_ctl, stride_div, stride; |
| 2972 | u32 tile_height, plane_offset, plane_size; |
| 2973 | unsigned int rotation; |
| 2974 | int x_offset, y_offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2975 | unsigned long surf_addr; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2976 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
| 2977 | struct intel_plane_state *plane_state; |
| 2978 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; |
| 2979 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; |
| 2980 | int scaler_id = -1; |
| 2981 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2982 | plane_state = to_intel_plane_state(plane->state); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2983 | |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 2984 | if (!visible || !fb) { |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2985 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 2986 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 2987 | POSTING_READ(PLANE_CTL(pipe, 0)); |
| 2988 | return; |
| 2989 | } |
| 2990 | |
| 2991 | plane_ctl = PLANE_CTL_ENABLE | |
| 2992 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 2993 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 2994 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2995 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
| 2996 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2997 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 2998 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 2999 | rotation = plane->state->rotation; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3000 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3001 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3002 | obj = intel_fb_obj(fb); |
| 3003 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 3004 | fb->pixel_format); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3005 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
| 3006 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3007 | /* |
| 3008 | * FIXME: intel_plane_state->src, dst aren't set when transitional |
| 3009 | * update_plane helpers are called from legacy paths. |
| 3010 | * Once full atomic crtc is available, below check can be avoided. |
| 3011 | */ |
| 3012 | if (drm_rect_width(&plane_state->src)) { |
| 3013 | scaler_id = plane_state->scaler_id; |
| 3014 | src_x = plane_state->src.x1 >> 16; |
| 3015 | src_y = plane_state->src.y1 >> 16; |
| 3016 | src_w = drm_rect_width(&plane_state->src) >> 16; |
| 3017 | src_h = drm_rect_height(&plane_state->src) >> 16; |
| 3018 | dst_x = plane_state->dst.x1; |
| 3019 | dst_y = plane_state->dst.y1; |
| 3020 | dst_w = drm_rect_width(&plane_state->dst); |
| 3021 | dst_h = drm_rect_height(&plane_state->dst); |
| 3022 | |
| 3023 | WARN_ON(x != src_x || y != src_y); |
| 3024 | } else { |
| 3025 | src_w = intel_crtc->config->pipe_src_w; |
| 3026 | src_h = intel_crtc->config->pipe_src_h; |
| 3027 | } |
| 3028 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3029 | if (intel_rotation_90_or_270(rotation)) { |
| 3030 | /* stride = Surface height in tiles */ |
Chandra Konduru | 2614f17 | 2015-05-08 20:22:46 -0700 | [diff] [blame] | 3031 | tile_height = intel_tile_height(dev, fb->pixel_format, |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3032 | fb->modifier[0]); |
| 3033 | stride = DIV_ROUND_UP(fb->height, tile_height); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3034 | x_offset = stride * tile_height - y - src_h; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3035 | y_offset = x; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3036 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3037 | } else { |
| 3038 | stride = fb->pitches[0] / stride_div; |
| 3039 | x_offset = x; |
| 3040 | y_offset = y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3041 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3042 | } |
| 3043 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3044 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3045 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3046 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3047 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3048 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3049 | |
| 3050 | if (scaler_id >= 0) { |
| 3051 | uint32_t ps_ctrl = 0; |
| 3052 | |
| 3053 | WARN_ON(!dst_w || !dst_h); |
| 3054 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | |
| 3055 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3056 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3057 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3058 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3059 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
| 3060 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3061 | } else { |
| 3062 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); |
| 3063 | } |
| 3064 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3065 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3066 | |
| 3067 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3068 | } |
| 3069 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3070 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3071 | static int |
| 3072 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3073 | int x, int y, enum mode_set_atomic state) |
| 3074 | { |
| 3075 | struct drm_device *dev = crtc->dev; |
| 3076 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3077 | |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 3078 | if (dev_priv->fbc.disable_fbc) |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 3079 | dev_priv->fbc.disable_fbc(dev_priv); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3080 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 3081 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 3082 | |
| 3083 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3086 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3087 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3088 | struct drm_crtc *crtc; |
| 3089 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3090 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3091 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3092 | enum plane plane = intel_crtc->plane; |
| 3093 | |
| 3094 | intel_prepare_page_flip(dev, plane); |
| 3095 | intel_finish_page_flip_plane(dev, plane); |
| 3096 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3100 | { |
| 3101 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3102 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3103 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3104 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3105 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3106 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3107 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3108 | /* |
| 3109 | * FIXME: Once we have proper support for primary planes (and |
| 3110 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3111 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3112 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 3113 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3114 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3115 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3116 | crtc->x, |
| 3117 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3118 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3119 | } |
| 3120 | } |
| 3121 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3122 | void intel_prepare_reset(struct drm_device *dev) |
| 3123 | { |
| 3124 | /* no reset support for gen2 */ |
| 3125 | if (IS_GEN2(dev)) |
| 3126 | return; |
| 3127 | |
| 3128 | /* reset doesn't touch the display */ |
| 3129 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3130 | return; |
| 3131 | |
| 3132 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3133 | /* |
| 3134 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3135 | * g33 docs say we should at least disable all the planes. |
| 3136 | */ |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 3137 | intel_display_suspend(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | void intel_finish_reset(struct drm_device *dev) |
| 3141 | { |
| 3142 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3143 | |
| 3144 | /* |
| 3145 | * Flips in the rings will be nuked by the reset, |
| 3146 | * so complete all pending flips so that user space |
| 3147 | * will get its events and not get stuck. |
| 3148 | */ |
| 3149 | intel_complete_page_flips(dev); |
| 3150 | |
| 3151 | /* no reset support for gen2 */ |
| 3152 | if (IS_GEN2(dev)) |
| 3153 | return; |
| 3154 | |
| 3155 | /* reset doesn't touch the display */ |
| 3156 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3157 | /* |
| 3158 | * Flips in the rings have been nuked by the reset, |
| 3159 | * so update the base address of all primary |
| 3160 | * planes to the the last fb to make sure we're |
| 3161 | * showing the correct fb after a reset. |
| 3162 | */ |
| 3163 | intel_update_primary_planes(dev); |
| 3164 | return; |
| 3165 | } |
| 3166 | |
| 3167 | /* |
| 3168 | * The display has been reset as well, |
| 3169 | * so need a full re-initialization. |
| 3170 | */ |
| 3171 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3172 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3173 | |
| 3174 | intel_modeset_init_hw(dev); |
| 3175 | |
| 3176 | spin_lock_irq(&dev_priv->irq_lock); |
| 3177 | if (dev_priv->display.hpd_irq_setup) |
| 3178 | dev_priv->display.hpd_irq_setup(dev); |
| 3179 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3180 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 3181 | intel_display_resume(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3182 | |
| 3183 | intel_hpd_init(dev_priv); |
| 3184 | |
| 3185 | drm_modeset_unlock_all(dev); |
| 3186 | } |
| 3187 | |
Chris Wilson | 2e2f351 | 2015-04-27 13:41:14 +0100 | [diff] [blame] | 3188 | static void |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3189 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 3190 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 3191 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 2e2f351 | 2015-04-27 13:41:14 +0100 | [diff] [blame] | 3192 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3193 | bool was_interruptible = dev_priv->mm.interruptible; |
| 3194 | int ret; |
| 3195 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3196 | /* Big Hammer, we also need to ensure that any pending |
| 3197 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 3198 | * current scanout is retired before unpinning the old |
Chris Wilson | 2e2f351 | 2015-04-27 13:41:14 +0100 | [diff] [blame] | 3199 | * framebuffer. Note that we rely on userspace rendering |
| 3200 | * into the buffer attached to the pipe they are waiting |
| 3201 | * on. If not, userspace generates a GPU hang with IPEHR |
| 3202 | * point to the MI_WAIT_FOR_EVENT. |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3203 | * |
| 3204 | * This should only fail upon a hung GPU, in which case we |
| 3205 | * can safely continue. |
| 3206 | */ |
| 3207 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2e2f351 | 2015-04-27 13:41:14 +0100 | [diff] [blame] | 3208 | ret = i915_gem_object_wait_rendering(obj, true); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3209 | dev_priv->mm.interruptible = was_interruptible; |
| 3210 | |
Chris Wilson | 2e2f351 | 2015-04-27 13:41:14 +0100 | [diff] [blame] | 3211 | WARN_ON(ret); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3212 | } |
| 3213 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3214 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3215 | { |
| 3216 | struct drm_device *dev = crtc->dev; |
| 3217 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3218 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3219 | bool pending; |
| 3220 | |
| 3221 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3222 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3223 | return false; |
| 3224 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3225 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3226 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3227 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3228 | |
| 3229 | return pending; |
| 3230 | } |
| 3231 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3232 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 3233 | { |
| 3234 | struct drm_device *dev = crtc->base.dev; |
| 3235 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3236 | const struct drm_display_mode *adjusted_mode; |
| 3237 | |
| 3238 | if (!i915.fastboot) |
| 3239 | return; |
| 3240 | |
| 3241 | /* |
| 3242 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3243 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3244 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3245 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3246 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3247 | * sized surface. |
| 3248 | * |
| 3249 | * To fix this properly, we need to hoist the checks up into |
| 3250 | * compute_mode_changes (or above), check the actual pfit state and |
| 3251 | * whether the platform allows pfit disable with pipe active, and only |
| 3252 | * then update the pipesrc and pfit state, even on the flip path. |
| 3253 | */ |
| 3254 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3255 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3256 | |
| 3257 | I915_WRITE(PIPESRC(crtc->pipe), |
| 3258 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 3259 | (adjusted_mode->crtc_vdisplay - 1)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3260 | if (!crtc->config->pch_pfit.enabled && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 3261 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3262 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3263 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 3264 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 3265 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 3266 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3267 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 3268 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3269 | } |
| 3270 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3271 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3272 | { |
| 3273 | struct drm_device *dev = crtc->dev; |
| 3274 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3275 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3276 | int pipe = intel_crtc->pipe; |
| 3277 | u32 reg, temp; |
| 3278 | |
| 3279 | /* enable normal train */ |
| 3280 | reg = FDI_TX_CTL(pipe); |
| 3281 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3282 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3283 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3284 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3285 | } else { |
| 3286 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3287 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3288 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3289 | I915_WRITE(reg, temp); |
| 3290 | |
| 3291 | reg = FDI_RX_CTL(pipe); |
| 3292 | temp = I915_READ(reg); |
| 3293 | if (HAS_PCH_CPT(dev)) { |
| 3294 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3295 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3296 | } else { |
| 3297 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3298 | temp |= FDI_LINK_TRAIN_NONE; |
| 3299 | } |
| 3300 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3301 | |
| 3302 | /* wait one idle pattern time */ |
| 3303 | POSTING_READ(reg); |
| 3304 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3305 | |
| 3306 | /* IVB wants error correction enabled */ |
| 3307 | if (IS_IVYBRIDGE(dev)) |
| 3308 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3309 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3310 | } |
| 3311 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3312 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3313 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3314 | { |
| 3315 | struct drm_device *dev = crtc->dev; |
| 3316 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3317 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3318 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3319 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3320 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3321 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3322 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3323 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3324 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3325 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3326 | reg = FDI_RX_IMR(pipe); |
| 3327 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3328 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3329 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3330 | I915_WRITE(reg, temp); |
| 3331 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3332 | udelay(150); |
| 3333 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3334 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3335 | reg = FDI_TX_CTL(pipe); |
| 3336 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3337 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3338 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3339 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3340 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3341 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3342 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3343 | reg = FDI_RX_CTL(pipe); |
| 3344 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3345 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3346 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3347 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3348 | |
| 3349 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3350 | udelay(150); |
| 3351 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3352 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3353 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3354 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3355 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3356 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3357 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3358 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3359 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3360 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3361 | |
| 3362 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3363 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3364 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3365 | break; |
| 3366 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3367 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3368 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3369 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3370 | |
| 3371 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3372 | reg = FDI_TX_CTL(pipe); |
| 3373 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3374 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3375 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3376 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3377 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3378 | reg = FDI_RX_CTL(pipe); |
| 3379 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3380 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3381 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3382 | I915_WRITE(reg, temp); |
| 3383 | |
| 3384 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3385 | udelay(150); |
| 3386 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3387 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3388 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3389 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3390 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3391 | |
| 3392 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3393 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3394 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3395 | break; |
| 3396 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3397 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3398 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3399 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3400 | |
| 3401 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3402 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3403 | } |
| 3404 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3405 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3406 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3407 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3408 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3409 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3410 | }; |
| 3411 | |
| 3412 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3413 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3414 | { |
| 3415 | struct drm_device *dev = crtc->dev; |
| 3416 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3417 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3418 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3419 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3420 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3421 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3422 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3423 | reg = FDI_RX_IMR(pipe); |
| 3424 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3425 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3426 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3427 | I915_WRITE(reg, temp); |
| 3428 | |
| 3429 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3430 | udelay(150); |
| 3431 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3432 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3433 | reg = FDI_TX_CTL(pipe); |
| 3434 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3435 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3436 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3437 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3438 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3439 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3440 | /* SNB-B */ |
| 3441 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3442 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3443 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3444 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3445 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3446 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3447 | reg = FDI_RX_CTL(pipe); |
| 3448 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3449 | if (HAS_PCH_CPT(dev)) { |
| 3450 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3451 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3452 | } else { |
| 3453 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3454 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3455 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3456 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3457 | |
| 3458 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3459 | udelay(150); |
| 3460 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3461 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3462 | reg = FDI_TX_CTL(pipe); |
| 3463 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3464 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3465 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3466 | I915_WRITE(reg, temp); |
| 3467 | |
| 3468 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3469 | udelay(500); |
| 3470 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3471 | for (retry = 0; retry < 5; retry++) { |
| 3472 | reg = FDI_RX_IIR(pipe); |
| 3473 | temp = I915_READ(reg); |
| 3474 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3475 | if (temp & FDI_RX_BIT_LOCK) { |
| 3476 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3477 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3478 | break; |
| 3479 | } |
| 3480 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3481 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3482 | if (retry < 5) |
| 3483 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3484 | } |
| 3485 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3486 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3487 | |
| 3488 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3489 | reg = FDI_TX_CTL(pipe); |
| 3490 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3491 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3492 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3493 | if (IS_GEN6(dev)) { |
| 3494 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3495 | /* SNB-B */ |
| 3496 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3497 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3498 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3499 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3500 | reg = FDI_RX_CTL(pipe); |
| 3501 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3502 | if (HAS_PCH_CPT(dev)) { |
| 3503 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3504 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3505 | } else { |
| 3506 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3507 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3508 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3509 | I915_WRITE(reg, temp); |
| 3510 | |
| 3511 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3512 | udelay(150); |
| 3513 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3514 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3515 | reg = FDI_TX_CTL(pipe); |
| 3516 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3517 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3518 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3519 | I915_WRITE(reg, temp); |
| 3520 | |
| 3521 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3522 | udelay(500); |
| 3523 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3524 | for (retry = 0; retry < 5; retry++) { |
| 3525 | reg = FDI_RX_IIR(pipe); |
| 3526 | temp = I915_READ(reg); |
| 3527 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3528 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3529 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3530 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3531 | break; |
| 3532 | } |
| 3533 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3534 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3535 | if (retry < 5) |
| 3536 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3537 | } |
| 3538 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3539 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3540 | |
| 3541 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3542 | } |
| 3543 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3544 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3545 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3546 | { |
| 3547 | struct drm_device *dev = crtc->dev; |
| 3548 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3549 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3550 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3551 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3552 | |
| 3553 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3554 | for train result */ |
| 3555 | reg = FDI_RX_IMR(pipe); |
| 3556 | temp = I915_READ(reg); |
| 3557 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3558 | temp &= ~FDI_RX_BIT_LOCK; |
| 3559 | I915_WRITE(reg, temp); |
| 3560 | |
| 3561 | POSTING_READ(reg); |
| 3562 | udelay(150); |
| 3563 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3564 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3565 | I915_READ(FDI_RX_IIR(pipe))); |
| 3566 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3567 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3568 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3569 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3570 | reg = FDI_TX_CTL(pipe); |
| 3571 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3572 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3573 | temp &= ~FDI_TX_ENABLE; |
| 3574 | I915_WRITE(reg, temp); |
| 3575 | |
| 3576 | reg = FDI_RX_CTL(pipe); |
| 3577 | temp = I915_READ(reg); |
| 3578 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3579 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3580 | temp &= ~FDI_RX_ENABLE; |
| 3581 | I915_WRITE(reg, temp); |
| 3582 | |
| 3583 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3584 | reg = FDI_TX_CTL(pipe); |
| 3585 | temp = I915_READ(reg); |
| 3586 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3587 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3588 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3589 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3590 | temp |= snb_b_fdi_train_param[j/2]; |
| 3591 | temp |= FDI_COMPOSITE_SYNC; |
| 3592 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3593 | |
| 3594 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3595 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3596 | |
| 3597 | reg = FDI_RX_CTL(pipe); |
| 3598 | temp = I915_READ(reg); |
| 3599 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3600 | temp |= FDI_COMPOSITE_SYNC; |
| 3601 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3602 | |
| 3603 | POSTING_READ(reg); |
| 3604 | udelay(1); /* should be 0.5us */ |
| 3605 | |
| 3606 | for (i = 0; i < 4; i++) { |
| 3607 | reg = FDI_RX_IIR(pipe); |
| 3608 | temp = I915_READ(reg); |
| 3609 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3610 | |
| 3611 | if (temp & FDI_RX_BIT_LOCK || |
| 3612 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3613 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3614 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3615 | i); |
| 3616 | break; |
| 3617 | } |
| 3618 | udelay(1); /* should be 0.5us */ |
| 3619 | } |
| 3620 | if (i == 4) { |
| 3621 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3622 | continue; |
| 3623 | } |
| 3624 | |
| 3625 | /* Train 2 */ |
| 3626 | reg = FDI_TX_CTL(pipe); |
| 3627 | temp = I915_READ(reg); |
| 3628 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3629 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3630 | I915_WRITE(reg, temp); |
| 3631 | |
| 3632 | reg = FDI_RX_CTL(pipe); |
| 3633 | temp = I915_READ(reg); |
| 3634 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3635 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3636 | I915_WRITE(reg, temp); |
| 3637 | |
| 3638 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3639 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3640 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3641 | for (i = 0; i < 4; i++) { |
| 3642 | reg = FDI_RX_IIR(pipe); |
| 3643 | temp = I915_READ(reg); |
| 3644 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3645 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3646 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3647 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3648 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3649 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3650 | i); |
| 3651 | goto train_done; |
| 3652 | } |
| 3653 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3654 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3655 | if (i == 4) |
| 3656 | 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] | 3657 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3658 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3659 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3660 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3661 | } |
| 3662 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3663 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3664 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3665 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3666 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3667 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3668 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3669 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3670 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3671 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3672 | reg = FDI_RX_CTL(pipe); |
| 3673 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3674 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3675 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3676 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3677 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3678 | |
| 3679 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3680 | udelay(200); |
| 3681 | |
| 3682 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3683 | temp = I915_READ(reg); |
| 3684 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3685 | |
| 3686 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3687 | udelay(200); |
| 3688 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3689 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3690 | reg = FDI_TX_CTL(pipe); |
| 3691 | temp = I915_READ(reg); |
| 3692 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3693 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3694 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3695 | POSTING_READ(reg); |
| 3696 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3697 | } |
| 3698 | } |
| 3699 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3700 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3701 | { |
| 3702 | struct drm_device *dev = intel_crtc->base.dev; |
| 3703 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3704 | int pipe = intel_crtc->pipe; |
| 3705 | u32 reg, temp; |
| 3706 | |
| 3707 | /* Switch from PCDclk to Rawclk */ |
| 3708 | reg = FDI_RX_CTL(pipe); |
| 3709 | temp = I915_READ(reg); |
| 3710 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3711 | |
| 3712 | /* Disable CPU FDI TX PLL */ |
| 3713 | reg = FDI_TX_CTL(pipe); |
| 3714 | temp = I915_READ(reg); |
| 3715 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3716 | |
| 3717 | POSTING_READ(reg); |
| 3718 | udelay(100); |
| 3719 | |
| 3720 | reg = FDI_RX_CTL(pipe); |
| 3721 | temp = I915_READ(reg); |
| 3722 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3723 | |
| 3724 | /* Wait for the clocks to turn off. */ |
| 3725 | POSTING_READ(reg); |
| 3726 | udelay(100); |
| 3727 | } |
| 3728 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3729 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3730 | { |
| 3731 | struct drm_device *dev = crtc->dev; |
| 3732 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3733 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3734 | int pipe = intel_crtc->pipe; |
| 3735 | u32 reg, temp; |
| 3736 | |
| 3737 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3738 | reg = FDI_TX_CTL(pipe); |
| 3739 | temp = I915_READ(reg); |
| 3740 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3741 | POSTING_READ(reg); |
| 3742 | |
| 3743 | reg = FDI_RX_CTL(pipe); |
| 3744 | temp = I915_READ(reg); |
| 3745 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3746 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3747 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3748 | |
| 3749 | POSTING_READ(reg); |
| 3750 | udelay(100); |
| 3751 | |
| 3752 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3753 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3754 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3755 | |
| 3756 | /* still set train pattern 1 */ |
| 3757 | reg = FDI_TX_CTL(pipe); |
| 3758 | temp = I915_READ(reg); |
| 3759 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3760 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3761 | I915_WRITE(reg, temp); |
| 3762 | |
| 3763 | reg = FDI_RX_CTL(pipe); |
| 3764 | temp = I915_READ(reg); |
| 3765 | if (HAS_PCH_CPT(dev)) { |
| 3766 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3767 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3768 | } else { |
| 3769 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3770 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3771 | } |
| 3772 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3773 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3774 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3775 | I915_WRITE(reg, temp); |
| 3776 | |
| 3777 | POSTING_READ(reg); |
| 3778 | udelay(100); |
| 3779 | } |
| 3780 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3781 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3782 | { |
| 3783 | struct intel_crtc *crtc; |
| 3784 | |
| 3785 | /* Note that we don't need to be called with mode_config.lock here |
| 3786 | * as our list of CRTC objects is static for the lifetime of the |
| 3787 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3788 | * happily treat the predicates as racy, atomic checks as userspace |
| 3789 | * cannot claim and pin a new fb without at least acquring the |
| 3790 | * struct_mutex and so serialising with us. |
| 3791 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3792 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3793 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3794 | continue; |
| 3795 | |
| 3796 | if (crtc->unpin_work) |
| 3797 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3798 | |
| 3799 | return true; |
| 3800 | } |
| 3801 | |
| 3802 | return false; |
| 3803 | } |
| 3804 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3805 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3806 | { |
| 3807 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3808 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3809 | |
| 3810 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3811 | smp_rmb(); |
| 3812 | intel_crtc->unpin_work = NULL; |
| 3813 | |
| 3814 | if (work->event) |
| 3815 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3816 | intel_crtc->pipe, |
| 3817 | work->event); |
| 3818 | |
| 3819 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3820 | |
| 3821 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3822 | queue_work(dev_priv->wq, &work->work); |
| 3823 | |
| 3824 | trace_i915_flip_complete(intel_crtc->plane, |
| 3825 | work->pending_flip_obj); |
| 3826 | } |
| 3827 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3828 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3829 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3830 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3831 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3832 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3833 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3834 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3835 | !intel_crtc_has_pending_flip(crtc), |
| 3836 | 60*HZ) == 0)) { |
| 3837 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3838 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3839 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3840 | if (intel_crtc->unpin_work) { |
| 3841 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3842 | page_flip_completed(intel_crtc); |
| 3843 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3844 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3845 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3846 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3847 | if (crtc->primary->fb) { |
| 3848 | mutex_lock(&dev->struct_mutex); |
| 3849 | intel_finish_fb(crtc->primary->fb); |
| 3850 | mutex_unlock(&dev->struct_mutex); |
| 3851 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3852 | } |
| 3853 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3854 | /* Program iCLKIP clock to the desired frequency */ |
| 3855 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3856 | { |
| 3857 | struct drm_device *dev = crtc->dev; |
| 3858 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3859 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3860 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3861 | u32 temp; |
| 3862 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 3863 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3864 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3865 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3866 | * the divisors, and gate it back when it is done. |
| 3867 | */ |
| 3868 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3869 | |
| 3870 | /* Disable SSCCTL */ |
| 3871 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3872 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3873 | SBI_SSCCTL_DISABLE, |
| 3874 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3875 | |
| 3876 | /* 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] | 3877 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3878 | auxdiv = 1; |
| 3879 | divsel = 0x41; |
| 3880 | phaseinc = 0x20; |
| 3881 | } else { |
| 3882 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3883 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3884 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3885 | * convert the virtual clock precision to KHz here for higher |
| 3886 | * precision. |
| 3887 | */ |
| 3888 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3889 | u32 iclk_pi_range = 64; |
| 3890 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3891 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3892 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3893 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3894 | pi_value = desired_divisor % iclk_pi_range; |
| 3895 | |
| 3896 | auxdiv = 0; |
| 3897 | divsel = msb_divisor_value - 2; |
| 3898 | phaseinc = pi_value; |
| 3899 | } |
| 3900 | |
| 3901 | /* This should not happen with any sane values */ |
| 3902 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3903 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3904 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3905 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3906 | |
| 3907 | 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] | 3908 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3909 | auxdiv, |
| 3910 | divsel, |
| 3911 | phasedir, |
| 3912 | phaseinc); |
| 3913 | |
| 3914 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3915 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3916 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3917 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3918 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3919 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3920 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3921 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3922 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3923 | |
| 3924 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3925 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3926 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3927 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3928 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3929 | |
| 3930 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3931 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3932 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3933 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3934 | |
| 3935 | /* Wait for initialization time */ |
| 3936 | udelay(24); |
| 3937 | |
| 3938 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3939 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 3940 | mutex_unlock(&dev_priv->sb_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3941 | } |
| 3942 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3943 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3944 | enum pipe pch_transcoder) |
| 3945 | { |
| 3946 | struct drm_device *dev = crtc->base.dev; |
| 3947 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3948 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3949 | |
| 3950 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3951 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3952 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3953 | I915_READ(HBLANK(cpu_transcoder))); |
| 3954 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3955 | I915_READ(HSYNC(cpu_transcoder))); |
| 3956 | |
| 3957 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3958 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3959 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3960 | I915_READ(VBLANK(cpu_transcoder))); |
| 3961 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3962 | I915_READ(VSYNC(cpu_transcoder))); |
| 3963 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3964 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3965 | } |
| 3966 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3967 | 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] | 3968 | { |
| 3969 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3970 | uint32_t temp; |
| 3971 | |
| 3972 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3973 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3974 | return; |
| 3975 | |
| 3976 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3977 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3978 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3979 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 3980 | if (enable) |
| 3981 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3982 | |
| 3983 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3984 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3985 | POSTING_READ(SOUTH_CHICKEN1); |
| 3986 | } |
| 3987 | |
| 3988 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3989 | { |
| 3990 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3991 | |
| 3992 | switch (intel_crtc->pipe) { |
| 3993 | case PIPE_A: |
| 3994 | break; |
| 3995 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3996 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3997 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3998 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3999 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4000 | |
| 4001 | break; |
| 4002 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4003 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4004 | |
| 4005 | break; |
| 4006 | default: |
| 4007 | BUG(); |
| 4008 | } |
| 4009 | } |
| 4010 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4011 | /* |
| 4012 | * Enable PCH resources required for PCH ports: |
| 4013 | * - PCH PLLs |
| 4014 | * - FDI training & RX/TX |
| 4015 | * - update transcoder timings |
| 4016 | * - DP transcoding bits |
| 4017 | * - transcoder |
| 4018 | */ |
| 4019 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4020 | { |
| 4021 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4022 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4023 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4024 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4025 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4026 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4027 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4028 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4029 | if (IS_IVYBRIDGE(dev)) |
| 4030 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4031 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4032 | /* Write the TU size bits before fdi link training, so that error |
| 4033 | * detection works. */ |
| 4034 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4035 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4036 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4037 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4038 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4039 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4040 | /* We need to program the right clock selection before writing the pixel |
| 4041 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4042 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4043 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4044 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4045 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4046 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4047 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4048 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4049 | temp |= sel; |
| 4050 | else |
| 4051 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4052 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4053 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4054 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4055 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4056 | * transcoder, and we actually should do this to not upset any PCH |
| 4057 | * transcoder that already use the clock when we share it. |
| 4058 | * |
| 4059 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4060 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4061 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4062 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4063 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4064 | /* set transcoder timing, panel must allow it */ |
| 4065 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4066 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4067 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4068 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4069 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4070 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4071 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4072 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4073 | reg = TRANS_DP_CTL(pipe); |
| 4074 | temp = I915_READ(reg); |
| 4075 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4076 | TRANS_DP_SYNC_MASK | |
| 4077 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4078 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4079 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4080 | |
| 4081 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4082 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4083 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4084 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4085 | |
| 4086 | switch (intel_trans_dp_port_sel(crtc)) { |
| 4087 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4088 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4089 | break; |
| 4090 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4091 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4092 | break; |
| 4093 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4094 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4095 | break; |
| 4096 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4097 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4100 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4103 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4104 | } |
| 4105 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4106 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4107 | { |
| 4108 | struct drm_device *dev = crtc->dev; |
| 4109 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4110 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4111 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4112 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4113 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4114 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4115 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4116 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4117 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4118 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4119 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4120 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4121 | } |
| 4122 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4123 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
| 4124 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4125 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4126 | 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] | 4127 | struct intel_shared_dpll *pll; |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4128 | struct intel_shared_dpll_config *shared_dpll; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4129 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4130 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4131 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
| 4132 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4133 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 4134 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 4135 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4136 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4137 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4138 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4139 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4140 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4141 | WARN_ON(shared_dpll[i].crtc_mask); |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4142 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4143 | goto found; |
| 4144 | } |
| 4145 | |
Satheeshakrishna M | bcddf610 | 2014-08-22 09:49:10 +0530 | [diff] [blame] | 4146 | if (IS_BROXTON(dev_priv->dev)) { |
| 4147 | /* PLL is attached to port in bxt */ |
| 4148 | struct intel_encoder *encoder; |
| 4149 | struct intel_digital_port *intel_dig_port; |
| 4150 | |
| 4151 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); |
| 4152 | if (WARN_ON(!encoder)) |
| 4153 | return NULL; |
| 4154 | |
| 4155 | intel_dig_port = enc_to_dig_port(&encoder->base); |
| 4156 | /* 1:1 mapping between ports and PLLs */ |
| 4157 | i = (enum intel_dpll_id)intel_dig_port->port; |
| 4158 | pll = &dev_priv->shared_dplls[i]; |
| 4159 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4160 | crtc->base.base.id, pll->name); |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4161 | WARN_ON(shared_dpll[i].crtc_mask); |
Satheeshakrishna M | bcddf610 | 2014-08-22 09:49:10 +0530 | [diff] [blame] | 4162 | |
| 4163 | goto found; |
| 4164 | } |
| 4165 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4166 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4167 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4168 | |
| 4169 | /* Only want to check enabled timings first */ |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4170 | if (shared_dpll[i].crtc_mask == 0) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4171 | continue; |
| 4172 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4173 | if (memcmp(&crtc_state->dpll_hw_state, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4174 | &shared_dpll[i].hw_state, |
| 4175 | sizeof(crtc_state->dpll_hw_state)) == 0) { |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4176 | 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] | 4177 | crtc->base.base.id, pll->name, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4178 | shared_dpll[i].crtc_mask, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4179 | pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4180 | goto found; |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4185 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4186 | pll = &dev_priv->shared_dplls[i]; |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4187 | if (shared_dpll[i].crtc_mask == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4188 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 4189 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4190 | goto found; |
| 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | return NULL; |
| 4195 | |
| 4196 | found: |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4197 | if (shared_dpll[i].crtc_mask == 0) |
| 4198 | shared_dpll[i].hw_state = |
| 4199 | crtc_state->dpll_hw_state; |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4200 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4201 | crtc_state->shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4202 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 4203 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 4204 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4205 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4206 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4207 | return pll; |
| 4208 | } |
| 4209 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4210 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4211 | { |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4212 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
| 4213 | struct intel_shared_dpll_config *shared_dpll; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4214 | struct intel_shared_dpll *pll; |
| 4215 | enum intel_dpll_id i; |
| 4216 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4217 | if (!to_intel_atomic_state(state)->dpll_set) |
| 4218 | return; |
| 4219 | |
| 4220 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4221 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4222 | pll = &dev_priv->shared_dplls[i]; |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 4223 | pll->config = shared_dpll[i]; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4227 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4228 | { |
| 4229 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 4230 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4231 | u32 temp; |
| 4232 | |
| 4233 | temp = I915_READ(dslreg); |
| 4234 | udelay(500); |
| 4235 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4236 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4237 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4241 | static int |
| 4242 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
| 4243 | unsigned scaler_user, int *scaler_id, unsigned int rotation, |
| 4244 | int src_w, int src_h, int dst_w, int dst_h) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4245 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4246 | struct intel_crtc_scaler_state *scaler_state = |
| 4247 | &crtc_state->scaler_state; |
| 4248 | struct intel_crtc *intel_crtc = |
| 4249 | to_intel_crtc(crtc_state->base.crtc); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4250 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4251 | |
| 4252 | need_scaling = intel_rotation_90_or_270(rotation) ? |
| 4253 | (src_h != dst_w || src_w != dst_h): |
| 4254 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4255 | |
| 4256 | /* |
| 4257 | * if plane is being disabled or scaler is no more required or force detach |
| 4258 | * - free scaler binded to this plane/crtc |
| 4259 | * - in order to do this, update crtc->scaler_usage |
| 4260 | * |
| 4261 | * Here scaler state in crtc_state is set free so that |
| 4262 | * scaler can be assigned to other user. Actual register |
| 4263 | * update to free the scaler is done in plane/panel-fit programming. |
| 4264 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4265 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4266 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4267 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4268 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4269 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4270 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4271 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4272 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4273 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4274 | scaler_state->scaler_users); |
| 4275 | *scaler_id = -1; |
| 4276 | } |
| 4277 | return 0; |
| 4278 | } |
| 4279 | |
| 4280 | /* range checks */ |
| 4281 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4282 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4283 | |
| 4284 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4285 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4286 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4287 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4288 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4289 | return -EINVAL; |
| 4290 | } |
| 4291 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4292 | /* mark this plane as a scaler user in crtc_state */ |
| 4293 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4294 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4295 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4296 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4297 | scaler_state->scaler_users); |
| 4298 | |
| 4299 | return 0; |
| 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4304 | * |
| 4305 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4306 | * |
| 4307 | * Return |
| 4308 | * 0 - scaler_usage updated successfully |
| 4309 | * error - requested scaling cannot be supported or other error condition |
| 4310 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4311 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4312 | { |
| 4313 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); |
| 4314 | struct drm_display_mode *adjusted_mode = |
| 4315 | &state->base.adjusted_mode; |
| 4316 | |
| 4317 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", |
| 4318 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); |
| 4319 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4320 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4321 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
| 4322 | state->pipe_src_w, state->pipe_src_h, |
Imre Deak | 8c6cda2 | 2015-06-23 20:40:27 +0300 | [diff] [blame] | 4323 | adjusted_mode->hdisplay, adjusted_mode->vdisplay); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | /** |
| 4327 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
| 4328 | * |
| 4329 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4330 | * @plane_state: atomic plane state to update |
| 4331 | * |
| 4332 | * Return |
| 4333 | * 0 - scaler_usage updated successfully |
| 4334 | * error - requested scaling cannot be supported or other error condition |
| 4335 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4336 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4337 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4338 | { |
| 4339 | |
| 4340 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4341 | struct intel_plane *intel_plane = |
| 4342 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4343 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4344 | int ret; |
| 4345 | |
| 4346 | bool force_detach = !fb || !plane_state->visible; |
| 4347 | |
| 4348 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", |
| 4349 | intel_plane->base.base.id, intel_crtc->pipe, |
| 4350 | drm_plane_index(&intel_plane->base)); |
| 4351 | |
| 4352 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4353 | drm_plane_index(&intel_plane->base), |
| 4354 | &plane_state->scaler_id, |
| 4355 | plane_state->base.rotation, |
| 4356 | drm_rect_width(&plane_state->src) >> 16, |
| 4357 | drm_rect_height(&plane_state->src) >> 16, |
| 4358 | drm_rect_width(&plane_state->dst), |
| 4359 | drm_rect_height(&plane_state->dst)); |
| 4360 | |
| 4361 | if (ret || plane_state->scaler_id < 0) |
| 4362 | return ret; |
| 4363 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4364 | /* check colorkey */ |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4365 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4366 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4367 | intel_plane->base.base.id); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4368 | return -EINVAL; |
| 4369 | } |
| 4370 | |
| 4371 | /* Check src format */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4372 | switch (fb->pixel_format) { |
| 4373 | case DRM_FORMAT_RGB565: |
| 4374 | case DRM_FORMAT_XBGR8888: |
| 4375 | case DRM_FORMAT_XRGB8888: |
| 4376 | case DRM_FORMAT_ABGR8888: |
| 4377 | case DRM_FORMAT_ARGB8888: |
| 4378 | case DRM_FORMAT_XRGB2101010: |
| 4379 | case DRM_FORMAT_XBGR2101010: |
| 4380 | case DRM_FORMAT_YUYV: |
| 4381 | case DRM_FORMAT_YVYU: |
| 4382 | case DRM_FORMAT_UYVY: |
| 4383 | case DRM_FORMAT_VYUY: |
| 4384 | break; |
| 4385 | default: |
| 4386 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", |
| 4387 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); |
| 4388 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4391 | return 0; |
| 4392 | } |
| 4393 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4394 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4395 | { |
| 4396 | int i; |
| 4397 | |
| 4398 | for (i = 0; i < crtc->num_scalers; i++) |
| 4399 | skl_detach_scaler(crtc, i); |
| 4400 | } |
| 4401 | |
| 4402 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4403 | { |
| 4404 | struct drm_device *dev = crtc->base.dev; |
| 4405 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4406 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4407 | struct intel_crtc_scaler_state *scaler_state = |
| 4408 | &crtc->config->scaler_state; |
| 4409 | |
| 4410 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4411 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4412 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4413 | int id; |
| 4414 | |
| 4415 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4416 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4417 | return; |
| 4418 | } |
| 4419 | |
| 4420 | id = scaler_state->scaler_id; |
| 4421 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4422 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4423 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4424 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4425 | |
| 4426 | 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] | 4427 | } |
| 4428 | } |
| 4429 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4430 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4431 | { |
| 4432 | struct drm_device *dev = crtc->base.dev; |
| 4433 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4434 | int pipe = crtc->pipe; |
| 4435 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4436 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4437 | /* Force use of hard-coded filter coefficients |
| 4438 | * as some pre-programmed values are broken, |
| 4439 | * e.g. x201. |
| 4440 | */ |
| 4441 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4442 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4443 | PF_PIPE_SEL_IVB(pipe)); |
| 4444 | else |
| 4445 | 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] | 4446 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4447 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4448 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4449 | } |
| 4450 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4451 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4452 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4453 | struct drm_device *dev = crtc->base.dev; |
| 4454 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4455 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4456 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4457 | return; |
| 4458 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4459 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4460 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4461 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4462 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4463 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4464 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4465 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4466 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4467 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4468 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4469 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4470 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4471 | */ |
| 4472 | } else { |
| 4473 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4474 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4475 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4476 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4477 | * the HW state readout code will complain that the expected |
| 4478 | * IPS_CTL value is not the one we read. */ |
| 4479 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4480 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4481 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4482 | } |
| 4483 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4484 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4485 | { |
| 4486 | struct drm_device *dev = crtc->base.dev; |
| 4487 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4488 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4489 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4490 | return; |
| 4491 | |
| 4492 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4493 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4494 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4495 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4496 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4497 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4498 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4499 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4500 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4501 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4502 | POSTING_READ(IPS_CTL); |
| 4503 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4504 | |
| 4505 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4506 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4507 | } |
| 4508 | |
| 4509 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4510 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4511 | { |
| 4512 | struct drm_device *dev = crtc->dev; |
| 4513 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4514 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4515 | enum pipe pipe = intel_crtc->pipe; |
| 4516 | int palreg = PALETTE(pipe); |
| 4517 | int i; |
| 4518 | bool reenable_ips = false; |
| 4519 | |
| 4520 | /* The clocks have to be on to load the palette. */ |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4521 | if (!crtc->state->active) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4522 | return; |
| 4523 | |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 4524 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 4525 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4526 | assert_dsi_pll_enabled(dev_priv); |
| 4527 | else |
| 4528 | assert_pll_enabled(dev_priv, pipe); |
| 4529 | } |
| 4530 | |
| 4531 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 4532 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4533 | palreg = LGC_PALETTE(pipe); |
| 4534 | |
| 4535 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 4536 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 4537 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4538 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4539 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 4540 | GAMMA_MODE_MODE_SPLIT)) { |
| 4541 | hsw_disable_ips(intel_crtc); |
| 4542 | reenable_ips = true; |
| 4543 | } |
| 4544 | |
| 4545 | for (i = 0; i < 256; i++) { |
| 4546 | I915_WRITE(palreg + 4 * i, |
| 4547 | (intel_crtc->lut_r[i] << 16) | |
| 4548 | (intel_crtc->lut_g[i] << 8) | |
| 4549 | intel_crtc->lut_b[i]); |
| 4550 | } |
| 4551 | |
| 4552 | if (reenable_ips) |
| 4553 | hsw_enable_ips(intel_crtc); |
| 4554 | } |
| 4555 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4556 | 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] | 4557 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4558 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4559 | struct drm_device *dev = intel_crtc->base.dev; |
| 4560 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4561 | |
| 4562 | mutex_lock(&dev->struct_mutex); |
| 4563 | dev_priv->mm.interruptible = false; |
| 4564 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4565 | dev_priv->mm.interruptible = true; |
| 4566 | mutex_unlock(&dev->struct_mutex); |
| 4567 | } |
| 4568 | |
| 4569 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4570 | * has to recompute where to put it anyway. |
| 4571 | */ |
| 4572 | } |
| 4573 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4574 | /** |
| 4575 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4576 | * @crtc: the CRTC whose primary plane was just enabled |
| 4577 | * |
| 4578 | * Performs potentially sleeping operations that must be done after the primary |
| 4579 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4580 | * called due to an explicit primary plane update, or due to an implicit |
| 4581 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4582 | * completely hide the primary plane. |
| 4583 | */ |
| 4584 | static void |
| 4585 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4586 | { |
| 4587 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4588 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4589 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4590 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4591 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4592 | /* |
| 4593 | * BDW signals flip done immediately if the plane |
| 4594 | * is disabled, even if the plane enable is already |
| 4595 | * armed to occur at the next vblank :( |
| 4596 | */ |
| 4597 | if (IS_BROADWELL(dev)) |
| 4598 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4599 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4600 | /* |
| 4601 | * FIXME IPS should be fine as long as one plane is |
| 4602 | * enabled, but in practice it seems to have problems |
| 4603 | * when going from primary only to sprite only and vice |
| 4604 | * versa. |
| 4605 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4606 | hsw_enable_ips(intel_crtc); |
| 4607 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4608 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4609 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4610 | * So don't enable underrun reporting before at least some planes |
| 4611 | * are enabled. |
| 4612 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4613 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4614 | */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4615 | if (IS_GEN2(dev)) |
| 4616 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4617 | |
| 4618 | /* Underruns don't raise interrupts, so check manually. */ |
| 4619 | if (HAS_GMCH_DISPLAY(dev)) |
| 4620 | i9xx_check_fifo_underruns(dev_priv); |
| 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * intel_pre_disable_primary - Perform operations before disabling primary plane |
| 4625 | * @crtc: the CRTC whose primary plane is to be disabled |
| 4626 | * |
| 4627 | * Performs potentially sleeping operations that must be done before the |
| 4628 | * primary plane is disabled, such as updating FBC and IPS. Note that this may |
| 4629 | * be called due to an explicit primary plane update, or due to an implicit |
| 4630 | * disable that is caused when a sprite plane completely hides the primary |
| 4631 | * plane. |
| 4632 | */ |
| 4633 | static void |
| 4634 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4635 | { |
| 4636 | struct drm_device *dev = crtc->dev; |
| 4637 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4638 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4639 | int pipe = intel_crtc->pipe; |
| 4640 | |
| 4641 | /* |
| 4642 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4643 | * So diasble underrun reporting before all the planes get disabled. |
| 4644 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4645 | * but leave the pipe running. |
| 4646 | */ |
| 4647 | if (IS_GEN2(dev)) |
| 4648 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4649 | |
| 4650 | /* |
| 4651 | * Vblank time updates from the shadow to live plane control register |
| 4652 | * are blocked if the memory self-refresh mode is active at that |
| 4653 | * moment. So to make sure the plane gets truly disabled, disable |
| 4654 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4655 | * will be checked/applied by the HW only at the next frame start |
| 4656 | * event which is after the vblank start event, so we need to have a |
| 4657 | * wait-for-vblank between disabling the plane and the pipe. |
| 4658 | */ |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4659 | if (HAS_GMCH_DISPLAY(dev)) { |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4660 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4661 | dev_priv->wm.vlv.cxsr = false; |
| 4662 | intel_wait_for_vblank(dev, pipe); |
| 4663 | } |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4664 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4665 | /* |
| 4666 | * FIXME IPS should be fine as long as one plane is |
| 4667 | * enabled, but in practice it seems to have problems |
| 4668 | * when going from primary only to sprite only and vice |
| 4669 | * versa. |
| 4670 | */ |
| 4671 | hsw_disable_ips(intel_crtc); |
| 4672 | } |
| 4673 | |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4674 | static void intel_post_plane_update(struct intel_crtc *crtc) |
| 4675 | { |
| 4676 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
| 4677 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 4678 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4679 | struct drm_plane *plane; |
| 4680 | |
| 4681 | if (atomic->wait_vblank) |
| 4682 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4683 | |
| 4684 | intel_frontbuffer_flip(dev, atomic->fb_bits); |
| 4685 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4686 | if (atomic->disable_cxsr) |
| 4687 | crtc->wm.cxsr_allowed = true; |
| 4688 | |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 4689 | if (crtc->atomic.update_wm_post) |
| 4690 | intel_update_watermarks(&crtc->base); |
| 4691 | |
Paulo Zanoni | c80ac85 | 2015-07-02 19:25:13 -0300 | [diff] [blame] | 4692 | if (atomic->update_fbc) |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 4693 | intel_fbc_update(dev_priv); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4694 | |
| 4695 | if (atomic->post_enable_primary) |
| 4696 | intel_post_enable_primary(&crtc->base); |
| 4697 | |
| 4698 | drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks) |
| 4699 | intel_update_sprite_watermarks(plane, &crtc->base, |
| 4700 | 0, 0, 0, false, false); |
| 4701 | |
| 4702 | memset(atomic, 0, sizeof(*atomic)); |
| 4703 | } |
| 4704 | |
| 4705 | static void intel_pre_plane_update(struct intel_crtc *crtc) |
| 4706 | { |
| 4707 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 4708 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4709 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
| 4710 | struct drm_plane *p; |
| 4711 | |
| 4712 | /* Track fb's for any planes being disabled */ |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4713 | drm_for_each_plane_mask(p, dev, atomic->disabled_planes) { |
| 4714 | struct intel_plane *plane = to_intel_plane(p); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4715 | |
| 4716 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 4717 | i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL, |
| 4718 | plane->frontbuffer_bit); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4719 | mutex_unlock(&dev->struct_mutex); |
| 4720 | } |
| 4721 | |
| 4722 | if (atomic->wait_for_flips) |
| 4723 | intel_crtc_wait_for_pending_flips(&crtc->base); |
| 4724 | |
Paulo Zanoni | c80ac85 | 2015-07-02 19:25:13 -0300 | [diff] [blame] | 4725 | if (atomic->disable_fbc) |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 4726 | intel_fbc_disable_crtc(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4727 | |
Rodrigo Vivi | 066cf55b | 2015-06-26 13:55:54 -0700 | [diff] [blame] | 4728 | if (crtc->atomic.disable_ips) |
| 4729 | hsw_disable_ips(crtc); |
| 4730 | |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4731 | if (atomic->pre_disable_primary) |
| 4732 | intel_pre_disable_primary(&crtc->base); |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4733 | |
| 4734 | if (atomic->disable_cxsr) { |
| 4735 | crtc->wm.cxsr_allowed = false; |
| 4736 | intel_set_memory_cxsr(dev_priv, false); |
| 4737 | } |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4738 | } |
| 4739 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4740 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4741 | { |
| 4742 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4743 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4744 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4745 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4746 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4747 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4748 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4749 | drm_for_each_plane_mask(p, dev, plane_mask) |
| 4750 | to_intel_plane(p)->disable_plane(p, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4751 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4752 | /* |
| 4753 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4754 | * to compute the mask of flip planes precisely. For the time being |
| 4755 | * consider this a flip to a NULL plane. |
| 4756 | */ |
| 4757 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4758 | } |
| 4759 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4760 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4761 | { |
| 4762 | struct drm_device *dev = crtc->dev; |
| 4763 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4764 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4765 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4766 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4767 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4768 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4769 | return; |
| 4770 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4771 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4772 | intel_prepare_shared_dpll(intel_crtc); |
| 4773 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4774 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4775 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4776 | |
| 4777 | intel_set_pipe_timings(intel_crtc); |
| 4778 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4779 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4780 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4781 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | ironlake_set_pipeconf(crtc); |
| 4785 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4786 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4787 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4788 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4789 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4790 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4791 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4792 | if (encoder->pre_enable) |
| 4793 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4794 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4795 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4796 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4797 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4798 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4799 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4800 | } else { |
| 4801 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4802 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4803 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4804 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4805 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4806 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4807 | /* |
| 4808 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4809 | * clocks enabled |
| 4810 | */ |
| 4811 | intel_crtc_load_lut(crtc); |
| 4812 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4813 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4814 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4815 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4816 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4817 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4818 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4819 | assert_vblank_disabled(crtc); |
| 4820 | drm_crtc_vblank_on(crtc); |
| 4821 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4822 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4823 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4824 | |
| 4825 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4826 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4829 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4830 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4831 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4832 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4833 | } |
| 4834 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4835 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4836 | { |
| 4837 | struct drm_device *dev = crtc->dev; |
| 4838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4839 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4840 | struct intel_encoder *encoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4841 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
| 4842 | struct intel_crtc_state *pipe_config = |
| 4843 | to_intel_crtc_state(crtc->state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4844 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4845 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4846 | return; |
| 4847 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4848 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4849 | intel_enable_shared_dpll(intel_crtc); |
| 4850 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4851 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4852 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4853 | |
| 4854 | intel_set_pipe_timings(intel_crtc); |
| 4855 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4856 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
| 4857 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), |
| 4858 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4861 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4862 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4863 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | haswell_set_pipeconf(crtc); |
| 4867 | |
| 4868 | intel_set_pipe_csc(crtc); |
| 4869 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4870 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4871 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4872 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4873 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4874 | if (encoder->pre_enable) |
| 4875 | encoder->pre_enable(encoder); |
| 4876 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4877 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4878 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4879 | true); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4880 | dev_priv->display.fdi_link_train(crtc); |
| 4881 | } |
| 4882 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4883 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4884 | |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4885 | if (INTEL_INFO(dev)->gen == 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4886 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4887 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4888 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4889 | else |
| 4890 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4891 | |
| 4892 | /* |
| 4893 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4894 | * clocks enabled |
| 4895 | */ |
| 4896 | intel_crtc_load_lut(crtc); |
| 4897 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4898 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4899 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4900 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4901 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4902 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4903 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4904 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4905 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4906 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4907 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4908 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4909 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4910 | assert_vblank_disabled(crtc); |
| 4911 | drm_crtc_vblank_on(crtc); |
| 4912 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4913 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4914 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4915 | intel_opregion_notify_encoder(encoder, true); |
| 4916 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4917 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4918 | /* If we change the relative order between pipe/planes enabling, we need |
| 4919 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4920 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
| 4921 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { |
| 4922 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4923 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4924 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4925 | } |
| 4926 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4927 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4928 | { |
| 4929 | struct drm_device *dev = crtc->base.dev; |
| 4930 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4931 | int pipe = crtc->pipe; |
| 4932 | |
| 4933 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4934 | * 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] | 4935 | if (crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4936 | I915_WRITE(PF_CTL(pipe), 0); |
| 4937 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4938 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4939 | } |
| 4940 | } |
| 4941 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4942 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4943 | { |
| 4944 | struct drm_device *dev = crtc->dev; |
| 4945 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4946 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4947 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4948 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4949 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4950 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4951 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4952 | encoder->disable(encoder); |
| 4953 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4954 | drm_crtc_vblank_off(crtc); |
| 4955 | assert_vblank_disabled(crtc); |
| 4956 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4957 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4958 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4959 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4960 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4961 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4962 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4963 | |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4964 | if (intel_crtc->config->has_pch_encoder) |
| 4965 | ironlake_fdi_disable(crtc); |
| 4966 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4967 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4968 | if (encoder->post_disable) |
| 4969 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4970 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4971 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4972 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4973 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4974 | if (HAS_PCH_CPT(dev)) { |
| 4975 | /* disable TRANS_DP_CTL */ |
| 4976 | reg = TRANS_DP_CTL(pipe); |
| 4977 | temp = I915_READ(reg); |
| 4978 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4979 | TRANS_DP_PORT_SEL_MASK); |
| 4980 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4981 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4982 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4983 | /* disable DPLL_SEL */ |
| 4984 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4985 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4986 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4987 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4988 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4989 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4990 | } |
Patrik Jakobsson | e4ca061 | 2015-07-08 15:31:52 +0200 | [diff] [blame] | 4991 | |
| 4992 | intel_crtc->active = false; |
| 4993 | intel_update_watermarks(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4996 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4997 | { |
| 4998 | struct drm_device *dev = crtc->dev; |
| 4999 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5000 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5001 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5002 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5003 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5004 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5005 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5006 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5007 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5008 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5009 | drm_crtc_vblank_off(crtc); |
| 5010 | assert_vblank_disabled(crtc); |
| 5011 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5012 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5013 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5014 | false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5015 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5016 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5017 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5018 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5019 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 5020 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5021 | |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5022 | if (INTEL_INFO(dev)->gen == 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5023 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5024 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5025 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5026 | else |
| 5027 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5028 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 5029 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5030 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5031 | if (intel_crtc->config->has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 5032 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 5033 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 5034 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5035 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 5036 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5037 | if (encoder->post_disable) |
| 5038 | encoder->post_disable(encoder); |
Patrik Jakobsson | e4ca061 | 2015-07-08 15:31:52 +0200 | [diff] [blame] | 5039 | |
| 5040 | intel_crtc->active = false; |
| 5041 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5042 | } |
| 5043 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5044 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5045 | { |
| 5046 | struct drm_device *dev = crtc->base.dev; |
| 5047 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5048 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5049 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5050 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5051 | return; |
| 5052 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5053 | /* |
| 5054 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5055 | * according to register description and PRM. |
| 5056 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5057 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5058 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5059 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5060 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5061 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5062 | |
| 5063 | /* Border color in case we don't scale up to the full screen. Black by |
| 5064 | * default, change to something else for debugging. */ |
| 5065 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5068 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5069 | { |
| 5070 | switch (port) { |
| 5071 | case PORT_A: |
Rodrigo Vivi | a513e3d75 | 2015-08-06 15:51:37 +0800 | [diff] [blame] | 5072 | case PORT_E: |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5073 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 5074 | case PORT_B: |
| 5075 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 5076 | case PORT_C: |
| 5077 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 5078 | case PORT_D: |
| 5079 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 5080 | default: |
| 5081 | WARN_ON_ONCE(1); |
| 5082 | return POWER_DOMAIN_PORT_OTHER; |
| 5083 | } |
| 5084 | } |
| 5085 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5086 | #define for_each_power_domain(domain, mask) \ |
| 5087 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 5088 | if ((1 << (domain)) & (mask)) |
| 5089 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5090 | enum intel_display_power_domain |
| 5091 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5092 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5093 | struct drm_device *dev = intel_encoder->base.dev; |
| 5094 | struct intel_digital_port *intel_dig_port; |
| 5095 | |
| 5096 | switch (intel_encoder->type) { |
| 5097 | case INTEL_OUTPUT_UNKNOWN: |
| 5098 | /* Only DDI platforms should ever use this output type */ |
| 5099 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5100 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5101 | case INTEL_OUTPUT_HDMI: |
| 5102 | case INTEL_OUTPUT_EDP: |
| 5103 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5104 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5105 | case INTEL_OUTPUT_DP_MST: |
| 5106 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5107 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5108 | case INTEL_OUTPUT_ANALOG: |
| 5109 | return POWER_DOMAIN_PORT_CRT; |
| 5110 | case INTEL_OUTPUT_DSI: |
| 5111 | return POWER_DOMAIN_PORT_DSI; |
| 5112 | default: |
| 5113 | return POWER_DOMAIN_PORT_OTHER; |
| 5114 | } |
| 5115 | } |
| 5116 | |
| 5117 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 5118 | { |
| 5119 | struct drm_device *dev = crtc->dev; |
| 5120 | struct intel_encoder *intel_encoder; |
| 5121 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5122 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5123 | unsigned long mask; |
| 5124 | enum transcoder transcoder; |
| 5125 | |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5126 | if (!crtc->state->active) |
| 5127 | return 0; |
| 5128 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5129 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 5130 | |
| 5131 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5132 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5133 | if (intel_crtc->config->pch_pfit.enabled || |
| 5134 | intel_crtc->config->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5135 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5136 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5137 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5138 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 5139 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5140 | return mask; |
| 5141 | } |
| 5142 | |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5143 | static unsigned long modeset_get_crtc_power_domains(struct drm_crtc *crtc) |
| 5144 | { |
| 5145 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5146 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5147 | enum intel_display_power_domain domain; |
| 5148 | unsigned long domains, new_domains, old_domains; |
| 5149 | |
| 5150 | old_domains = intel_crtc->enabled_power_domains; |
| 5151 | intel_crtc->enabled_power_domains = new_domains = get_crtc_power_domains(crtc); |
| 5152 | |
| 5153 | domains = new_domains & ~old_domains; |
| 5154 | |
| 5155 | for_each_power_domain(domain, domains) |
| 5156 | intel_display_power_get(dev_priv, domain); |
| 5157 | |
| 5158 | return old_domains & ~new_domains; |
| 5159 | } |
| 5160 | |
| 5161 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
| 5162 | unsigned long domains) |
| 5163 | { |
| 5164 | enum intel_display_power_domain domain; |
| 5165 | |
| 5166 | for_each_power_domain(domain, domains) |
| 5167 | intel_display_power_put(dev_priv, domain); |
| 5168 | } |
| 5169 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5170 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5171 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5172 | struct drm_device *dev = state->dev; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5173 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5174 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
| 5175 | struct drm_crtc_state *crtc_state; |
| 5176 | struct drm_crtc *crtc; |
| 5177 | int i; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5178 | |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5179 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 5180 | if (needs_modeset(crtc->state)) |
| 5181 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 5182 | modeset_get_crtc_power_domains(crtc); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5183 | } |
| 5184 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5185 | if (dev_priv->display.modeset_commit_cdclk) { |
| 5186 | unsigned int cdclk = to_intel_atomic_state(state)->cdclk; |
| 5187 | |
| 5188 | if (cdclk != dev_priv->cdclk_freq && |
| 5189 | !WARN_ON(!state->allow_modeset)) |
| 5190 | dev_priv->display.modeset_commit_cdclk(state); |
| 5191 | } |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 5192 | |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5193 | for (i = 0; i < I915_MAX_PIPES; i++) |
| 5194 | if (put_domains[i]) |
| 5195 | modeset_put_power_domains(dev_priv, put_domains[i]); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5196 | } |
| 5197 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5198 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
| 5199 | { |
| 5200 | int max_cdclk_freq = dev_priv->max_cdclk_freq; |
| 5201 | |
| 5202 | if (INTEL_INFO(dev_priv)->gen >= 9 || |
| 5203 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 5204 | return max_cdclk_freq; |
| 5205 | else if (IS_CHERRYVIEW(dev_priv)) |
| 5206 | return max_cdclk_freq*95/100; |
| 5207 | else if (INTEL_INFO(dev_priv)->gen < 4) |
| 5208 | return 2*max_cdclk_freq*90/100; |
| 5209 | else |
| 5210 | return max_cdclk_freq*90/100; |
| 5211 | } |
| 5212 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5213 | static void intel_update_max_cdclk(struct drm_device *dev) |
| 5214 | { |
| 5215 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5216 | |
| 5217 | if (IS_SKYLAKE(dev)) { |
| 5218 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
| 5219 | |
| 5220 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
| 5221 | dev_priv->max_cdclk_freq = 675000; |
| 5222 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
| 5223 | dev_priv->max_cdclk_freq = 540000; |
| 5224 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
| 5225 | dev_priv->max_cdclk_freq = 450000; |
| 5226 | else |
| 5227 | dev_priv->max_cdclk_freq = 337500; |
| 5228 | } else if (IS_BROADWELL(dev)) { |
| 5229 | /* |
| 5230 | * FIXME with extra cooling we can allow |
| 5231 | * 540 MHz for ULX and 675 Mhz for ULT. |
| 5232 | * How can we know if extra cooling is |
| 5233 | * available? PCI ID, VTB, something else? |
| 5234 | */ |
| 5235 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 5236 | dev_priv->max_cdclk_freq = 450000; |
| 5237 | else if (IS_BDW_ULX(dev)) |
| 5238 | dev_priv->max_cdclk_freq = 450000; |
| 5239 | else if (IS_BDW_ULT(dev)) |
| 5240 | dev_priv->max_cdclk_freq = 540000; |
| 5241 | else |
| 5242 | dev_priv->max_cdclk_freq = 675000; |
Mika Kahola | 0904dea | 2015-06-12 10:11:32 +0300 | [diff] [blame] | 5243 | } else if (IS_CHERRYVIEW(dev)) { |
| 5244 | dev_priv->max_cdclk_freq = 320000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5245 | } else if (IS_VALLEYVIEW(dev)) { |
| 5246 | dev_priv->max_cdclk_freq = 400000; |
| 5247 | } else { |
| 5248 | /* otherwise assume cdclk is fixed */ |
| 5249 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; |
| 5250 | } |
| 5251 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5252 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
| 5253 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5254 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
| 5255 | dev_priv->max_cdclk_freq); |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5256 | |
| 5257 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", |
| 5258 | dev_priv->max_dotclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | static void intel_update_cdclk(struct drm_device *dev) |
| 5262 | { |
| 5263 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5264 | |
| 5265 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
| 5266 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
| 5267 | dev_priv->cdclk_freq); |
| 5268 | |
| 5269 | /* |
| 5270 | * Program the gmbus_freq based on the cdclk frequency. |
| 5271 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5272 | * in fact 1MHz is the correct frequency. |
| 5273 | */ |
| 5274 | if (IS_VALLEYVIEW(dev)) { |
| 5275 | /* |
| 5276 | * Program the gmbus_freq based on the cdclk frequency. |
| 5277 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5278 | * in fact 1MHz is the correct frequency. |
| 5279 | */ |
| 5280 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
| 5281 | } |
| 5282 | |
| 5283 | if (dev_priv->max_cdclk_freq == 0) |
| 5284 | intel_update_max_cdclk(dev); |
| 5285 | } |
| 5286 | |
Damien Lespiau | 70d0c57 | 2015-06-04 18:21:29 +0100 | [diff] [blame] | 5287 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5288 | { |
| 5289 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5290 | uint32_t divider; |
| 5291 | uint32_t ratio; |
| 5292 | uint32_t current_freq; |
| 5293 | int ret; |
| 5294 | |
| 5295 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ |
| 5296 | switch (frequency) { |
| 5297 | case 144000: |
| 5298 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
| 5299 | ratio = BXT_DE_PLL_RATIO(60); |
| 5300 | break; |
| 5301 | case 288000: |
| 5302 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
| 5303 | ratio = BXT_DE_PLL_RATIO(60); |
| 5304 | break; |
| 5305 | case 384000: |
| 5306 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
| 5307 | ratio = BXT_DE_PLL_RATIO(60); |
| 5308 | break; |
| 5309 | case 576000: |
| 5310 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5311 | ratio = BXT_DE_PLL_RATIO(60); |
| 5312 | break; |
| 5313 | case 624000: |
| 5314 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5315 | ratio = BXT_DE_PLL_RATIO(65); |
| 5316 | break; |
| 5317 | case 19200: |
| 5318 | /* |
| 5319 | * Bypass frequency with DE PLL disabled. Init ratio, divider |
| 5320 | * to suppress GCC warning. |
| 5321 | */ |
| 5322 | ratio = 0; |
| 5323 | divider = 0; |
| 5324 | break; |
| 5325 | default: |
| 5326 | DRM_ERROR("unsupported CDCLK freq %d", frequency); |
| 5327 | |
| 5328 | return; |
| 5329 | } |
| 5330 | |
| 5331 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5332 | /* Inform power controller of upcoming frequency change */ |
| 5333 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5334 | 0x80000000); |
| 5335 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5336 | |
| 5337 | if (ret) { |
| 5338 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
| 5339 | ret, frequency); |
| 5340 | return; |
| 5341 | } |
| 5342 | |
| 5343 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; |
| 5344 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ |
| 5345 | current_freq = current_freq * 500 + 1000; |
| 5346 | |
| 5347 | /* |
| 5348 | * DE PLL has to be disabled when |
| 5349 | * - setting to 19.2MHz (bypass, PLL isn't used) |
| 5350 | * - before setting to 624MHz (PLL needs toggling) |
| 5351 | * - before setting to any frequency from 624MHz (PLL needs toggling) |
| 5352 | */ |
| 5353 | if (frequency == 19200 || frequency == 624000 || |
| 5354 | current_freq == 624000) { |
| 5355 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); |
| 5356 | /* Timeout 200us */ |
| 5357 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), |
| 5358 | 1)) |
| 5359 | DRM_ERROR("timout waiting for DE PLL unlock\n"); |
| 5360 | } |
| 5361 | |
| 5362 | if (frequency != 19200) { |
| 5363 | uint32_t val; |
| 5364 | |
| 5365 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5366 | val &= ~BXT_DE_PLL_RATIO_MASK; |
| 5367 | val |= ratio; |
| 5368 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5369 | |
| 5370 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5371 | /* Timeout 200us */ |
| 5372 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) |
| 5373 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
| 5374 | |
| 5375 | val = I915_READ(CDCLK_CTL); |
| 5376 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; |
| 5377 | val |= divider; |
| 5378 | /* |
| 5379 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5380 | * enable otherwise. |
| 5381 | */ |
| 5382 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5383 | if (frequency >= 500000) |
| 5384 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5385 | |
| 5386 | val &= ~CDCLK_FREQ_DECIMAL_MASK; |
| 5387 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5388 | val |= (frequency - 1000) / 500; |
| 5389 | I915_WRITE(CDCLK_CTL, val); |
| 5390 | } |
| 5391 | |
| 5392 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5393 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5394 | DIV_ROUND_UP(frequency, 25000)); |
| 5395 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5396 | |
| 5397 | if (ret) { |
| 5398 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
| 5399 | ret, frequency); |
| 5400 | return; |
| 5401 | } |
| 5402 | |
Damien Lespiau | a47871b | 2015-06-04 18:21:34 +0100 | [diff] [blame] | 5403 | intel_update_cdclk(dev); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | void broxton_init_cdclk(struct drm_device *dev) |
| 5407 | { |
| 5408 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5409 | uint32_t val; |
| 5410 | |
| 5411 | /* |
| 5412 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT |
| 5413 | * or else the reset will hang because there is no PCH to respond. |
| 5414 | * Move the handshake programming to initialization sequence. |
| 5415 | * Previously was left up to BIOS. |
| 5416 | */ |
| 5417 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 5418 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; |
| 5419 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); |
| 5420 | |
| 5421 | /* Enable PG1 for cdclk */ |
| 5422 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 5423 | |
| 5424 | /* check if cd clock is enabled */ |
| 5425 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { |
| 5426 | DRM_DEBUG_KMS("Display already initialized\n"); |
| 5427 | return; |
| 5428 | } |
| 5429 | |
| 5430 | /* |
| 5431 | * FIXME: |
| 5432 | * - The initial CDCLK needs to be read from VBT. |
| 5433 | * Need to make this change after VBT has changes for BXT. |
| 5434 | * - check if setting the max (or any) cdclk freq is really necessary |
| 5435 | * here, it belongs to modeset time |
| 5436 | */ |
| 5437 | broxton_set_cdclk(dev, 624000); |
| 5438 | |
| 5439 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5440 | POSTING_READ(DBUF_CTL); |
| 5441 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5442 | udelay(10); |
| 5443 | |
| 5444 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5445 | DRM_ERROR("DBuf power enable timeout!\n"); |
| 5446 | } |
| 5447 | |
| 5448 | void broxton_uninit_cdclk(struct drm_device *dev) |
| 5449 | { |
| 5450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5451 | |
| 5452 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5453 | POSTING_READ(DBUF_CTL); |
| 5454 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5455 | udelay(10); |
| 5456 | |
| 5457 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5458 | DRM_ERROR("DBuf power disable timeout!\n"); |
| 5459 | |
| 5460 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ |
| 5461 | broxton_set_cdclk(dev, 19200); |
| 5462 | |
| 5463 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
| 5464 | } |
| 5465 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5466 | static const struct skl_cdclk_entry { |
| 5467 | unsigned int freq; |
| 5468 | unsigned int vco; |
| 5469 | } skl_cdclk_frequencies[] = { |
| 5470 | { .freq = 308570, .vco = 8640 }, |
| 5471 | { .freq = 337500, .vco = 8100 }, |
| 5472 | { .freq = 432000, .vco = 8640 }, |
| 5473 | { .freq = 450000, .vco = 8100 }, |
| 5474 | { .freq = 540000, .vco = 8100 }, |
| 5475 | { .freq = 617140, .vco = 8640 }, |
| 5476 | { .freq = 675000, .vco = 8100 }, |
| 5477 | }; |
| 5478 | |
| 5479 | static unsigned int skl_cdclk_decimal(unsigned int freq) |
| 5480 | { |
| 5481 | return (freq - 1000) / 500; |
| 5482 | } |
| 5483 | |
| 5484 | static unsigned int skl_cdclk_get_vco(unsigned int freq) |
| 5485 | { |
| 5486 | unsigned int i; |
| 5487 | |
| 5488 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { |
| 5489 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; |
| 5490 | |
| 5491 | if (e->freq == freq) |
| 5492 | return e->vco; |
| 5493 | } |
| 5494 | |
| 5495 | return 8100; |
| 5496 | } |
| 5497 | |
| 5498 | static void |
| 5499 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) |
| 5500 | { |
| 5501 | unsigned int min_freq; |
| 5502 | u32 val; |
| 5503 | |
| 5504 | /* select the minimum CDCLK before enabling DPLL 0 */ |
| 5505 | val = I915_READ(CDCLK_CTL); |
| 5506 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; |
| 5507 | val |= CDCLK_FREQ_337_308; |
| 5508 | |
| 5509 | if (required_vco == 8640) |
| 5510 | min_freq = 308570; |
| 5511 | else |
| 5512 | min_freq = 337500; |
| 5513 | |
| 5514 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); |
| 5515 | |
| 5516 | I915_WRITE(CDCLK_CTL, val); |
| 5517 | POSTING_READ(CDCLK_CTL); |
| 5518 | |
| 5519 | /* |
| 5520 | * We always enable DPLL0 with the lowest link rate possible, but still |
| 5521 | * taking into account the VCO required to operate the eDP panel at the |
| 5522 | * desired frequency. The usual DP link rates operate with a VCO of |
| 5523 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. |
| 5524 | * The modeset code is responsible for the selection of the exact link |
| 5525 | * rate later on, with the constraint of choosing a frequency that |
| 5526 | * works with required_vco. |
| 5527 | */ |
| 5528 | val = I915_READ(DPLL_CTRL1); |
| 5529 | |
| 5530 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 5531 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
| 5532 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); |
| 5533 | if (required_vco == 8640) |
| 5534 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
| 5535 | SKL_DPLL0); |
| 5536 | else |
| 5537 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
| 5538 | SKL_DPLL0); |
| 5539 | |
| 5540 | I915_WRITE(DPLL_CTRL1, val); |
| 5541 | POSTING_READ(DPLL_CTRL1); |
| 5542 | |
| 5543 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); |
| 5544 | |
| 5545 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) |
| 5546 | DRM_ERROR("DPLL0 not locked\n"); |
| 5547 | } |
| 5548 | |
| 5549 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) |
| 5550 | { |
| 5551 | int ret; |
| 5552 | u32 val; |
| 5553 | |
| 5554 | /* inform PCU we want to change CDCLK */ |
| 5555 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; |
| 5556 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5557 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); |
| 5558 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5559 | |
| 5560 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); |
| 5561 | } |
| 5562 | |
| 5563 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) |
| 5564 | { |
| 5565 | unsigned int i; |
| 5566 | |
| 5567 | for (i = 0; i < 15; i++) { |
| 5568 | if (skl_cdclk_pcu_ready(dev_priv)) |
| 5569 | return true; |
| 5570 | udelay(10); |
| 5571 | } |
| 5572 | |
| 5573 | return false; |
| 5574 | } |
| 5575 | |
| 5576 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) |
| 5577 | { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5578 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5579 | u32 freq_select, pcu_ack; |
| 5580 | |
| 5581 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); |
| 5582 | |
| 5583 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { |
| 5584 | DRM_ERROR("failed to inform PCU about cdclk change\n"); |
| 5585 | return; |
| 5586 | } |
| 5587 | |
| 5588 | /* set CDCLK_CTL */ |
| 5589 | switch(freq) { |
| 5590 | case 450000: |
| 5591 | case 432000: |
| 5592 | freq_select = CDCLK_FREQ_450_432; |
| 5593 | pcu_ack = 1; |
| 5594 | break; |
| 5595 | case 540000: |
| 5596 | freq_select = CDCLK_FREQ_540; |
| 5597 | pcu_ack = 2; |
| 5598 | break; |
| 5599 | case 308570: |
| 5600 | case 337500: |
| 5601 | default: |
| 5602 | freq_select = CDCLK_FREQ_337_308; |
| 5603 | pcu_ack = 0; |
| 5604 | break; |
| 5605 | case 617140: |
| 5606 | case 675000: |
| 5607 | freq_select = CDCLK_FREQ_675_617; |
| 5608 | pcu_ack = 3; |
| 5609 | break; |
| 5610 | } |
| 5611 | |
| 5612 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); |
| 5613 | POSTING_READ(CDCLK_CTL); |
| 5614 | |
| 5615 | /* inform PCU of the change */ |
| 5616 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5617 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); |
| 5618 | mutex_unlock(&dev_priv->rps.hw_lock); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5619 | |
| 5620 | intel_update_cdclk(dev); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
| 5624 | { |
| 5625 | /* disable DBUF power */ |
| 5626 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
| 5627 | POSTING_READ(DBUF_CTL); |
| 5628 | |
| 5629 | udelay(10); |
| 5630 | |
| 5631 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5632 | DRM_ERROR("DBuf power disable timeout\n"); |
| 5633 | |
| 5634 | /* disable DPLL0 */ |
| 5635 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); |
| 5636 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) |
| 5637 | DRM_ERROR("Couldn't disable DPLL0\n"); |
| 5638 | |
| 5639 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
| 5640 | } |
| 5641 | |
| 5642 | void skl_init_cdclk(struct drm_i915_private *dev_priv) |
| 5643 | { |
| 5644 | u32 val; |
| 5645 | unsigned int required_vco; |
| 5646 | |
| 5647 | /* enable PCH reset handshake */ |
| 5648 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 5649 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); |
| 5650 | |
| 5651 | /* enable PG1 and Misc I/O */ |
| 5652 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 5653 | |
| 5654 | /* DPLL0 already enabed !? */ |
| 5655 | if (I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE) { |
| 5656 | DRM_DEBUG_DRIVER("DPLL0 already running\n"); |
| 5657 | return; |
| 5658 | } |
| 5659 | |
| 5660 | /* enable DPLL0 */ |
| 5661 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); |
| 5662 | skl_dpll0_enable(dev_priv, required_vco); |
| 5663 | |
| 5664 | /* set CDCLK to the frequency the BIOS chose */ |
| 5665 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); |
| 5666 | |
| 5667 | /* enable DBUF power */ |
| 5668 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
| 5669 | POSTING_READ(DBUF_CTL); |
| 5670 | |
| 5671 | udelay(10); |
| 5672 | |
| 5673 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5674 | DRM_ERROR("DBuf power enable timeout\n"); |
| 5675 | } |
| 5676 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5677 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5678 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5679 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5680 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5681 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5682 | /* Obtain SKU information */ |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5683 | mutex_lock(&dev_priv->sb_lock); |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5684 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 5685 | CCK_FUSE_HPLL_FREQ_MASK; |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5686 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5687 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5688 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5692 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5693 | { |
| 5694 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5695 | u32 val, cmd; |
| 5696 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5697 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5698 | != dev_priv->cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5699 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5700 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5701 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5702 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5703 | cmd = 1; |
| 5704 | else |
| 5705 | cmd = 0; |
| 5706 | |
| 5707 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5708 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5709 | val &= ~DSPFREQGUAR_MASK; |
| 5710 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5711 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5712 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5713 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5714 | 50)) { |
| 5715 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5716 | } |
| 5717 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5718 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5719 | mutex_lock(&dev_priv->sb_lock); |
| 5720 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5721 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5722 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5723 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5724 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5725 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5726 | /* adjust cdclk divider */ |
| 5727 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 5728 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5729 | val |= divider; |
| 5730 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5731 | |
| 5732 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 5733 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5734 | 50)) |
| 5735 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5736 | } |
| 5737 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5738 | /* adjust self-refresh exit latency value */ |
| 5739 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5740 | val &= ~0x7f; |
| 5741 | |
| 5742 | /* |
| 5743 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5744 | * so that the core display fetch happens in time to avoid underruns. |
| 5745 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5746 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5747 | val |= 4500 / 250; /* 4.5 usec */ |
| 5748 | else |
| 5749 | val |= 3000 / 250; /* 3.0 usec */ |
| 5750 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5751 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5752 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5753 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5754 | intel_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5755 | } |
| 5756 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5757 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5758 | { |
| 5759 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5760 | u32 val, cmd; |
| 5761 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5762 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5763 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5764 | |
| 5765 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5766 | case 333333: |
| 5767 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5768 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5769 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5770 | break; |
| 5771 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5772 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5773 | return; |
| 5774 | } |
| 5775 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5776 | /* |
| 5777 | * Specs are full of misinformation, but testing on actual |
| 5778 | * hardware has shown that we just need to write the desired |
| 5779 | * CCK divider into the Punit register. |
| 5780 | */ |
| 5781 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5782 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5783 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5784 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5785 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5786 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5787 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5788 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5789 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5790 | 50)) { |
| 5791 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5792 | } |
| 5793 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5794 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5795 | intel_update_cdclk(dev); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5796 | } |
| 5797 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5798 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5799 | int max_pixclk) |
| 5800 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5801 | 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] | 5802 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5803 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5804 | /* |
| 5805 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5806 | * 200MHz |
| 5807 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5808 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5809 | * 400MHz (VLV only) |
| 5810 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5811 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5812 | * |
| 5813 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5814 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5815 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5816 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5817 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5818 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5819 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5820 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5821 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5822 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5823 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5824 | else |
| 5825 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5828 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5829 | int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5830 | { |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5831 | /* |
| 5832 | * FIXME: |
| 5833 | * - remove the guardband, it's not needed on BXT |
| 5834 | * - set 19.2MHz bypass frequency if there are no active pipes |
| 5835 | */ |
| 5836 | if (max_pixclk > 576000*9/10) |
| 5837 | return 624000; |
| 5838 | else if (max_pixclk > 384000*9/10) |
| 5839 | return 576000; |
| 5840 | else if (max_pixclk > 288000*9/10) |
| 5841 | return 384000; |
| 5842 | else if (max_pixclk > 144000*9/10) |
| 5843 | return 288000; |
| 5844 | else |
| 5845 | return 144000; |
| 5846 | } |
| 5847 | |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5848 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
| 5849 | * that's non-NULL, look at current state otherwise. */ |
| 5850 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 5851 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5852 | { |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5853 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5854 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5855 | int max_pixclk = 0; |
| 5856 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5857 | for_each_intel_crtc(dev, intel_crtc) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5858 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5859 | if (IS_ERR(crtc_state)) |
| 5860 | return PTR_ERR(crtc_state); |
| 5861 | |
| 5862 | if (!crtc_state->base.enable) |
| 5863 | continue; |
| 5864 | |
| 5865 | max_pixclk = max(max_pixclk, |
| 5866 | crtc_state->base.adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | return max_pixclk; |
| 5870 | } |
| 5871 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5872 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5873 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5874 | struct drm_device *dev = state->dev; |
| 5875 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5876 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5877 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5878 | if (max_pixclk < 0) |
| 5879 | return max_pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5880 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5881 | to_intel_atomic_state(state)->cdclk = |
| 5882 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5883 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5884 | return 0; |
| 5885 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5886 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5887 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 5888 | { |
| 5889 | struct drm_device *dev = state->dev; |
| 5890 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5891 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5892 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5893 | if (max_pixclk < 0) |
| 5894 | return max_pixclk; |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5895 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5896 | to_intel_atomic_state(state)->cdclk = |
| 5897 | broxton_calc_cdclk(dev_priv, max_pixclk); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5898 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5899 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5900 | } |
| 5901 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5902 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5903 | { |
| 5904 | unsigned int credits, default_credits; |
| 5905 | |
| 5906 | if (IS_CHERRYVIEW(dev_priv)) |
| 5907 | default_credits = PFI_CREDIT(12); |
| 5908 | else |
| 5909 | default_credits = PFI_CREDIT(8); |
| 5910 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5911 | 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] | 5912 | /* CHV suggested value is 31 or 63 */ |
| 5913 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | fcc0008 | 2015-05-26 20:22:40 +0300 | [diff] [blame] | 5914 | credits = PFI_CREDIT_63; |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5915 | else |
| 5916 | credits = PFI_CREDIT(15); |
| 5917 | } else { |
| 5918 | credits = default_credits; |
| 5919 | } |
| 5920 | |
| 5921 | /* |
| 5922 | * WA - write default credits before re-programming |
| 5923 | * FIXME: should we also set the resend bit here? |
| 5924 | */ |
| 5925 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5926 | default_credits); |
| 5927 | |
| 5928 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5929 | credits | PFI_CREDIT_RESEND); |
| 5930 | |
| 5931 | /* |
| 5932 | * FIXME is this guaranteed to clear |
| 5933 | * immediately or should we poll for it? |
| 5934 | */ |
| 5935 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 5936 | } |
| 5937 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5938 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5939 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5940 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5941 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5942 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5943 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5944 | /* |
| 5945 | * FIXME: We can end up here with all power domains off, yet |
| 5946 | * with a CDCLK frequency other than the minimum. To account |
| 5947 | * for this take the PIPE-A power domain, which covers the HW |
| 5948 | * blocks needed for the following programming. This can be |
| 5949 | * removed once it's guaranteed that we get here either with |
| 5950 | * the minimum CDCLK set, or the required power domains |
| 5951 | * enabled. |
| 5952 | */ |
| 5953 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5954 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5955 | if (IS_CHERRYVIEW(dev)) |
| 5956 | cherryview_set_cdclk(dev, req_cdclk); |
| 5957 | else |
| 5958 | valleyview_set_cdclk(dev, req_cdclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5959 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5960 | vlv_program_pfi_credits(dev_priv); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5961 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5962 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5963 | } |
| 5964 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5965 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 5966 | { |
| 5967 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5968 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5969 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5970 | struct intel_encoder *encoder; |
| 5971 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 5972 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5973 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5974 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5975 | return; |
| 5976 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5977 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 5978 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5979 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5980 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5981 | |
| 5982 | intel_set_pipe_timings(intel_crtc); |
| 5983 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5984 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 5985 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5986 | |
| 5987 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5988 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5989 | } |
| 5990 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5991 | i9xx_set_pipeconf(intel_crtc); |
| 5992 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5993 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5994 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5995 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5996 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5997 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5998 | if (encoder->pre_pll_enable) |
| 5999 | encoder->pre_pll_enable(encoder); |
| 6000 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6001 | if (!is_dsi) { |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6002 | if (IS_CHERRYVIEW(dev)) { |
| 6003 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6004 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6005 | } else { |
| 6006 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6007 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6008 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6009 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6010 | |
| 6011 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6012 | if (encoder->pre_enable) |
| 6013 | encoder->pre_enable(encoder); |
| 6014 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6015 | i9xx_pfit_enable(intel_crtc); |
| 6016 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6017 | intel_crtc_load_lut(crtc); |
| 6018 | |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6019 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6020 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6021 | assert_vblank_disabled(crtc); |
| 6022 | drm_crtc_vblank_on(crtc); |
| 6023 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6024 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6025 | encoder->enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6026 | } |
| 6027 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6028 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 6029 | { |
| 6030 | struct drm_device *dev = crtc->base.dev; |
| 6031 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6032 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6033 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 6034 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6035 | } |
| 6036 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6037 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6038 | { |
| 6039 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6040 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6041 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6042 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6043 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6044 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6045 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6046 | return; |
| 6047 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6048 | i9xx_set_pll_dividers(intel_crtc); |
| 6049 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6050 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6051 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6052 | |
| 6053 | intel_set_pipe_timings(intel_crtc); |
| 6054 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6055 | i9xx_set_pipeconf(intel_crtc); |
| 6056 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6057 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6058 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6059 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6060 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6061 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 6062 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6063 | if (encoder->pre_enable) |
| 6064 | encoder->pre_enable(encoder); |
| 6065 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6066 | i9xx_enable_pll(intel_crtc); |
| 6067 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6068 | i9xx_pfit_enable(intel_crtc); |
| 6069 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6070 | intel_crtc_load_lut(crtc); |
| 6071 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 6072 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6073 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6074 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6075 | assert_vblank_disabled(crtc); |
| 6076 | drm_crtc_vblank_on(crtc); |
| 6077 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6078 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6079 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6080 | } |
| 6081 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6082 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6083 | { |
| 6084 | struct drm_device *dev = crtc->base.dev; |
| 6085 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6086 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6087 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6088 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6089 | |
| 6090 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6091 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6092 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6093 | I915_READ(PFIT_CONTROL)); |
| 6094 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6095 | } |
| 6096 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6097 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 6098 | { |
| 6099 | struct drm_device *dev = crtc->dev; |
| 6100 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6101 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6102 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6103 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6104 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6105 | /* |
| 6106 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6107 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 6108 | * We also need to wait on all gmch platforms because of the |
| 6109 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6110 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 6111 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6112 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6113 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6114 | encoder->disable(encoder); |
| 6115 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6116 | drm_crtc_vblank_off(crtc); |
| 6117 | assert_vblank_disabled(crtc); |
| 6118 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6119 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6120 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6121 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6122 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6123 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6124 | if (encoder->post_disable) |
| 6125 | encoder->post_disable(encoder); |
| 6126 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6127 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6128 | if (IS_CHERRYVIEW(dev)) |
| 6129 | chv_disable_pll(dev_priv, pipe); |
| 6130 | else if (IS_VALLEYVIEW(dev)) |
| 6131 | vlv_disable_pll(dev_priv, pipe); |
| 6132 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6133 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6134 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6135 | |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6136 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6137 | if (encoder->post_pll_disable) |
| 6138 | encoder->post_pll_disable(encoder); |
| 6139 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6140 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6141 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Patrik Jakobsson | e4ca061 | 2015-07-08 15:31:52 +0200 | [diff] [blame] | 6142 | |
| 6143 | intel_crtc->active = false; |
| 6144 | intel_update_watermarks(crtc); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6145 | } |
| 6146 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6147 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6148 | { |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6149 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6150 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6151 | enum intel_display_power_domain domain; |
| 6152 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6153 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6154 | if (!intel_crtc->active) |
| 6155 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6156 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6157 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
| 6158 | intel_crtc_wait_for_pending_flips(crtc); |
| 6159 | intel_pre_disable_primary(crtc); |
| 6160 | } |
| 6161 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 6162 | intel_crtc_disable_planes(crtc, crtc->state->plane_mask); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6163 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6164 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6165 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6166 | domains = intel_crtc->enabled_power_domains; |
| 6167 | for_each_power_domain(domain, domains) |
| 6168 | intel_display_power_put(dev_priv, domain); |
| 6169 | intel_crtc->enabled_power_domains = 0; |
| 6170 | } |
| 6171 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6172 | /* |
| 6173 | * turn all crtc's off, but do not adjust state |
| 6174 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6175 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6176 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6177 | { |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6178 | struct drm_mode_config *config = &dev->mode_config; |
| 6179 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; |
| 6180 | struct drm_atomic_state *state; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6181 | struct drm_crtc *crtc; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6182 | unsigned crtc_mask = 0; |
| 6183 | int ret = 0; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6184 | |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6185 | if (WARN_ON(!ctx)) |
| 6186 | return 0; |
| 6187 | |
| 6188 | lockdep_assert_held(&ctx->ww_ctx); |
| 6189 | state = drm_atomic_state_alloc(dev); |
| 6190 | if (WARN_ON(!state)) |
| 6191 | return -ENOMEM; |
| 6192 | |
| 6193 | state->acquire_ctx = ctx; |
| 6194 | state->allow_modeset = true; |
| 6195 | |
| 6196 | for_each_crtc(dev, crtc) { |
| 6197 | struct drm_crtc_state *crtc_state = |
| 6198 | drm_atomic_get_crtc_state(state, crtc); |
| 6199 | |
| 6200 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 6201 | if (ret) |
| 6202 | goto free; |
| 6203 | |
| 6204 | if (!crtc_state->active) |
| 6205 | continue; |
| 6206 | |
| 6207 | crtc_state->active = false; |
| 6208 | crtc_mask |= 1 << drm_crtc_index(crtc); |
| 6209 | } |
| 6210 | |
| 6211 | if (crtc_mask) { |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 6212 | ret = drm_atomic_commit(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6213 | |
| 6214 | if (!ret) { |
| 6215 | for_each_crtc(dev, crtc) |
| 6216 | if (crtc_mask & (1 << drm_crtc_index(crtc))) |
| 6217 | crtc->state->active = true; |
| 6218 | |
| 6219 | return ret; |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | free: |
| 6224 | if (ret) |
| 6225 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
| 6226 | drm_atomic_state_free(state); |
| 6227 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6228 | } |
| 6229 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6230 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6231 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6232 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6233 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6234 | drm_encoder_cleanup(encoder); |
| 6235 | kfree(intel_encoder); |
| 6236 | } |
| 6237 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6238 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6239 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 6240 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6241 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6242 | struct drm_crtc *crtc = connector->base.state->crtc; |
| 6243 | |
| 6244 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6245 | connector->base.base.id, |
| 6246 | connector->base.name); |
| 6247 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6248 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6249 | struct drm_encoder *encoder = &connector->encoder->base; |
| 6250 | struct drm_connector_state *conn_state = connector->base.state; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6251 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6252 | I915_STATE_WARN(!crtc, |
| 6253 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6254 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6255 | if (!crtc) |
| 6256 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6257 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6258 | I915_STATE_WARN(!crtc->state->active, |
| 6259 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6260 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6261 | if (!encoder) |
| 6262 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6263 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6264 | I915_STATE_WARN(conn_state->best_encoder != encoder, |
| 6265 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6266 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6267 | I915_STATE_WARN(conn_state->crtc != encoder->crtc, |
| 6268 | "attached encoder crtc differs from connector crtc\n"); |
| 6269 | } else { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6270 | I915_STATE_WARN(crtc && crtc->state->active, |
| 6271 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6272 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
| 6273 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6274 | } |
| 6275 | } |
| 6276 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6277 | int intel_connector_init(struct intel_connector *connector) |
| 6278 | { |
| 6279 | struct drm_connector_state *connector_state; |
| 6280 | |
| 6281 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); |
| 6282 | if (!connector_state) |
| 6283 | return -ENOMEM; |
| 6284 | |
| 6285 | connector->base.state = connector_state; |
| 6286 | return 0; |
| 6287 | } |
| 6288 | |
| 6289 | struct intel_connector *intel_connector_alloc(void) |
| 6290 | { |
| 6291 | struct intel_connector *connector; |
| 6292 | |
| 6293 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6294 | if (!connector) |
| 6295 | return NULL; |
| 6296 | |
| 6297 | if (intel_connector_init(connector) < 0) { |
| 6298 | kfree(connector); |
| 6299 | return NULL; |
| 6300 | } |
| 6301 | |
| 6302 | return connector; |
| 6303 | } |
| 6304 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6305 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6306 | * one connector and no cloning and hence the encoder state determines the state |
| 6307 | * of the connector. */ |
| 6308 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6309 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6310 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6311 | struct intel_encoder *encoder = connector->encoder; |
| 6312 | |
| 6313 | return encoder->get_hw_state(encoder, &pipe); |
| 6314 | } |
| 6315 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6316 | 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] | 6317 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6318 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6319 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6320 | |
| 6321 | return 0; |
| 6322 | } |
| 6323 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6324 | 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] | 6325 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6326 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6327 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6328 | struct intel_crtc *other_crtc; |
| 6329 | struct intel_crtc_state *other_crtc_state; |
| 6330 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6331 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6332 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6333 | if (pipe_config->fdi_lanes > 4) { |
| 6334 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6335 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6336 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6337 | } |
| 6338 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 6339 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6340 | if (pipe_config->fdi_lanes > 2) { |
| 6341 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6342 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6343 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6344 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6345 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6346 | } |
| 6347 | } |
| 6348 | |
| 6349 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6350 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6351 | |
| 6352 | /* Ivybridge 3 pipe is really complicated */ |
| 6353 | switch (pipe) { |
| 6354 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6355 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6356 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6357 | if (pipe_config->fdi_lanes <= 2) |
| 6358 | return 0; |
| 6359 | |
| 6360 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 6361 | other_crtc_state = |
| 6362 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6363 | if (IS_ERR(other_crtc_state)) |
| 6364 | return PTR_ERR(other_crtc_state); |
| 6365 | |
| 6366 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6367 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6368 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6369 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6370 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6371 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6372 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6373 | if (pipe_config->fdi_lanes > 2) { |
| 6374 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6375 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6376 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6377 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6378 | |
| 6379 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 6380 | other_crtc_state = |
| 6381 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6382 | if (IS_ERR(other_crtc_state)) |
| 6383 | return PTR_ERR(other_crtc_state); |
| 6384 | |
| 6385 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6386 | 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] | 6387 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6388 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6389 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6390 | default: |
| 6391 | BUG(); |
| 6392 | } |
| 6393 | } |
| 6394 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6395 | #define RETRY 1 |
| 6396 | 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] | 6397 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6398 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6399 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6400 | 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] | 6401 | int lane, link_bw, fdi_dotclock, ret; |
| 6402 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6403 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6404 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6405 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6406 | * each output octet as 10 bits. The actual frequency |
| 6407 | * is stored as a divider into a 100MHz clock, and the |
| 6408 | * mode pixel clock is stored in units of 1KHz. |
| 6409 | * Hence the bw of each lane in terms of the mode signal |
| 6410 | * is: |
| 6411 | */ |
| 6412 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 6413 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6414 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6415 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6416 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6417 | pipe_config->pipe_bpp); |
| 6418 | |
| 6419 | pipe_config->fdi_lanes = lane; |
| 6420 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6421 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6422 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6423 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6424 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 6425 | intel_crtc->pipe, pipe_config); |
| 6426 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6427 | pipe_config->pipe_bpp -= 2*3; |
| 6428 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6429 | pipe_config->pipe_bpp); |
| 6430 | needs_recompute = true; |
| 6431 | pipe_config->bw_constrained = true; |
| 6432 | |
| 6433 | goto retry; |
| 6434 | } |
| 6435 | |
| 6436 | if (needs_recompute) |
| 6437 | return RETRY; |
| 6438 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6439 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6440 | } |
| 6441 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6442 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
| 6443 | struct intel_crtc_state *pipe_config) |
| 6444 | { |
| 6445 | if (pipe_config->pipe_bpp > 24) |
| 6446 | return false; |
| 6447 | |
| 6448 | /* HSW can handle pixel rate up to cdclk? */ |
| 6449 | if (IS_HASWELL(dev_priv->dev)) |
| 6450 | return true; |
| 6451 | |
| 6452 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6453 | * We compare against max which means we must take |
| 6454 | * the increased cdclk requirement into account when |
| 6455 | * calculating the new cdclk. |
| 6456 | * |
| 6457 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6458 | */ |
| 6459 | return ilk_pipe_pixel_rate(pipe_config) <= |
| 6460 | dev_priv->max_cdclk_freq * 95 / 100; |
| 6461 | } |
| 6462 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6463 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6464 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6465 | { |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6466 | struct drm_device *dev = crtc->base.dev; |
| 6467 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6468 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6469 | pipe_config->ips_enabled = i915.enable_ips && |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6470 | hsw_crtc_supports_ips(crtc) && |
| 6471 | pipe_config_supports_ips(dev_priv, pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6472 | } |
| 6473 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6474 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6475 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6476 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6477 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 6478 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6479 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6480 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6481 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6482 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4491315 | 2015-06-03 15:45:10 +0300 | [diff] [blame] | 6483 | int clock_limit = dev_priv->max_cdclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6484 | |
| 6485 | /* |
| 6486 | * Enable pixel doubling when the dot clock |
| 6487 | * is > 90% of the (display) core speed. |
| 6488 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 6489 | * GDG double wide on either pipe, |
| 6490 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6491 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 6492 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6493 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6494 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6495 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6496 | } |
| 6497 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6498 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6499 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6500 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6501 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6502 | /* |
| 6503 | * Pipe horizontal size must be even in: |
| 6504 | * - DVO ganged mode |
| 6505 | * - LVDS dual channel mode |
| 6506 | * - Double wide pipe |
| 6507 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6508 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6509 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 6510 | pipe_config->pipe_src_w &= ~1; |
| 6511 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6512 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6513 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6514 | */ |
| 6515 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 6516 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6517 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6518 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 6519 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6520 | hsw_compute_ips_config(crtc, pipe_config); |
| 6521 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6522 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6523 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6524 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6525 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6526 | } |
| 6527 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6528 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 6529 | { |
| 6530 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6531 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 6532 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6533 | uint32_t linkrate; |
| 6534 | |
Damien Lespiau | 414355a | 2015-06-04 18:21:31 +0100 | [diff] [blame] | 6535 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6536 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6537 | |
| 6538 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 6539 | return 540000; |
| 6540 | |
| 6541 | linkrate = (I915_READ(DPLL_CTRL1) & |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6542 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6543 | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6544 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
| 6545 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6546 | /* vco 8640 */ |
| 6547 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6548 | case CDCLK_FREQ_450_432: |
| 6549 | return 432000; |
| 6550 | case CDCLK_FREQ_337_308: |
| 6551 | return 308570; |
| 6552 | case CDCLK_FREQ_675_617: |
| 6553 | return 617140; |
| 6554 | default: |
| 6555 | WARN(1, "Unknown cd freq selection\n"); |
| 6556 | } |
| 6557 | } else { |
| 6558 | /* vco 8100 */ |
| 6559 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6560 | case CDCLK_FREQ_450_432: |
| 6561 | return 450000; |
| 6562 | case CDCLK_FREQ_337_308: |
| 6563 | return 337500; |
| 6564 | case CDCLK_FREQ_675_617: |
| 6565 | return 675000; |
| 6566 | default: |
| 6567 | WARN(1, "Unknown cd freq selection\n"); |
| 6568 | } |
| 6569 | } |
| 6570 | |
| 6571 | /* error case, do as if DPLL0 isn't enabled */ |
| 6572 | return 24000; |
| 6573 | } |
| 6574 | |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6575 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
| 6576 | { |
| 6577 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6578 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6579 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; |
| 6580 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); |
| 6581 | int cdclk; |
| 6582 | |
| 6583 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) |
| 6584 | return 19200; |
| 6585 | |
| 6586 | cdclk = 19200 * pll_ratio / 2; |
| 6587 | |
| 6588 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { |
| 6589 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
| 6590 | return cdclk; /* 576MHz or 624MHz */ |
| 6591 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
| 6592 | return cdclk * 2 / 3; /* 384MHz */ |
| 6593 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
| 6594 | return cdclk / 2; /* 288MHz */ |
| 6595 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
| 6596 | return cdclk / 4; /* 144MHz */ |
| 6597 | } |
| 6598 | |
| 6599 | /* error case, do as if DE PLL isn't enabled */ |
| 6600 | return 19200; |
| 6601 | } |
| 6602 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6603 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 6604 | { |
| 6605 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6606 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6607 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6608 | |
| 6609 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6610 | return 800000; |
| 6611 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6612 | return 450000; |
| 6613 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6614 | return 450000; |
| 6615 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6616 | return 540000; |
| 6617 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6618 | return 337500; |
| 6619 | else |
| 6620 | return 675000; |
| 6621 | } |
| 6622 | |
| 6623 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6624 | { |
| 6625 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6626 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6627 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6628 | |
| 6629 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6630 | return 800000; |
| 6631 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6632 | return 450000; |
| 6633 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6634 | return 450000; |
| 6635 | else if (IS_HSW_ULT(dev)) |
| 6636 | return 337500; |
| 6637 | else |
| 6638 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6639 | } |
| 6640 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6641 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6642 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6643 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6644 | u32 val; |
| 6645 | int divider; |
| 6646 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6647 | if (dev_priv->hpll_freq == 0) |
| 6648 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 6649 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6650 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6651 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6652 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6653 | |
| 6654 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 6655 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 6656 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 6657 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 6658 | "cdclk change in progress\n"); |
| 6659 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6660 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6661 | } |
| 6662 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6663 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6664 | { |
| 6665 | return 450000; |
| 6666 | } |
| 6667 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6668 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6669 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6670 | return 400000; |
| 6671 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6672 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6673 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 6674 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6675 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6676 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6677 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6678 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6679 | { |
| 6680 | return 200000; |
| 6681 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6682 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6683 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6684 | { |
| 6685 | u16 gcfgc = 0; |
| 6686 | |
| 6687 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6688 | |
| 6689 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6690 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6691 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6692 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6693 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6694 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6695 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6696 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6697 | return 200000; |
| 6698 | default: |
| 6699 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6700 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6701 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6702 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6703 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6704 | } |
| 6705 | } |
| 6706 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6707 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6708 | { |
| 6709 | u16 gcfgc = 0; |
| 6710 | |
| 6711 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6712 | |
| 6713 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6714 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6715 | else { |
| 6716 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6717 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6718 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6719 | default: |
| 6720 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6721 | return 190000; |
| 6722 | } |
| 6723 | } |
| 6724 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6725 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6726 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6727 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6728 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6729 | } |
| 6730 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6731 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6732 | { |
| 6733 | u16 hpllcc = 0; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6734 | |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 6735 | /* |
| 6736 | * 852GM/852GMV only supports 133 MHz and the HPLLCC |
| 6737 | * encoding is different :( |
| 6738 | * FIXME is this the right way to detect 852GM/852GMV? |
| 6739 | */ |
| 6740 | if (dev->pdev->revision == 0x1) |
| 6741 | return 133333; |
| 6742 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6743 | pci_bus_read_config_word(dev->pdev->bus, |
| 6744 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); |
| 6745 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6746 | /* Assume that the hardware is in the high speed state. This |
| 6747 | * should be the default. |
| 6748 | */ |
| 6749 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6750 | case GC_CLOCK_133_200: |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6751 | case GC_CLOCK_133_200_2: |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6752 | case GC_CLOCK_100_200: |
| 6753 | return 200000; |
| 6754 | case GC_CLOCK_166_250: |
| 6755 | return 250000; |
| 6756 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6757 | return 133333; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6758 | case GC_CLOCK_133_266: |
| 6759 | case GC_CLOCK_133_266_2: |
| 6760 | case GC_CLOCK_166_266: |
| 6761 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | /* Shouldn't happen */ |
| 6765 | return 0; |
| 6766 | } |
| 6767 | |
| 6768 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6769 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6770 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6771 | } |
| 6772 | |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6773 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
| 6774 | { |
| 6775 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6776 | static const unsigned int blb_vco[8] = { |
| 6777 | [0] = 3200000, |
| 6778 | [1] = 4000000, |
| 6779 | [2] = 5333333, |
| 6780 | [3] = 4800000, |
| 6781 | [4] = 6400000, |
| 6782 | }; |
| 6783 | static const unsigned int pnv_vco[8] = { |
| 6784 | [0] = 3200000, |
| 6785 | [1] = 4000000, |
| 6786 | [2] = 5333333, |
| 6787 | [3] = 4800000, |
| 6788 | [4] = 2666667, |
| 6789 | }; |
| 6790 | static const unsigned int cl_vco[8] = { |
| 6791 | [0] = 3200000, |
| 6792 | [1] = 4000000, |
| 6793 | [2] = 5333333, |
| 6794 | [3] = 6400000, |
| 6795 | [4] = 3333333, |
| 6796 | [5] = 3566667, |
| 6797 | [6] = 4266667, |
| 6798 | }; |
| 6799 | static const unsigned int elk_vco[8] = { |
| 6800 | [0] = 3200000, |
| 6801 | [1] = 4000000, |
| 6802 | [2] = 5333333, |
| 6803 | [3] = 4800000, |
| 6804 | }; |
| 6805 | static const unsigned int ctg_vco[8] = { |
| 6806 | [0] = 3200000, |
| 6807 | [1] = 4000000, |
| 6808 | [2] = 5333333, |
| 6809 | [3] = 6400000, |
| 6810 | [4] = 2666667, |
| 6811 | [5] = 4266667, |
| 6812 | }; |
| 6813 | const unsigned int *vco_table; |
| 6814 | unsigned int vco; |
| 6815 | uint8_t tmp = 0; |
| 6816 | |
| 6817 | /* FIXME other chipsets? */ |
| 6818 | if (IS_GM45(dev)) |
| 6819 | vco_table = ctg_vco; |
| 6820 | else if (IS_G4X(dev)) |
| 6821 | vco_table = elk_vco; |
| 6822 | else if (IS_CRESTLINE(dev)) |
| 6823 | vco_table = cl_vco; |
| 6824 | else if (IS_PINEVIEW(dev)) |
| 6825 | vco_table = pnv_vco; |
| 6826 | else if (IS_G33(dev)) |
| 6827 | vco_table = blb_vco; |
| 6828 | else |
| 6829 | return 0; |
| 6830 | |
| 6831 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); |
| 6832 | |
| 6833 | vco = vco_table[tmp & 0x7]; |
| 6834 | if (vco == 0) |
| 6835 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); |
| 6836 | else |
| 6837 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); |
| 6838 | |
| 6839 | return vco; |
| 6840 | } |
| 6841 | |
| 6842 | static int gm45_get_display_clock_speed(struct drm_device *dev) |
| 6843 | { |
| 6844 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6845 | uint16_t tmp = 0; |
| 6846 | |
| 6847 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6848 | |
| 6849 | cdclk_sel = (tmp >> 12) & 0x1; |
| 6850 | |
| 6851 | switch (vco) { |
| 6852 | case 2666667: |
| 6853 | case 4000000: |
| 6854 | case 5333333: |
| 6855 | return cdclk_sel ? 333333 : 222222; |
| 6856 | case 3200000: |
| 6857 | return cdclk_sel ? 320000 : 228571; |
| 6858 | default: |
| 6859 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); |
| 6860 | return 222222; |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | static int i965gm_get_display_clock_speed(struct drm_device *dev) |
| 6865 | { |
| 6866 | static const uint8_t div_3200[] = { 16, 10, 8 }; |
| 6867 | static const uint8_t div_4000[] = { 20, 12, 10 }; |
| 6868 | static const uint8_t div_5333[] = { 24, 16, 14 }; |
| 6869 | const uint8_t *div_table; |
| 6870 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6871 | uint16_t tmp = 0; |
| 6872 | |
| 6873 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6874 | |
| 6875 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; |
| 6876 | |
| 6877 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6878 | goto fail; |
| 6879 | |
| 6880 | switch (vco) { |
| 6881 | case 3200000: |
| 6882 | div_table = div_3200; |
| 6883 | break; |
| 6884 | case 4000000: |
| 6885 | div_table = div_4000; |
| 6886 | break; |
| 6887 | case 5333333: |
| 6888 | div_table = div_5333; |
| 6889 | break; |
| 6890 | default: |
| 6891 | goto fail; |
| 6892 | } |
| 6893 | |
| 6894 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6895 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6896 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6897 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
| 6898 | return 200000; |
| 6899 | } |
| 6900 | |
| 6901 | static int g33_get_display_clock_speed(struct drm_device *dev) |
| 6902 | { |
| 6903 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; |
| 6904 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; |
| 6905 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; |
| 6906 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; |
| 6907 | const uint8_t *div_table; |
| 6908 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6909 | uint16_t tmp = 0; |
| 6910 | |
| 6911 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6912 | |
| 6913 | cdclk_sel = (tmp >> 4) & 0x7; |
| 6914 | |
| 6915 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6916 | goto fail; |
| 6917 | |
| 6918 | switch (vco) { |
| 6919 | case 3200000: |
| 6920 | div_table = div_3200; |
| 6921 | break; |
| 6922 | case 4000000: |
| 6923 | div_table = div_4000; |
| 6924 | break; |
| 6925 | case 4800000: |
| 6926 | div_table = div_4800; |
| 6927 | break; |
| 6928 | case 5333333: |
| 6929 | div_table = div_5333; |
| 6930 | break; |
| 6931 | default: |
| 6932 | goto fail; |
| 6933 | } |
| 6934 | |
| 6935 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6936 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6937 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6938 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
| 6939 | return 190476; |
| 6940 | } |
| 6941 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6942 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6943 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6944 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6945 | while (*num > DATA_LINK_M_N_MASK || |
| 6946 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6947 | *num >>= 1; |
| 6948 | *den >>= 1; |
| 6949 | } |
| 6950 | } |
| 6951 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6952 | static void compute_m_n(unsigned int m, unsigned int n, |
| 6953 | uint32_t *ret_m, uint32_t *ret_n) |
| 6954 | { |
| 6955 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 6956 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6957 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6958 | } |
| 6959 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6960 | void |
| 6961 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6962 | int pixel_clock, int link_clock, |
| 6963 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6964 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6965 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6966 | |
| 6967 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6968 | link_clock * nlanes * 8, |
| 6969 | &m_n->gmch_m, &m_n->gmch_n); |
| 6970 | |
| 6971 | compute_m_n(pixel_clock, link_clock, |
| 6972 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6973 | } |
| 6974 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6975 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6976 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6977 | if (i915.panel_use_ssc >= 0) |
| 6978 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6979 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6980 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6981 | } |
| 6982 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6983 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 6984 | int num_connectors) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6985 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6986 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6987 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6988 | int refclk; |
| 6989 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6990 | WARN_ON(!crtc_state->base.state); |
| 6991 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 6992 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 6993 | refclk = 100000; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6994 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6995 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6996 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 6997 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6998 | } else if (!IS_GEN2(dev)) { |
| 6999 | refclk = 96000; |
| 7000 | } else { |
| 7001 | refclk = 48000; |
| 7002 | } |
| 7003 | |
| 7004 | return refclk; |
| 7005 | } |
| 7006 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7007 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7008 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 7009 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7010 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7011 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7012 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 7013 | { |
| 7014 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7015 | } |
| 7016 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7017 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7018 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7019 | intel_clock_t *reduced_clock) |
| 7020 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7021 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7022 | u32 fp, fp2 = 0; |
| 7023 | |
| 7024 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7025 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7026 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7027 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7028 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7029 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7030 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7031 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7032 | } |
| 7033 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7034 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7035 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7036 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7037 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7038 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7039 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7040 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7041 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7042 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7043 | } |
| 7044 | } |
| 7045 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7046 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 7047 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7048 | { |
| 7049 | u32 reg_val; |
| 7050 | |
| 7051 | /* |
| 7052 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 7053 | * and set it to a reasonable value instead. |
| 7054 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7055 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7056 | reg_val &= 0xffffff00; |
| 7057 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7058 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7059 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7060 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7061 | reg_val &= 0x8cffffff; |
| 7062 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7063 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7064 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7065 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7066 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7067 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7068 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7069 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7070 | reg_val &= 0x00ffffff; |
| 7071 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7072 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7073 | } |
| 7074 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7075 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 7076 | struct intel_link_m_n *m_n) |
| 7077 | { |
| 7078 | struct drm_device *dev = crtc->base.dev; |
| 7079 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7080 | int pipe = crtc->pipe; |
| 7081 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7082 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7083 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7084 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7085 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7089 | struct intel_link_m_n *m_n, |
| 7090 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7091 | { |
| 7092 | struct drm_device *dev = crtc->base.dev; |
| 7093 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7094 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7095 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7096 | |
| 7097 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7098 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7099 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7100 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7101 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7102 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 7103 | * for gen < 8) and if DRRS is supported (to make sure the |
| 7104 | * registers are not unnecessarily accessed). |
| 7105 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 7106 | 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] | 7107 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7108 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7109 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7110 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7111 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7112 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7113 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7114 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7115 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7116 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7117 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7118 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7119 | } |
| 7120 | } |
| 7121 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7122 | 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] | 7123 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7124 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 7125 | |
| 7126 | if (m_n == M1_N1) { |
| 7127 | dp_m_n = &crtc->config->dp_m_n; |
| 7128 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 7129 | } else if (m_n == M2_N2) { |
| 7130 | |
| 7131 | /* |
| 7132 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7133 | * needs to be programmed into M1_N1. |
| 7134 | */ |
| 7135 | dp_m_n = &crtc->config->dp_m2_n2; |
| 7136 | } else { |
| 7137 | DRM_ERROR("Unsupported divider value\n"); |
| 7138 | return; |
| 7139 | } |
| 7140 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7141 | if (crtc->config->has_pch_encoder) |
| 7142 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7143 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7144 | 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] | 7145 | } |
| 7146 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7147 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7148 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7149 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7150 | u32 dpll, dpll_md; |
| 7151 | |
| 7152 | /* |
| 7153 | * Enable DPIO clock input. We should never disable the reference |
| 7154 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 7155 | * on it. |
| 7156 | */ |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 7157 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
| 7158 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7159 | /* We should never disable this, set it here for state tracking */ |
| 7160 | if (crtc->pipe == PIPE_B) |
| 7161 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7162 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7163 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7164 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7165 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7166 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7167 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7168 | } |
| 7169 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7170 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7171 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7172 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7173 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7174 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7175 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7176 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7177 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7178 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7179 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7180 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7181 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7182 | bestn = pipe_config->dpll.n; |
| 7183 | bestm1 = pipe_config->dpll.m1; |
| 7184 | bestm2 = pipe_config->dpll.m2; |
| 7185 | bestp1 = pipe_config->dpll.p1; |
| 7186 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7187 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7188 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7189 | |
| 7190 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7191 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7192 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7193 | |
| 7194 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7195 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7196 | |
| 7197 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7198 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7199 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7200 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7201 | |
| 7202 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7203 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7204 | |
| 7205 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7206 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7207 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7208 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7209 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7210 | |
| 7211 | /* |
| 7212 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7213 | * but we don't support that). |
| 7214 | * Note: don't use the DAC post divider as it seems unstable. |
| 7215 | */ |
| 7216 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7217 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7218 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7219 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7220 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7221 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7222 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7223 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7224 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 7225 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7226 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7227 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7228 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7229 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7230 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7231 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7232 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7233 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7234 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7235 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7236 | 0x0df40000); |
| 7237 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7238 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7239 | 0x0df70000); |
| 7240 | } else { /* HDMI or VGA */ |
| 7241 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7242 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7243 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7244 | 0x0df70000); |
| 7245 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7246 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7247 | 0x0df40000); |
| 7248 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7249 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7250 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7251 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7252 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 7253 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7254 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7255 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7256 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7257 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7258 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7259 | } |
| 7260 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7261 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7262 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7263 | { |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 7264 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
| 7265 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7266 | DPLL_VCO_ENABLE; |
| 7267 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7268 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7269 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7270 | pipe_config->dpll_hw_state.dpll_md = |
| 7271 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7272 | } |
| 7273 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7274 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7275 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7276 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7277 | struct drm_device *dev = crtc->base.dev; |
| 7278 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7279 | int pipe = crtc->pipe; |
| 7280 | int dpll_reg = DPLL(crtc->pipe); |
| 7281 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7282 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7283 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7284 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7285 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7286 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7287 | bestn = pipe_config->dpll.n; |
| 7288 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7289 | bestm1 = pipe_config->dpll.m1; |
| 7290 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7291 | bestp1 = pipe_config->dpll.p1; |
| 7292 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7293 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7294 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7295 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7296 | |
| 7297 | /* |
| 7298 | * Enable Refclk and SSC |
| 7299 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7300 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7301 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7302 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7303 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7304 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7305 | /* p1 and p2 divider */ |
| 7306 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7307 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7308 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7309 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7310 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7311 | |
| 7312 | /* Feedback post-divider - m2 */ |
| 7313 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7314 | |
| 7315 | /* Feedback refclk divider - n and m1 */ |
| 7316 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7317 | DPIO_CHV_M1_DIV_BY_2 | |
| 7318 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7319 | |
| 7320 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7321 | 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] | 7322 | |
| 7323 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7324 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7325 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7326 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7327 | if (bestm2_frac) |
| 7328 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7329 | 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] | 7330 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7331 | /* Program digital lock detect threshold */ |
| 7332 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7333 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7334 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7335 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7336 | if (!bestm2_frac) |
| 7337 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7338 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7339 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7340 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7341 | if (vco == 5400000) { |
| 7342 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7343 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7344 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7345 | tribuf_calcntr = 0x9; |
| 7346 | } else if (vco <= 6200000) { |
| 7347 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7348 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7349 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7350 | tribuf_calcntr = 0x9; |
| 7351 | } else if (vco <= 6480000) { |
| 7352 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7353 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7354 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7355 | tribuf_calcntr = 0x8; |
| 7356 | } else { |
| 7357 | /* Not supported. Apply the same limits as in the max case */ |
| 7358 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7359 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7360 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7361 | tribuf_calcntr = 0; |
| 7362 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7363 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7364 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7365 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7366 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7367 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7368 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7369 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7370 | /* AFC Recal */ |
| 7371 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7372 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7373 | DPIO_AFC_RECAL); |
| 7374 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7375 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7376 | } |
| 7377 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7378 | /** |
| 7379 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7380 | * @dev_priv: i915 private structure |
| 7381 | * @pipe: pipe PLL to enable |
| 7382 | * @dpll: PLL configuration |
| 7383 | * |
| 7384 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7385 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7386 | * be enabled. |
| 7387 | */ |
| 7388 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 7389 | const struct dpll *dpll) |
| 7390 | { |
| 7391 | struct intel_crtc *crtc = |
| 7392 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7393 | struct intel_crtc_state pipe_config = { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7394 | .base.crtc = &crtc->base, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7395 | .pixel_multiplier = 1, |
| 7396 | .dpll = *dpll, |
| 7397 | }; |
| 7398 | |
| 7399 | if (IS_CHERRYVIEW(dev)) { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7400 | chv_compute_dpll(crtc, &pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7401 | chv_prepare_pll(crtc, &pipe_config); |
| 7402 | chv_enable_pll(crtc, &pipe_config); |
| 7403 | } else { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7404 | vlv_compute_dpll(crtc, &pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7405 | vlv_prepare_pll(crtc, &pipe_config); |
| 7406 | vlv_enable_pll(crtc, &pipe_config); |
| 7407 | } |
| 7408 | } |
| 7409 | |
| 7410 | /** |
| 7411 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7412 | * @dev_priv: i915 private structure |
| 7413 | * @pipe: pipe PLL to disable |
| 7414 | * |
| 7415 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7416 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7417 | */ |
| 7418 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 7419 | { |
| 7420 | if (IS_CHERRYVIEW(dev)) |
| 7421 | chv_disable_pll(to_i915(dev), pipe); |
| 7422 | else |
| 7423 | vlv_disable_pll(to_i915(dev), pipe); |
| 7424 | } |
| 7425 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7426 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7427 | struct intel_crtc_state *crtc_state, |
| 7428 | intel_clock_t *reduced_clock, |
| 7429 | int num_connectors) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7430 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7431 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7432 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7433 | u32 dpll; |
| 7434 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7435 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7436 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7437 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7438 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7439 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7440 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7441 | |
| 7442 | dpll = DPLL_VGA_MODE_DIS; |
| 7443 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7444 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7445 | dpll |= DPLLB_MODE_LVDS; |
| 7446 | else |
| 7447 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7448 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7449 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7450 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7451 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7452 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7453 | |
| 7454 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7455 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7456 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7457 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7458 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7459 | |
| 7460 | /* compute bitmask from p1 value */ |
| 7461 | if (IS_PINEVIEW(dev)) |
| 7462 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7463 | else { |
| 7464 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7465 | if (IS_G4X(dev) && reduced_clock) |
| 7466 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7467 | } |
| 7468 | switch (clock->p2) { |
| 7469 | case 5: |
| 7470 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7471 | break; |
| 7472 | case 7: |
| 7473 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7474 | break; |
| 7475 | case 10: |
| 7476 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7477 | break; |
| 7478 | case 14: |
| 7479 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7480 | break; |
| 7481 | } |
| 7482 | if (INTEL_INFO(dev)->gen >= 4) |
| 7483 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7484 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7485 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7486 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7487 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7488 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 7489 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7490 | else |
| 7491 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7492 | |
| 7493 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7494 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7495 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7496 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7497 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7498 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7499 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7500 | } |
| 7501 | } |
| 7502 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7503 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7504 | struct intel_crtc_state *crtc_state, |
| 7505 | intel_clock_t *reduced_clock, |
| 7506 | int num_connectors) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7507 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7508 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7509 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7510 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7511 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7512 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7513 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7514 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7515 | dpll = DPLL_VGA_MODE_DIS; |
| 7516 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7517 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7518 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7519 | } else { |
| 7520 | if (clock->p1 == 2) |
| 7521 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7522 | else |
| 7523 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7524 | if (clock->p2 == 4) |
| 7525 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7526 | } |
| 7527 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7528 | 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] | 7529 | dpll |= DPLL_DVO_2X_MODE; |
| 7530 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7531 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7532 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 7533 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7534 | else |
| 7535 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7536 | |
| 7537 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7538 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7539 | } |
| 7540 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7541 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7542 | { |
| 7543 | struct drm_device *dev = intel_crtc->base.dev; |
| 7544 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7545 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7546 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7547 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7548 | &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7549 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7550 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7551 | |
| 7552 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7553 | * the hw state checker will get angry at the mismatch. */ |
| 7554 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7555 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7556 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7557 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7558 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7559 | crtc_vtotal -= 1; |
| 7560 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7561 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7562 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7563 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7564 | else |
| 7565 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7566 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7567 | if (vsyncshift < 0) |
| 7568 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7569 | } |
| 7570 | |
| 7571 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7572 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7573 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7574 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7575 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7576 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7577 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7578 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7579 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7580 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7581 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7582 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7583 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7584 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7585 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7586 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7587 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7588 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7589 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7590 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7591 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7592 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7593 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7594 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7595 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7596 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7597 | * bits. */ |
| 7598 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 7599 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7600 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7601 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7602 | /* pipesrc controls the size that is scaled from, which should |
| 7603 | * always be the user's requested size. |
| 7604 | */ |
| 7605 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7606 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7607 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7608 | } |
| 7609 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7610 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7611 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7612 | { |
| 7613 | struct drm_device *dev = crtc->base.dev; |
| 7614 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7615 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7616 | uint32_t tmp; |
| 7617 | |
| 7618 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7619 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7620 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7621 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7622 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7623 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7624 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7625 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7626 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7627 | |
| 7628 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7629 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7630 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7631 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7632 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7633 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7634 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7635 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7636 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7637 | |
| 7638 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7639 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7640 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7641 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7642 | } |
| 7643 | |
| 7644 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7645 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7646 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7647 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7648 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7649 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7650 | } |
| 7651 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7652 | 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] | 7653 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7654 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7655 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7656 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7657 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7658 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7659 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7660 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7661 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7662 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7663 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7664 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7665 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7666 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7667 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7668 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 7669 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7670 | |
| 7671 | mode->hsync = drm_mode_hsync(mode); |
| 7672 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7673 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7674 | } |
| 7675 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7676 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7677 | { |
| 7678 | struct drm_device *dev = intel_crtc->base.dev; |
| 7679 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7680 | uint32_t pipeconf; |
| 7681 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7682 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7683 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7684 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 7685 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 7686 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7687 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7688 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7689 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7690 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7691 | /* only g4x and later have fancy bpc/dither controls */ |
| 7692 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7693 | /* 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] | 7694 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7695 | pipeconf |= PIPECONF_DITHER_EN | |
| 7696 | PIPECONF_DITHER_TYPE_SP; |
| 7697 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7698 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7699 | case 18: |
| 7700 | pipeconf |= PIPECONF_6BPC; |
| 7701 | break; |
| 7702 | case 24: |
| 7703 | pipeconf |= PIPECONF_8BPC; |
| 7704 | break; |
| 7705 | case 30: |
| 7706 | pipeconf |= PIPECONF_10BPC; |
| 7707 | break; |
| 7708 | default: |
| 7709 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7710 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7711 | } |
| 7712 | } |
| 7713 | |
| 7714 | if (HAS_PIPE_CXSR(dev)) { |
| 7715 | if (intel_crtc->lowfreq_avail) { |
| 7716 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 7717 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 7718 | } else { |
| 7719 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7720 | } |
| 7721 | } |
| 7722 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7723 | 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] | 7724 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7725 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7726 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7727 | else |
| 7728 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7729 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7730 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7731 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7732 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7733 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7734 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7735 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7736 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7737 | } |
| 7738 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7739 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7740 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7741 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7742 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7743 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 7744 | int refclk, num_connectors = 0; |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 7745 | intel_clock_t clock; |
| 7746 | bool ok; |
| 7747 | bool is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7748 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 7749 | const intel_limit_t *limit; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7750 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 7751 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7752 | struct drm_connector_state *connector_state; |
| 7753 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7754 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7755 | memset(&crtc_state->dpll_hw_state, 0, |
| 7756 | sizeof(crtc_state->dpll_hw_state)); |
| 7757 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 7758 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7759 | if (connector_state->crtc != &crtc->base) |
| 7760 | continue; |
| 7761 | |
| 7762 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7763 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7764 | switch (encoder->type) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7765 | case INTEL_OUTPUT_DSI: |
| 7766 | is_dsi = true; |
| 7767 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7768 | default: |
| 7769 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7770 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 7771 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 7772 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7773 | } |
| 7774 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7775 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 7776 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7777 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7778 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7779 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7780 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7781 | /* |
| 7782 | * Returns a set of divisors for the desired target clock with |
| 7783 | * the given refclk, or FALSE. The returned values represent |
| 7784 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 7785 | * 2) / p1 / p2. |
| 7786 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7787 | limit = intel_limit(crtc_state, refclk); |
| 7788 | ok = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7789 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7790 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7791 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7792 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7793 | return -EINVAL; |
| 7794 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7795 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7796 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7797 | crtc_state->dpll.n = clock.n; |
| 7798 | crtc_state->dpll.m1 = clock.m1; |
| 7799 | crtc_state->dpll.m2 = clock.m2; |
| 7800 | crtc_state->dpll.p1 = clock.p1; |
| 7801 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7802 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7803 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7804 | if (IS_GEN2(dev)) { |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 7805 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7806 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7807 | } else if (IS_CHERRYVIEW(dev)) { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7808 | chv_compute_dpll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7809 | } else if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7810 | vlv_compute_dpll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7811 | } else { |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 7812 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7813 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7814 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7815 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7816 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7817 | } |
| 7818 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7819 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7820 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7821 | { |
| 7822 | struct drm_device *dev = crtc->base.dev; |
| 7823 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7824 | uint32_t tmp; |
| 7825 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7826 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 7827 | return; |
| 7828 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7829 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7830 | if (!(tmp & PFIT_ENABLE)) |
| 7831 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7832 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7833 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7834 | if (INTEL_INFO(dev)->gen < 4) { |
| 7835 | if (crtc->pipe != PIPE_B) |
| 7836 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7837 | } else { |
| 7838 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7839 | return; |
| 7840 | } |
| 7841 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7842 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7843 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 7844 | if (INTEL_INFO(dev)->gen < 5) |
| 7845 | pipe_config->gmch_pfit.lvds_border_bits = |
| 7846 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 7847 | } |
| 7848 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7849 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7850 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7851 | { |
| 7852 | struct drm_device *dev = crtc->base.dev; |
| 7853 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7854 | int pipe = pipe_config->cpu_transcoder; |
| 7855 | intel_clock_t clock; |
| 7856 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7857 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7858 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7859 | /* In case of MIPI DPLL will not even be used */ |
| 7860 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 7861 | return; |
| 7862 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7863 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7864 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7865 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7866 | |
| 7867 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7868 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7869 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7870 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7871 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7872 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7873 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7874 | } |
| 7875 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7876 | static void |
| 7877 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7878 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7879 | { |
| 7880 | struct drm_device *dev = crtc->base.dev; |
| 7881 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7882 | u32 val, base, offset; |
| 7883 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7884 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7885 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7886 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7887 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7888 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7889 | val = I915_READ(DSPCNTR(plane)); |
| 7890 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 7891 | return; |
| 7892 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7893 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7894 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7895 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7896 | return; |
| 7897 | } |
| 7898 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7899 | fb = &intel_fb->base; |
| 7900 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7901 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7902 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7903 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7904 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7905 | } |
| 7906 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7907 | |
| 7908 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7909 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7910 | fb->pixel_format = fourcc; |
| 7911 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7912 | |
| 7913 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7914 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7915 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7916 | else |
| 7917 | offset = I915_READ(DSPLINOFF(plane)); |
| 7918 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7919 | } else { |
| 7920 | base = I915_READ(DSPADDR(plane)); |
| 7921 | } |
| 7922 | plane_config->base = base; |
| 7923 | |
| 7924 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7925 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7926 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7927 | |
| 7928 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7929 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7930 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7931 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 7932 | fb->pixel_format, |
| 7933 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7934 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7935 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7936 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7937 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7938 | pipe_name(pipe), plane, fb->width, fb->height, |
| 7939 | fb->bits_per_pixel, base, fb->pitches[0], |
| 7940 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7941 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7942 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7943 | } |
| 7944 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7945 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7946 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7947 | { |
| 7948 | struct drm_device *dev = crtc->base.dev; |
| 7949 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7950 | int pipe = pipe_config->cpu_transcoder; |
| 7951 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 7952 | intel_clock_t clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7953 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7954 | int refclk = 100000; |
| 7955 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7956 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7957 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7958 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7959 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7960 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7961 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7962 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7963 | |
| 7964 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7965 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7966 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7967 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7968 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7969 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7970 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7971 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7972 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7973 | } |
| 7974 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7975 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7976 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7977 | { |
| 7978 | struct drm_device *dev = crtc->base.dev; |
| 7979 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7980 | uint32_t tmp; |
| 7981 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 7982 | if (!intel_display_power_is_enabled(dev_priv, |
| 7983 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7984 | return false; |
| 7985 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7986 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7987 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7988 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7989 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7990 | if (!(tmp & PIPECONF_ENABLE)) |
| 7991 | return false; |
| 7992 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7993 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 7994 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7995 | case PIPECONF_6BPC: |
| 7996 | pipe_config->pipe_bpp = 18; |
| 7997 | break; |
| 7998 | case PIPECONF_8BPC: |
| 7999 | pipe_config->pipe_bpp = 24; |
| 8000 | break; |
| 8001 | case PIPECONF_10BPC: |
| 8002 | pipe_config->pipe_bpp = 30; |
| 8003 | break; |
| 8004 | default: |
| 8005 | break; |
| 8006 | } |
| 8007 | } |
| 8008 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8009 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 8010 | pipe_config->limited_color_range = true; |
| 8011 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8012 | if (INTEL_INFO(dev)->gen < 4) |
| 8013 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8014 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8015 | intel_get_pipe_timings(crtc, pipe_config); |
| 8016 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8017 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8018 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8019 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8020 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 8021 | pipe_config->pixel_multiplier = |
| 8022 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8023 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8024 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8025 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 8026 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8027 | pipe_config->pixel_multiplier = |
| 8028 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8029 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8030 | } else { |
| 8031 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8032 | * port and will be fixed up in the encoder->get_config |
| 8033 | * function. */ |
| 8034 | pipe_config->pixel_multiplier = 1; |
| 8035 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8036 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 8037 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8038 | /* |
| 8039 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8040 | * on 830. Filter it out here so that we don't |
| 8041 | * report errors due to that. |
| 8042 | */ |
| 8043 | if (IS_I830(dev)) |
| 8044 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8045 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8046 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8047 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8048 | } else { |
| 8049 | /* Mask out read-only status bits. */ |
| 8050 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8051 | DPLL_PORTC_READY_MASK | |
| 8052 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8053 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8054 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8055 | if (IS_CHERRYVIEW(dev)) |
| 8056 | chv_crtc_clock_get(crtc, pipe_config); |
| 8057 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8058 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8059 | else |
| 8060 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8061 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame^] | 8062 | /* |
| 8063 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8064 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8065 | * default. |
| 8066 | */ |
| 8067 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8068 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8069 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8070 | return true; |
| 8071 | } |
| 8072 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8073 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8074 | { |
| 8075 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8076 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8077 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8078 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8079 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8080 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8081 | bool has_ck505 = false; |
| 8082 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8083 | |
| 8084 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8085 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8086 | switch (encoder->type) { |
| 8087 | case INTEL_OUTPUT_LVDS: |
| 8088 | has_panel = true; |
| 8089 | has_lvds = true; |
| 8090 | break; |
| 8091 | case INTEL_OUTPUT_EDP: |
| 8092 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8093 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8094 | has_cpu_edp = true; |
| 8095 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8096 | default: |
| 8097 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8098 | } |
| 8099 | } |
| 8100 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8101 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8102 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8103 | can_ssc = has_ck505; |
| 8104 | } else { |
| 8105 | has_ck505 = false; |
| 8106 | can_ssc = true; |
| 8107 | } |
| 8108 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8109 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 8110 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8111 | |
| 8112 | /* Ironlake: try to setup display ref clock before DPLL |
| 8113 | * enabling. This is only under driver's control after |
| 8114 | * PCH B stepping, previous chipset stepping should be |
| 8115 | * ignoring this setting. |
| 8116 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8117 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8118 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8119 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8120 | * compute the final state we want first and check if we need to |
| 8121 | * make any changes at all. |
| 8122 | */ |
| 8123 | final = val; |
| 8124 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8125 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8126 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8127 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8128 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8129 | |
| 8130 | final &= ~DREF_SSC_SOURCE_MASK; |
| 8131 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 8132 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8133 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8134 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8135 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8136 | |
| 8137 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8138 | final |= DREF_SSC1_ENABLE; |
| 8139 | |
| 8140 | if (has_cpu_edp) { |
| 8141 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8142 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8143 | else |
| 8144 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8145 | } else |
| 8146 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8147 | } else { |
| 8148 | final |= DREF_SSC_SOURCE_DISABLE; |
| 8149 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8150 | } |
| 8151 | |
| 8152 | if (final == val) |
| 8153 | return; |
| 8154 | |
| 8155 | /* Always enable nonspread source */ |
| 8156 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8157 | |
| 8158 | if (has_ck505) |
| 8159 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8160 | else |
| 8161 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8162 | |
| 8163 | if (has_panel) { |
| 8164 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8165 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8166 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8167 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8168 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8169 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8170 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8171 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8172 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8173 | |
| 8174 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8175 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8176 | POSTING_READ(PCH_DREF_CONTROL); |
| 8177 | udelay(200); |
| 8178 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8179 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8180 | |
| 8181 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8182 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8183 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8184 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8185 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8186 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8187 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8188 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8189 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8190 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8191 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8192 | POSTING_READ(PCH_DREF_CONTROL); |
| 8193 | udelay(200); |
| 8194 | } else { |
| 8195 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 8196 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8197 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8198 | |
| 8199 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8200 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8201 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8202 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8203 | POSTING_READ(PCH_DREF_CONTROL); |
| 8204 | udelay(200); |
| 8205 | |
| 8206 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8207 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8208 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8209 | |
| 8210 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8211 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8212 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8213 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8214 | POSTING_READ(PCH_DREF_CONTROL); |
| 8215 | udelay(200); |
| 8216 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8217 | |
| 8218 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8219 | } |
| 8220 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8221 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8222 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8223 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8224 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8225 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8226 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8227 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8228 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8229 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 8230 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 8231 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8232 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8233 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8234 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8235 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8236 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8237 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 8238 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 8239 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | /* WaMPhyProgramming:hsw */ |
| 8243 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8244 | { |
| 8245 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8246 | |
| 8247 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8248 | tmp &= ~(0xFF << 24); |
| 8249 | tmp |= (0x12 << 24); |
| 8250 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8251 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8252 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8253 | tmp |= (1 << 11); |
| 8254 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8255 | |
| 8256 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8257 | tmp |= (1 << 11); |
| 8258 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8259 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8260 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8261 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8262 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8263 | |
| 8264 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8265 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8266 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8267 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8268 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8269 | tmp &= ~(7 << 13); |
| 8270 | tmp |= (5 << 13); |
| 8271 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8272 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8273 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8274 | tmp &= ~(7 << 13); |
| 8275 | tmp |= (5 << 13); |
| 8276 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8277 | |
| 8278 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8279 | tmp &= ~0xFF; |
| 8280 | tmp |= 0x1C; |
| 8281 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8282 | |
| 8283 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8284 | tmp &= ~0xFF; |
| 8285 | tmp |= 0x1C; |
| 8286 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8287 | |
| 8288 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8289 | tmp &= ~(0xFF << 16); |
| 8290 | tmp |= (0x1C << 16); |
| 8291 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8292 | |
| 8293 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8294 | tmp &= ~(0xFF << 16); |
| 8295 | tmp |= (0x1C << 16); |
| 8296 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8297 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8298 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8299 | tmp |= (1 << 27); |
| 8300 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8301 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8302 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8303 | tmp |= (1 << 27); |
| 8304 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8305 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8306 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8307 | tmp &= ~(0xF << 28); |
| 8308 | tmp |= (4 << 28); |
| 8309 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8310 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8311 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8312 | tmp &= ~(0xF << 28); |
| 8313 | tmp |= (4 << 28); |
| 8314 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8315 | } |
| 8316 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8317 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8318 | * Programming" based on the parameters passed: |
| 8319 | * - Sequence to enable CLKOUT_DP |
| 8320 | * - Sequence to enable CLKOUT_DP without spread |
| 8321 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8322 | */ |
| 8323 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 8324 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8325 | { |
| 8326 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8327 | uint32_t reg, tmp; |
| 8328 | |
| 8329 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8330 | with_spread = true; |
| 8331 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 8332 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 8333 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8334 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8335 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8336 | |
| 8337 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8338 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8339 | tmp |= SBI_SSCCTL_PATHALT; |
| 8340 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8341 | |
| 8342 | udelay(24); |
| 8343 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8344 | if (with_spread) { |
| 8345 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8346 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8347 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8348 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8349 | if (with_fdi) { |
| 8350 | lpt_reset_fdi_mphy(dev_priv); |
| 8351 | lpt_program_fdi_mphy(dev_priv); |
| 8352 | } |
| 8353 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8354 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8355 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 8356 | SBI_GEN0 : SBI_DBUFF0; |
| 8357 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8358 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8359 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8360 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8361 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8362 | } |
| 8363 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8364 | /* Sequence to disable CLKOUT_DP */ |
| 8365 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 8366 | { |
| 8367 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8368 | uint32_t reg, tmp; |
| 8369 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8370 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8371 | |
| 8372 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 8373 | SBI_GEN0 : SBI_DBUFF0; |
| 8374 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8375 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8376 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8377 | |
| 8378 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8379 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8380 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8381 | tmp |= SBI_SSCCTL_PATHALT; |
| 8382 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8383 | udelay(32); |
| 8384 | } |
| 8385 | tmp |= SBI_SSCCTL_DISABLE; |
| 8386 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8387 | } |
| 8388 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8389 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8390 | } |
| 8391 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8392 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 8393 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8394 | struct intel_encoder *encoder; |
| 8395 | bool has_vga = false; |
| 8396 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8397 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8398 | switch (encoder->type) { |
| 8399 | case INTEL_OUTPUT_ANALOG: |
| 8400 | has_vga = true; |
| 8401 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8402 | default: |
| 8403 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8404 | } |
| 8405 | } |
| 8406 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8407 | if (has_vga) |
| 8408 | lpt_enable_clkout_dp(dev, true, true); |
| 8409 | else |
| 8410 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8411 | } |
| 8412 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8413 | /* |
| 8414 | * Initialize reference clocks when the driver loads |
| 8415 | */ |
| 8416 | void intel_init_pch_refclk(struct drm_device *dev) |
| 8417 | { |
| 8418 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 8419 | ironlake_init_pch_refclk(dev); |
| 8420 | else if (HAS_PCH_LPT(dev)) |
| 8421 | lpt_init_pch_refclk(dev); |
| 8422 | } |
| 8423 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8424 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8425 | { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8426 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8427 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8428 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8429 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8430 | struct drm_connector_state *connector_state; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8431 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8432 | int num_connectors = 0, i; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8433 | bool is_lvds = false; |
| 8434 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8435 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8436 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8437 | continue; |
| 8438 | |
| 8439 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8440 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8441 | switch (encoder->type) { |
| 8442 | case INTEL_OUTPUT_LVDS: |
| 8443 | is_lvds = true; |
| 8444 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8445 | default: |
| 8446 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8447 | } |
| 8448 | num_connectors++; |
| 8449 | } |
| 8450 | |
| 8451 | 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] | 8452 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8453 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8454 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 8455 | } |
| 8456 | |
| 8457 | return 120000; |
| 8458 | } |
| 8459 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8460 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8461 | { |
| 8462 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8463 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8464 | int pipe = intel_crtc->pipe; |
| 8465 | uint32_t val; |
| 8466 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8467 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8468 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8469 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8470 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8471 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8472 | break; |
| 8473 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8474 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8475 | break; |
| 8476 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8477 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8478 | break; |
| 8479 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8480 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8481 | break; |
| 8482 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8483 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8484 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8485 | } |
| 8486 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8487 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8488 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8489 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8490 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8491 | val |= PIPECONF_INTERLACED_ILK; |
| 8492 | else |
| 8493 | val |= PIPECONF_PROGRESSIVE; |
| 8494 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8495 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8496 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8497 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8498 | I915_WRITE(PIPECONF(pipe), val); |
| 8499 | POSTING_READ(PIPECONF(pipe)); |
| 8500 | } |
| 8501 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8502 | /* |
| 8503 | * Set up the pipe CSC unit. |
| 8504 | * |
| 8505 | * Currently only full range RGB to limited range RGB conversion |
| 8506 | * is supported, but eventually this should handle various |
| 8507 | * RGB<->YCbCr scenarios as well. |
| 8508 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 8509 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8510 | { |
| 8511 | struct drm_device *dev = crtc->dev; |
| 8512 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8513 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8514 | int pipe = intel_crtc->pipe; |
| 8515 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 8516 | |
| 8517 | /* |
| 8518 | * TODO: Check what kind of values actually come out of the pipe |
| 8519 | * with these coeff/postoff values and adjust to get the best |
| 8520 | * accuracy. Perhaps we even need to take the bpc value into |
| 8521 | * consideration. |
| 8522 | */ |
| 8523 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8524 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8525 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 8526 | |
| 8527 | /* |
| 8528 | * GY/GU and RY/RU should be the other way around according |
| 8529 | * to BSpec, but reality doesn't agree. Just set them up in |
| 8530 | * a way that results in the correct picture. |
| 8531 | */ |
| 8532 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 8533 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 8534 | |
| 8535 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 8536 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 8537 | |
| 8538 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 8539 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 8540 | |
| 8541 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 8542 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 8543 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 8544 | |
| 8545 | if (INTEL_INFO(dev)->gen > 6) { |
| 8546 | uint16_t postoff = 0; |
| 8547 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8548 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 8549 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8550 | |
| 8551 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 8552 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 8553 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 8554 | |
| 8555 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 8556 | } else { |
| 8557 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 8558 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8559 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 8560 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 8561 | |
| 8562 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 8563 | } |
| 8564 | } |
| 8565 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8566 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8567 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8568 | struct drm_device *dev = crtc->dev; |
| 8569 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8570 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8571 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8572 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8573 | uint32_t val; |
| 8574 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 8575 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8576 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8577 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8578 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8579 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8580 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8581 | val |= PIPECONF_INTERLACED_ILK; |
| 8582 | else |
| 8583 | val |= PIPECONF_PROGRESSIVE; |
| 8584 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8585 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8586 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 8587 | |
| 8588 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 8589 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8590 | |
Satheeshakrishna M | 3cdf122c | 2014-04-08 15:46:53 +0530 | [diff] [blame] | 8591 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8592 | val = 0; |
| 8593 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8594 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8595 | case 18: |
| 8596 | val |= PIPEMISC_DITHER_6_BPC; |
| 8597 | break; |
| 8598 | case 24: |
| 8599 | val |= PIPEMISC_DITHER_8_BPC; |
| 8600 | break; |
| 8601 | case 30: |
| 8602 | val |= PIPEMISC_DITHER_10_BPC; |
| 8603 | break; |
| 8604 | case 36: |
| 8605 | val |= PIPEMISC_DITHER_12_BPC; |
| 8606 | break; |
| 8607 | default: |
| 8608 | /* Case prevented by pipe_config_set_bpp. */ |
| 8609 | BUG(); |
| 8610 | } |
| 8611 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8612 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8613 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8614 | |
| 8615 | I915_WRITE(PIPEMISC(pipe), val); |
| 8616 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8617 | } |
| 8618 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8619 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8620 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8621 | intel_clock_t *clock, |
| 8622 | bool *has_reduced_clock, |
| 8623 | intel_clock_t *reduced_clock) |
| 8624 | { |
| 8625 | struct drm_device *dev = crtc->dev; |
| 8626 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8627 | int refclk; |
| 8628 | const intel_limit_t *limit; |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 8629 | bool ret; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8630 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8631 | refclk = ironlake_get_refclk(crtc_state); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8632 | |
| 8633 | /* |
| 8634 | * Returns a set of divisors for the desired target clock with the given |
| 8635 | * refclk, or FALSE. The returned values represent the clock equation: |
| 8636 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 8637 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 8638 | limit = intel_limit(crtc_state, refclk); |
| 8639 | ret = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8640 | crtc_state->port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 8641 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8642 | if (!ret) |
| 8643 | return false; |
| 8644 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8645 | return true; |
| 8646 | } |
| 8647 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8648 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8649 | { |
| 8650 | /* |
| 8651 | * Account for spread spectrum to avoid |
| 8652 | * oversubscribing the link. Max center spread |
| 8653 | * is 2.5%; use 5% for safety's sake. |
| 8654 | */ |
| 8655 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8656 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8657 | } |
| 8658 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8659 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8660 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8661 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8662 | } |
| 8663 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8664 | 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] | 8665 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8666 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8667 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8668 | { |
| 8669 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8670 | struct drm_device *dev = crtc->dev; |
| 8671 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8672 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8673 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8674 | struct drm_connector_state *connector_state; |
| 8675 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8676 | uint32_t dpll; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8677 | int factor, num_connectors = 0, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 8678 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8679 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8680 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8681 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8682 | continue; |
| 8683 | |
| 8684 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8685 | |
| 8686 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8687 | case INTEL_OUTPUT_LVDS: |
| 8688 | is_lvds = true; |
| 8689 | break; |
| 8690 | case INTEL_OUTPUT_SDVO: |
| 8691 | case INTEL_OUTPUT_HDMI: |
| 8692 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8693 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8694 | default: |
| 8695 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8696 | } |
| 8697 | |
| 8698 | num_connectors++; |
| 8699 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8700 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8701 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8702 | factor = 21; |
| 8703 | if (is_lvds) { |
| 8704 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8705 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 8706 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8707 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8708 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8709 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8710 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8711 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 8712 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8713 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8714 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 8715 | *fp2 |= FP_CB_TUNE; |
| 8716 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8717 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8718 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8719 | if (is_lvds) |
| 8720 | dpll |= DPLLB_MODE_LVDS; |
| 8721 | else |
| 8722 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8723 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8724 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8725 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8726 | |
| 8727 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8728 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8729 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8730 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8731 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8732 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8733 | 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] | 8734 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8735 | 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] | 8736 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8737 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8738 | case 5: |
| 8739 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8740 | break; |
| 8741 | case 7: |
| 8742 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8743 | break; |
| 8744 | case 10: |
| 8745 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8746 | break; |
| 8747 | case 14: |
| 8748 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8749 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8750 | } |
| 8751 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 8752 | 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] | 8753 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8754 | else |
| 8755 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8756 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 8757 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8758 | } |
| 8759 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8760 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8761 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8762 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8763 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8764 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8765 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 8766 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 8767 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8768 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8769 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8770 | memset(&crtc_state->dpll_hw_state, 0, |
| 8771 | sizeof(crtc_state->dpll_hw_state)); |
| 8772 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 8773 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8774 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8775 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 8776 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 8777 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8778 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8779 | &has_reduced_clock, &reduced_clock); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8780 | if (!ok && !crtc_state->clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8781 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8782 | return -EINVAL; |
| 8783 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8784 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8785 | if (!crtc_state->clock_set) { |
| 8786 | crtc_state->dpll.n = clock.n; |
| 8787 | crtc_state->dpll.m1 = clock.m1; |
| 8788 | crtc_state->dpll.m2 = clock.m2; |
| 8789 | crtc_state->dpll.p1 = clock.p1; |
| 8790 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8791 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8792 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8793 | /* 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] | 8794 | if (crtc_state->has_pch_encoder) { |
| 8795 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8796 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8797 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8798 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8799 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8800 | &fp, &reduced_clock, |
| 8801 | has_reduced_clock ? &fp2 : NULL); |
| 8802 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8803 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8804 | crtc_state->dpll_hw_state.fp0 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8805 | if (has_reduced_clock) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8806 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8807 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8808 | crtc_state->dpll_hw_state.fp1 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8809 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8810 | pll = intel_get_shared_dpll(crtc, crtc_state); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8811 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 8812 | 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] | 8813 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 8814 | return -EINVAL; |
| 8815 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8816 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8817 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 8818 | if (is_lvds && has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8819 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 8820 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8821 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8822 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8823 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8824 | } |
| 8825 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8826 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8827 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8828 | { |
| 8829 | struct drm_device *dev = crtc->base.dev; |
| 8830 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8831 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8832 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8833 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8834 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8835 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8836 | & ~TU_SIZE_MASK; |
| 8837 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8838 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8839 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8840 | } |
| 8841 | |
| 8842 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8843 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8844 | struct intel_link_m_n *m_n, |
| 8845 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8846 | { |
| 8847 | struct drm_device *dev = crtc->base.dev; |
| 8848 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8849 | enum pipe pipe = crtc->pipe; |
| 8850 | |
| 8851 | if (INTEL_INFO(dev)->gen >= 5) { |
| 8852 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8853 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8854 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8855 | & ~TU_SIZE_MASK; |
| 8856 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8857 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8858 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8859 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8860 | * gen < 8) and if DRRS is supported (to make sure the |
| 8861 | * registers are not unnecessarily read). |
| 8862 | */ |
| 8863 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8864 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8865 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8866 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8867 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8868 | & ~TU_SIZE_MASK; |
| 8869 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8870 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8871 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8872 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8873 | } else { |
| 8874 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8875 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8876 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8877 | & ~TU_SIZE_MASK; |
| 8878 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8879 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8880 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8881 | } |
| 8882 | } |
| 8883 | |
| 8884 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8885 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8886 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8887 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8888 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8889 | else |
| 8890 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8891 | &pipe_config->dp_m_n, |
| 8892 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8893 | } |
| 8894 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8895 | 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] | 8896 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8897 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8898 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8899 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8900 | } |
| 8901 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8902 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8903 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8904 | { |
| 8905 | struct drm_device *dev = crtc->base.dev; |
| 8906 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8907 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8908 | uint32_t ps_ctrl = 0; |
| 8909 | int id = -1; |
| 8910 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8911 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8912 | /* find scaler attached to this pipe */ |
| 8913 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8914 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8915 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8916 | id = i; |
| 8917 | pipe_config->pch_pfit.enabled = true; |
| 8918 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8919 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8920 | break; |
| 8921 | } |
| 8922 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8923 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8924 | scaler_state->scaler_id = id; |
| 8925 | if (id >= 0) { |
| 8926 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8927 | } else { |
| 8928 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8929 | } |
| 8930 | } |
| 8931 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8932 | static void |
| 8933 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8934 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8935 | { |
| 8936 | struct drm_device *dev = crtc->base.dev; |
| 8937 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8938 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8939 | int pipe = crtc->pipe; |
| 8940 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8941 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8942 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8943 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8944 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8945 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8946 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8947 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8948 | return; |
| 8949 | } |
| 8950 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8951 | fb = &intel_fb->base; |
| 8952 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8953 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8954 | if (!(val & PLANE_CTL_ENABLE)) |
| 8955 | goto error; |
| 8956 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8957 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 8958 | fourcc = skl_format_to_fourcc(pixel_format, |
| 8959 | val & PLANE_CTL_ORDER_RGBX, |
| 8960 | val & PLANE_CTL_ALPHA_MASK); |
| 8961 | fb->pixel_format = fourcc; |
| 8962 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 8963 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8964 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8965 | switch (tiling) { |
| 8966 | case PLANE_CTL_TILED_LINEAR: |
| 8967 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 8968 | break; |
| 8969 | case PLANE_CTL_TILED_X: |
| 8970 | plane_config->tiling = I915_TILING_X; |
| 8971 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8972 | break; |
| 8973 | case PLANE_CTL_TILED_Y: |
| 8974 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 8975 | break; |
| 8976 | case PLANE_CTL_TILED_YF: |
| 8977 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 8978 | break; |
| 8979 | default: |
| 8980 | MISSING_CASE(tiling); |
| 8981 | goto error; |
| 8982 | } |
| 8983 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8984 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 8985 | plane_config->base = base; |
| 8986 | |
| 8987 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 8988 | |
| 8989 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 8990 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8991 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8992 | |
| 8993 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8994 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 8995 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8996 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8997 | |
| 8998 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8999 | fb->pixel_format, |
| 9000 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9001 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9002 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9003 | |
| 9004 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9005 | pipe_name(pipe), fb->width, fb->height, |
| 9006 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9007 | plane_config->size); |
| 9008 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9009 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9010 | return; |
| 9011 | |
| 9012 | error: |
| 9013 | kfree(fb); |
| 9014 | } |
| 9015 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9016 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9017 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9018 | { |
| 9019 | struct drm_device *dev = crtc->base.dev; |
| 9020 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9021 | uint32_t tmp; |
| 9022 | |
| 9023 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9024 | |
| 9025 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9026 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9027 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9028 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9029 | |
| 9030 | /* We currently do not free assignements of panel fitters on |
| 9031 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9032 | * differentiates them) so just WARN about this case for now. */ |
| 9033 | if (IS_GEN7(dev)) { |
| 9034 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9035 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9036 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9037 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9038 | } |
| 9039 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9040 | static void |
| 9041 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9042 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9043 | { |
| 9044 | struct drm_device *dev = crtc->base.dev; |
| 9045 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9046 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9047 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9048 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9049 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9050 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9051 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9052 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9053 | val = I915_READ(DSPCNTR(pipe)); |
| 9054 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 9055 | return; |
| 9056 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9057 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9058 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9059 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9060 | return; |
| 9061 | } |
| 9062 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9063 | fb = &intel_fb->base; |
| 9064 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9065 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9066 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9067 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9068 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9069 | } |
| 9070 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9071 | |
| 9072 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 9073 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9074 | fb->pixel_format = fourcc; |
| 9075 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9076 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9077 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9078 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9079 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9080 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9081 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9082 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9083 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9084 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9085 | } |
| 9086 | plane_config->base = base; |
| 9087 | |
| 9088 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9089 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 9090 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9091 | |
| 9092 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9093 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9094 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9095 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9096 | fb->pixel_format, |
| 9097 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9098 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9099 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9100 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 9101 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9102 | pipe_name(pipe), fb->width, fb->height, |
| 9103 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9104 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9105 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9106 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9107 | } |
| 9108 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9109 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9110 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9111 | { |
| 9112 | struct drm_device *dev = crtc->base.dev; |
| 9113 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9114 | uint32_t tmp; |
| 9115 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 9116 | if (!intel_display_power_is_enabled(dev_priv, |
| 9117 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9118 | return false; |
| 9119 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9120 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9121 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9122 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9123 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9124 | if (!(tmp & PIPECONF_ENABLE)) |
| 9125 | return false; |
| 9126 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9127 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9128 | case PIPECONF_6BPC: |
| 9129 | pipe_config->pipe_bpp = 18; |
| 9130 | break; |
| 9131 | case PIPECONF_8BPC: |
| 9132 | pipe_config->pipe_bpp = 24; |
| 9133 | break; |
| 9134 | case PIPECONF_10BPC: |
| 9135 | pipe_config->pipe_bpp = 30; |
| 9136 | break; |
| 9137 | case PIPECONF_12BPC: |
| 9138 | pipe_config->pipe_bpp = 36; |
| 9139 | break; |
| 9140 | default: |
| 9141 | break; |
| 9142 | } |
| 9143 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9144 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9145 | pipe_config->limited_color_range = true; |
| 9146 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9147 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9148 | struct intel_shared_dpll *pll; |
| 9149 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9150 | pipe_config->has_pch_encoder = true; |
| 9151 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9152 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9153 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9154 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9155 | |
| 9156 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9157 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9158 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 9159 | pipe_config->shared_dpll = |
| 9160 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9161 | } else { |
| 9162 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9163 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 9164 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 9165 | else |
| 9166 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 9167 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9168 | |
| 9169 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 9170 | |
| 9171 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 9172 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9173 | |
| 9174 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9175 | pipe_config->pixel_multiplier = |
| 9176 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9177 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9178 | |
| 9179 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9180 | } else { |
| 9181 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9182 | } |
| 9183 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9184 | intel_get_pipe_timings(crtc, pipe_config); |
| 9185 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9186 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9187 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9188 | return true; |
| 9189 | } |
| 9190 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9191 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9192 | { |
| 9193 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9194 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9195 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9196 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9197 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9198 | pipe_name(crtc->pipe)); |
| 9199 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9200 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 9201 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 9202 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9203 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
| 9204 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 9205 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9206 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9207 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9208 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9209 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9210 | 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] | 9211 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9212 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9213 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9214 | 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] | 9215 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9216 | /* |
| 9217 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9218 | * interrupts remain enabled. We used to check for that, but since it's |
| 9219 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9220 | * the interrupts, the check below should be enough. |
| 9221 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9222 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9223 | } |
| 9224 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9225 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9226 | { |
| 9227 | struct drm_device *dev = dev_priv->dev; |
| 9228 | |
| 9229 | if (IS_HASWELL(dev)) |
| 9230 | return I915_READ(D_COMP_HSW); |
| 9231 | else |
| 9232 | return I915_READ(D_COMP_BDW); |
| 9233 | } |
| 9234 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9235 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9236 | { |
| 9237 | struct drm_device *dev = dev_priv->dev; |
| 9238 | |
| 9239 | if (IS_HASWELL(dev)) { |
| 9240 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9241 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9242 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 9243 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9244 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9245 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9246 | I915_WRITE(D_COMP_BDW, val); |
| 9247 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9248 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9249 | } |
| 9250 | |
| 9251 | /* |
| 9252 | * This function implements pieces of two sequences from BSpec: |
| 9253 | * - Sequence for display software to disable LCPLL |
| 9254 | * - Sequence for display software to allow package C8+ |
| 9255 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9256 | * register. Callers should take care of disabling all the display engine |
| 9257 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9258 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9259 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9260 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9261 | { |
| 9262 | uint32_t val; |
| 9263 | |
| 9264 | assert_can_disable_lcpll(dev_priv); |
| 9265 | |
| 9266 | val = I915_READ(LCPLL_CTL); |
| 9267 | |
| 9268 | if (switch_to_fclk) { |
| 9269 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9270 | I915_WRITE(LCPLL_CTL, val); |
| 9271 | |
| 9272 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9273 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9274 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9275 | |
| 9276 | val = I915_READ(LCPLL_CTL); |
| 9277 | } |
| 9278 | |
| 9279 | val |= LCPLL_PLL_DISABLE; |
| 9280 | I915_WRITE(LCPLL_CTL, val); |
| 9281 | POSTING_READ(LCPLL_CTL); |
| 9282 | |
| 9283 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 9284 | DRM_ERROR("LCPLL still locked\n"); |
| 9285 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9286 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9287 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9288 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9289 | ndelay(100); |
| 9290 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9291 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9292 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9293 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9294 | |
| 9295 | if (allow_power_down) { |
| 9296 | val = I915_READ(LCPLL_CTL); |
| 9297 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9298 | I915_WRITE(LCPLL_CTL, val); |
| 9299 | POSTING_READ(LCPLL_CTL); |
| 9300 | } |
| 9301 | } |
| 9302 | |
| 9303 | /* |
| 9304 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9305 | * source. |
| 9306 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9307 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9308 | { |
| 9309 | uint32_t val; |
| 9310 | |
| 9311 | val = I915_READ(LCPLL_CTL); |
| 9312 | |
| 9313 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9314 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9315 | return; |
| 9316 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9317 | /* |
| 9318 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9319 | * 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] | 9320 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9321 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9322 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9323 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9324 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9325 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9326 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9327 | } |
| 9328 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9329 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9330 | val |= D_COMP_COMP_FORCE; |
| 9331 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9332 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9333 | |
| 9334 | val = I915_READ(LCPLL_CTL); |
| 9335 | val &= ~LCPLL_PLL_DISABLE; |
| 9336 | I915_WRITE(LCPLL_CTL, val); |
| 9337 | |
| 9338 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 9339 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9340 | |
| 9341 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9342 | val = I915_READ(LCPLL_CTL); |
| 9343 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9344 | I915_WRITE(LCPLL_CTL, val); |
| 9345 | |
| 9346 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9347 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9348 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9349 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9350 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9351 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 9352 | intel_update_cdclk(dev_priv->dev); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9353 | } |
| 9354 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9355 | /* |
| 9356 | * Package states C8 and deeper are really deep PC states that can only be |
| 9357 | * reached when all the devices on the system allow it, so even if the graphics |
| 9358 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9359 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9360 | * |
| 9361 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9362 | * well is disabled and most interrupts are disabled, and these are also |
| 9363 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9364 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9365 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9366 | * hang the machine. |
| 9367 | * |
| 9368 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9369 | * the state of some registers, so when we come back from PC8+ we need to |
| 9370 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9371 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9372 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9373 | * because of the runtime PM support). |
| 9374 | * |
| 9375 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9376 | * documentation. |
| 9377 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9378 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9379 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9380 | struct drm_device *dev = dev_priv->dev; |
| 9381 | uint32_t val; |
| 9382 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9383 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9384 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9385 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 9386 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9387 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9388 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9389 | } |
| 9390 | |
| 9391 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9392 | hsw_disable_lcpll(dev_priv, true, true); |
| 9393 | } |
| 9394 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9395 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9396 | { |
| 9397 | struct drm_device *dev = dev_priv->dev; |
| 9398 | uint32_t val; |
| 9399 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9400 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9401 | |
| 9402 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9403 | lpt_init_pch_refclk(dev); |
| 9404 | |
| 9405 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 9406 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9407 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9408 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9409 | } |
| 9410 | |
| 9411 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9412 | } |
| 9413 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9414 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9415 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9416 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9417 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9418 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9419 | broxton_set_cdclk(dev, req_cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9420 | } |
| 9421 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9422 | /* compute the max rate for new configuration */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9423 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9424 | { |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9425 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9426 | struct intel_crtc_state *crtc_state; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9427 | int max_pixel_rate = 0; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9428 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9429 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 9430 | int pixel_rate; |
| 9431 | |
| 9432 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 9433 | if (IS_ERR(crtc_state)) |
| 9434 | return PTR_ERR(crtc_state); |
| 9435 | |
| 9436 | if (!crtc_state->base.enable) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9437 | continue; |
| 9438 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9439 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9440 | |
| 9441 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9442 | if (IS_BROADWELL(state->dev) && crtc_state->ips_enabled) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9443 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
| 9444 | |
| 9445 | max_pixel_rate = max(max_pixel_rate, pixel_rate); |
| 9446 | } |
| 9447 | |
| 9448 | return max_pixel_rate; |
| 9449 | } |
| 9450 | |
| 9451 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) |
| 9452 | { |
| 9453 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9454 | uint32_t val, data; |
| 9455 | int ret; |
| 9456 | |
| 9457 | if (WARN((I915_READ(LCPLL_CTL) & |
| 9458 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | |
| 9459 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | |
| 9460 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | |
| 9461 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, |
| 9462 | "trying to change cdclk frequency with cdclk not enabled\n")) |
| 9463 | return; |
| 9464 | |
| 9465 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9466 | ret = sandybridge_pcode_write(dev_priv, |
| 9467 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); |
| 9468 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9469 | if (ret) { |
| 9470 | DRM_ERROR("failed to inform pcode about cdclk change\n"); |
| 9471 | return; |
| 9472 | } |
| 9473 | |
| 9474 | val = I915_READ(LCPLL_CTL); |
| 9475 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9476 | I915_WRITE(LCPLL_CTL, val); |
| 9477 | |
| 9478 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9479 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9480 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9481 | |
| 9482 | val = I915_READ(LCPLL_CTL); |
| 9483 | val &= ~LCPLL_CLK_FREQ_MASK; |
| 9484 | |
| 9485 | switch (cdclk) { |
| 9486 | case 450000: |
| 9487 | val |= LCPLL_CLK_FREQ_450; |
| 9488 | data = 0; |
| 9489 | break; |
| 9490 | case 540000: |
| 9491 | val |= LCPLL_CLK_FREQ_54O_BDW; |
| 9492 | data = 1; |
| 9493 | break; |
| 9494 | case 337500: |
| 9495 | val |= LCPLL_CLK_FREQ_337_5_BDW; |
| 9496 | data = 2; |
| 9497 | break; |
| 9498 | case 675000: |
| 9499 | val |= LCPLL_CLK_FREQ_675_BDW; |
| 9500 | data = 3; |
| 9501 | break; |
| 9502 | default: |
| 9503 | WARN(1, "invalid cdclk frequency\n"); |
| 9504 | return; |
| 9505 | } |
| 9506 | |
| 9507 | I915_WRITE(LCPLL_CTL, val); |
| 9508 | |
| 9509 | val = I915_READ(LCPLL_CTL); |
| 9510 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9511 | I915_WRITE(LCPLL_CTL, val); |
| 9512 | |
| 9513 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9514 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9515 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9516 | |
| 9517 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9518 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); |
| 9519 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9520 | |
| 9521 | intel_update_cdclk(dev); |
| 9522 | |
| 9523 | WARN(cdclk != dev_priv->cdclk_freq, |
| 9524 | "cdclk requested %d kHz but got %d kHz\n", |
| 9525 | cdclk, dev_priv->cdclk_freq); |
| 9526 | } |
| 9527 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9528 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9529 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9530 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
| 9531 | int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9532 | int cdclk; |
| 9533 | |
| 9534 | /* |
| 9535 | * FIXME should also account for plane ratio |
| 9536 | * once 64bpp pixel formats are supported. |
| 9537 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9538 | if (max_pixclk > 540000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9539 | cdclk = 675000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9540 | else if (max_pixclk > 450000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9541 | cdclk = 540000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9542 | else if (max_pixclk > 337500) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9543 | cdclk = 450000; |
| 9544 | else |
| 9545 | cdclk = 337500; |
| 9546 | |
| 9547 | /* |
| 9548 | * FIXME move the cdclk caclulation to |
| 9549 | * compute_config() so we can fail gracegully. |
| 9550 | */ |
| 9551 | if (cdclk > dev_priv->max_cdclk_freq) { |
| 9552 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 9553 | cdclk, dev_priv->max_cdclk_freq); |
| 9554 | cdclk = dev_priv->max_cdclk_freq; |
| 9555 | } |
| 9556 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9557 | to_intel_atomic_state(state)->cdclk = cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9558 | |
| 9559 | return 0; |
| 9560 | } |
| 9561 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9562 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9563 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9564 | struct drm_device *dev = old_state->dev; |
| 9565 | unsigned int req_cdclk = to_intel_atomic_state(old_state)->cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9566 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9567 | broadwell_set_cdclk(dev, req_cdclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9568 | } |
| 9569 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9570 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9571 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9572 | { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9573 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 9574 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9575 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9576 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 9577 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9578 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9579 | } |
| 9580 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9581 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9582 | enum port port, |
| 9583 | struct intel_crtc_state *pipe_config) |
| 9584 | { |
| 9585 | switch (port) { |
| 9586 | case PORT_A: |
| 9587 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
| 9588 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 9589 | break; |
| 9590 | case PORT_B: |
| 9591 | pipe_config->ddi_pll_sel = SKL_DPLL1; |
| 9592 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 9593 | break; |
| 9594 | case PORT_C: |
| 9595 | pipe_config->ddi_pll_sel = SKL_DPLL2; |
| 9596 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 9597 | break; |
| 9598 | default: |
| 9599 | DRM_ERROR("Incorrect port type\n"); |
| 9600 | } |
| 9601 | } |
| 9602 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9603 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9604 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9605 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9606 | { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9607 | u32 temp, dpll_ctl1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9608 | |
| 9609 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 9610 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 9611 | |
| 9612 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9613 | case SKL_DPLL0: |
| 9614 | /* |
| 9615 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part |
| 9616 | * of the shared DPLL framework and thus needs to be read out |
| 9617 | * separately |
| 9618 | */ |
| 9619 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 9620 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; |
| 9621 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9622 | case SKL_DPLL1: |
| 9623 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 9624 | break; |
| 9625 | case SKL_DPLL2: |
| 9626 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 9627 | break; |
| 9628 | case SKL_DPLL3: |
| 9629 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 9630 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9631 | } |
| 9632 | } |
| 9633 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9634 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9635 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9636 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9637 | { |
| 9638 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 9639 | |
| 9640 | switch (pipe_config->ddi_pll_sel) { |
| 9641 | case PORT_CLK_SEL_WRPLL1: |
| 9642 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 9643 | break; |
| 9644 | case PORT_CLK_SEL_WRPLL2: |
| 9645 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 9646 | break; |
| 9647 | } |
| 9648 | } |
| 9649 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9650 | 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] | 9651 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9652 | { |
| 9653 | struct drm_device *dev = crtc->base.dev; |
| 9654 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9655 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9656 | enum port port; |
| 9657 | uint32_t tmp; |
| 9658 | |
| 9659 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9660 | |
| 9661 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9662 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9663 | if (IS_SKYLAKE(dev)) |
| 9664 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9665 | else if (IS_BROXTON(dev)) |
| 9666 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9667 | else |
| 9668 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9669 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9670 | if (pipe_config->shared_dpll >= 0) { |
| 9671 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 9672 | |
| 9673 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 9674 | &pipe_config->dpll_hw_state)); |
| 9675 | } |
| 9676 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9677 | /* |
| 9678 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9679 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9680 | * the PCH transcoder is on. |
| 9681 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9682 | if (INTEL_INFO(dev)->gen < 9 && |
| 9683 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9684 | pipe_config->has_pch_encoder = true; |
| 9685 | |
| 9686 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9687 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9688 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9689 | |
| 9690 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9691 | } |
| 9692 | } |
| 9693 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9694 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9695 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9696 | { |
| 9697 | struct drm_device *dev = crtc->base.dev; |
| 9698 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9699 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9700 | uint32_t tmp; |
| 9701 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 9702 | if (!intel_display_power_is_enabled(dev_priv, |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9703 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 9704 | return false; |
| 9705 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9706 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9707 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 9708 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9709 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9710 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9711 | enum pipe trans_edp_pipe; |
| 9712 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9713 | default: |
| 9714 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 9715 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9716 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9717 | trans_edp_pipe = PIPE_A; |
| 9718 | break; |
| 9719 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9720 | trans_edp_pipe = PIPE_B; |
| 9721 | break; |
| 9722 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9723 | trans_edp_pipe = PIPE_C; |
| 9724 | break; |
| 9725 | } |
| 9726 | |
| 9727 | if (trans_edp_pipe == crtc->pipe) |
| 9728 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9729 | } |
| 9730 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 9731 | if (!intel_display_power_is_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9732 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 9733 | return false; |
| 9734 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9735 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9736 | if (!(tmp & PIPECONF_ENABLE)) |
| 9737 | return false; |
| 9738 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9739 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9740 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9741 | intel_get_pipe_timings(crtc, pipe_config); |
| 9742 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9743 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9744 | skl_init_scalers(dev, crtc, pipe_config); |
| 9745 | } |
| 9746 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9747 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Chandra Konduru | af99ceda | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 9748 | |
| 9749 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9750 | pipe_config->scaler_state.scaler_id = -1; |
| 9751 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
| 9752 | } |
| 9753 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9754 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9755 | if (INTEL_INFO(dev)->gen == 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9756 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9757 | else if (INTEL_INFO(dev)->gen < 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9758 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9759 | else |
| 9760 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9761 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9762 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 9763 | if (IS_HASWELL(dev)) |
| 9764 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 9765 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 9766 | |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9767 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
| 9768 | pipe_config->pixel_multiplier = |
| 9769 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9770 | } else { |
| 9771 | pipe_config->pixel_multiplier = 1; |
| 9772 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9773 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9774 | return true; |
| 9775 | } |
| 9776 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9777 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 9778 | { |
| 9779 | struct drm_device *dev = crtc->dev; |
| 9780 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9782 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9783 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9784 | if (base) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9785 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
| 9786 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9787 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 9788 | |
| 9789 | switch (stride) { |
| 9790 | default: |
| 9791 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 9792 | width, stride); |
| 9793 | stride = 256; |
| 9794 | /* fallthrough */ |
| 9795 | case 256: |
| 9796 | case 512: |
| 9797 | case 1024: |
| 9798 | case 2048: |
| 9799 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9800 | } |
| 9801 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9802 | cntl |= CURSOR_ENABLE | |
| 9803 | CURSOR_GAMMA_ENABLE | |
| 9804 | CURSOR_FORMAT_ARGB | |
| 9805 | CURSOR_STRIDE(stride); |
| 9806 | |
| 9807 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9808 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9809 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9810 | if (intel_crtc->cursor_cntl != 0 && |
| 9811 | (intel_crtc->cursor_base != base || |
| 9812 | intel_crtc->cursor_size != size || |
| 9813 | intel_crtc->cursor_cntl != cntl)) { |
| 9814 | /* On these chipsets we can only modify the base/size/stride |
| 9815 | * whilst the cursor is disabled. |
| 9816 | */ |
| 9817 | I915_WRITE(_CURACNTR, 0); |
| 9818 | POSTING_READ(_CURACNTR); |
| 9819 | intel_crtc->cursor_cntl = 0; |
| 9820 | } |
| 9821 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9822 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9823 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9824 | intel_crtc->cursor_base = base; |
| 9825 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9826 | |
| 9827 | if (intel_crtc->cursor_size != size) { |
| 9828 | I915_WRITE(CURSIZE, size); |
| 9829 | intel_crtc->cursor_size = size; |
| 9830 | } |
| 9831 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9832 | if (intel_crtc->cursor_cntl != cntl) { |
| 9833 | I915_WRITE(_CURACNTR, cntl); |
| 9834 | POSTING_READ(_CURACNTR); |
| 9835 | intel_crtc->cursor_cntl = cntl; |
| 9836 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9837 | } |
| 9838 | |
| 9839 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 9840 | { |
| 9841 | struct drm_device *dev = crtc->dev; |
| 9842 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9843 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9844 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9845 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9846 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9847 | cntl = 0; |
| 9848 | if (base) { |
| 9849 | cntl = MCURSOR_GAMMA_ENABLE; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9850 | switch (intel_crtc->base.cursor->state->crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9851 | case 64: |
| 9852 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 9853 | break; |
| 9854 | case 128: |
| 9855 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 9856 | break; |
| 9857 | case 256: |
| 9858 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 9859 | break; |
| 9860 | default: |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9861 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9862 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9863 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9864 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 9865 | |
| 9866 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 9867 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9868 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9869 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 9870 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9871 | cntl |= CURSOR_ROTATE_180; |
| 9872 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9873 | if (intel_crtc->cursor_cntl != cntl) { |
| 9874 | I915_WRITE(CURCNTR(pipe), cntl); |
| 9875 | POSTING_READ(CURCNTR(pipe)); |
| 9876 | intel_crtc->cursor_cntl = cntl; |
| 9877 | } |
| 9878 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 9879 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9880 | I915_WRITE(CURBASE(pipe), base); |
| 9881 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9882 | |
| 9883 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 9884 | } |
| 9885 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9886 | /* 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] | 9887 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 9888 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9889 | { |
| 9890 | struct drm_device *dev = crtc->dev; |
| 9891 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9892 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9893 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 9894 | int x = crtc->cursor_x; |
| 9895 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9896 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9897 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9898 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9899 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9900 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9901 | if (x >= intel_crtc->config->pipe_src_w) |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9902 | base = 0; |
| 9903 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9904 | if (y >= intel_crtc->config->pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9905 | base = 0; |
| 9906 | |
| 9907 | if (x < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9908 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9909 | base = 0; |
| 9910 | |
| 9911 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9912 | x = -x; |
| 9913 | } |
| 9914 | pos |= x << CURSOR_X_SHIFT; |
| 9915 | |
| 9916 | if (y < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9917 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9918 | base = 0; |
| 9919 | |
| 9920 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9921 | y = -y; |
| 9922 | } |
| 9923 | pos |= y << CURSOR_Y_SHIFT; |
| 9924 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9925 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9926 | return; |
| 9927 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9928 | I915_WRITE(CURPOS(pipe), pos); |
| 9929 | |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9930 | /* ILK+ do this automagically */ |
| 9931 | if (HAS_GMCH_DISPLAY(dev) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 9932 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 9933 | base += (intel_crtc->base.cursor->state->crtc_h * |
| 9934 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 9935 | } |
| 9936 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 9937 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9938 | i845_update_cursor(crtc, base); |
| 9939 | else |
| 9940 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9941 | } |
| 9942 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9943 | static bool cursor_size_ok(struct drm_device *dev, |
| 9944 | uint32_t width, uint32_t height) |
| 9945 | { |
| 9946 | if (width == 0 || height == 0) |
| 9947 | return false; |
| 9948 | |
| 9949 | /* |
| 9950 | * 845g/865g are special in that they are only limited by |
| 9951 | * the width of their cursors, the height is arbitrary up to |
| 9952 | * the precision of the register. Everything else requires |
| 9953 | * square cursors, limited to a few power-of-two sizes. |
| 9954 | */ |
| 9955 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 9956 | if ((width & 63) != 0) |
| 9957 | return false; |
| 9958 | |
| 9959 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 9960 | return false; |
| 9961 | |
| 9962 | if (height > 1023) |
| 9963 | return false; |
| 9964 | } else { |
| 9965 | switch (width | height) { |
| 9966 | case 256: |
| 9967 | case 128: |
| 9968 | if (IS_GEN2(dev)) |
| 9969 | return false; |
| 9970 | case 64: |
| 9971 | break; |
| 9972 | default: |
| 9973 | return false; |
| 9974 | } |
| 9975 | } |
| 9976 | |
| 9977 | return true; |
| 9978 | } |
| 9979 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9980 | 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] | 9981 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9982 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9983 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9984 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9985 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9986 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9987 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 9988 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 9989 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 9990 | } |
| 9991 | |
| 9992 | intel_crtc_load_lut(crtc); |
| 9993 | } |
| 9994 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9995 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 9996 | static struct drm_display_mode load_detect_mode = { |
| 9997 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 9998 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 9999 | }; |
| 10000 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10001 | struct drm_framebuffer * |
| 10002 | __intel_framebuffer_create(struct drm_device *dev, |
| 10003 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10004 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10005 | { |
| 10006 | struct intel_framebuffer *intel_fb; |
| 10007 | int ret; |
| 10008 | |
| 10009 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 10010 | if (!intel_fb) { |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 10011 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10012 | return ERR_PTR(-ENOMEM); |
| 10013 | } |
| 10014 | |
| 10015 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10016 | if (ret) |
| 10017 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10018 | |
| 10019 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10020 | err: |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 10021 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10022 | kfree(intel_fb); |
| 10023 | |
| 10024 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10025 | } |
| 10026 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 10027 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10028 | intel_framebuffer_create(struct drm_device *dev, |
| 10029 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10030 | struct drm_i915_gem_object *obj) |
| 10031 | { |
| 10032 | struct drm_framebuffer *fb; |
| 10033 | int ret; |
| 10034 | |
| 10035 | ret = i915_mutex_lock_interruptible(dev); |
| 10036 | if (ret) |
| 10037 | return ERR_PTR(ret); |
| 10038 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 10039 | mutex_unlock(&dev->struct_mutex); |
| 10040 | |
| 10041 | return fb; |
| 10042 | } |
| 10043 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10044 | static u32 |
| 10045 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 10046 | { |
| 10047 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 10048 | return ALIGN(pitch, 64); |
| 10049 | } |
| 10050 | |
| 10051 | static u32 |
| 10052 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 10053 | { |
| 10054 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 10055 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10056 | } |
| 10057 | |
| 10058 | static struct drm_framebuffer * |
| 10059 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 10060 | struct drm_display_mode *mode, |
| 10061 | int depth, int bpp) |
| 10062 | { |
| 10063 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 10064 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10065 | |
| 10066 | obj = i915_gem_alloc_object(dev, |
| 10067 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 10068 | if (obj == NULL) |
| 10069 | return ERR_PTR(-ENOMEM); |
| 10070 | |
| 10071 | mode_cmd.width = mode->hdisplay; |
| 10072 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 10073 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 10074 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 10075 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10076 | |
| 10077 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 10078 | } |
| 10079 | |
| 10080 | static struct drm_framebuffer * |
| 10081 | mode_fits_in_fbdev(struct drm_device *dev, |
| 10082 | struct drm_display_mode *mode) |
| 10083 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 10084 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10085 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10086 | struct drm_i915_gem_object *obj; |
| 10087 | struct drm_framebuffer *fb; |
| 10088 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10089 | if (!dev_priv->fbdev) |
| 10090 | return NULL; |
| 10091 | |
| 10092 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10093 | return NULL; |
| 10094 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10095 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10096 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10097 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10098 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10099 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 10100 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10101 | return NULL; |
| 10102 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10103 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10104 | return NULL; |
| 10105 | |
| 10106 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 10107 | #else |
| 10108 | return NULL; |
| 10109 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10110 | } |
| 10111 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10112 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 10113 | struct drm_crtc *crtc, |
| 10114 | struct drm_display_mode *mode, |
| 10115 | struct drm_framebuffer *fb, |
| 10116 | int x, int y) |
| 10117 | { |
| 10118 | struct drm_plane_state *plane_state; |
| 10119 | int hdisplay, vdisplay; |
| 10120 | int ret; |
| 10121 | |
| 10122 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 10123 | if (IS_ERR(plane_state)) |
| 10124 | return PTR_ERR(plane_state); |
| 10125 | |
| 10126 | if (mode) |
| 10127 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 10128 | else |
| 10129 | hdisplay = vdisplay = 0; |
| 10130 | |
| 10131 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 10132 | if (ret) |
| 10133 | return ret; |
| 10134 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 10135 | plane_state->crtc_x = 0; |
| 10136 | plane_state->crtc_y = 0; |
| 10137 | plane_state->crtc_w = hdisplay; |
| 10138 | plane_state->crtc_h = vdisplay; |
| 10139 | plane_state->src_x = x << 16; |
| 10140 | plane_state->src_y = y << 16; |
| 10141 | plane_state->src_w = hdisplay << 16; |
| 10142 | plane_state->src_h = vdisplay << 16; |
| 10143 | |
| 10144 | return 0; |
| 10145 | } |
| 10146 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10147 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10148 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10149 | struct intel_load_detect_pipe *old, |
| 10150 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10151 | { |
| 10152 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10153 | struct intel_encoder *intel_encoder = |
| 10154 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10155 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10156 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10157 | struct drm_crtc *crtc = NULL; |
| 10158 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10159 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10160 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10161 | struct drm_atomic_state *state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10162 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10163 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10164 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10165 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10166 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10167 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10168 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10169 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10170 | retry: |
| 10171 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 10172 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10173 | goto fail; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10174 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10175 | /* |
| 10176 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10177 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10178 | * - if the connector already has an assigned crtc, use it (but make |
| 10179 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10180 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10181 | * - try to find the first unused crtc that can drive this connector, |
| 10182 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10183 | */ |
| 10184 | |
| 10185 | /* See if we already have a CRTC for this connector */ |
| 10186 | if (encoder->crtc) { |
| 10187 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10188 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10189 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10190 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10191 | goto fail; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 10192 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 10193 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10194 | goto fail; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 10195 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 10196 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10197 | old->load_detect_temp = false; |
| 10198 | |
| 10199 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 10200 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 10201 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10202 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10203 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10204 | } |
| 10205 | |
| 10206 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10207 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10208 | i++; |
| 10209 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10210 | continue; |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10211 | if (possible_crtc->state->enable) |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10212 | continue; |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10213 | |
| 10214 | crtc = possible_crtc; |
| 10215 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10216 | } |
| 10217 | |
| 10218 | /* |
| 10219 | * If we didn't find an unused CRTC, don't use any. |
| 10220 | */ |
| 10221 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10222 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10223 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10224 | } |
| 10225 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10226 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10227 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10228 | goto fail; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 10229 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 10230 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10231 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10232 | |
| 10233 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 10234 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10235 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10236 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10237 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10238 | state = drm_atomic_state_alloc(dev); |
| 10239 | if (!state) |
| 10240 | return false; |
| 10241 | |
| 10242 | state->acquire_ctx = ctx; |
| 10243 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10244 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10245 | if (IS_ERR(connector_state)) { |
| 10246 | ret = PTR_ERR(connector_state); |
| 10247 | goto fail; |
| 10248 | } |
| 10249 | |
| 10250 | connector_state->crtc = crtc; |
| 10251 | connector_state->best_encoder = &intel_encoder->base; |
| 10252 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10253 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10254 | if (IS_ERR(crtc_state)) { |
| 10255 | ret = PTR_ERR(crtc_state); |
| 10256 | goto fail; |
| 10257 | } |
| 10258 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10259 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10260 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10261 | if (!mode) |
| 10262 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10263 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10264 | /* We need a framebuffer large enough to accommodate all accesses |
| 10265 | * that the plane may generate whilst we perform load detection. |
| 10266 | * We can not rely on the fbcon either being present (we get called |
| 10267 | * during its initialisation to detect all boot displays, or it may |
| 10268 | * not even exist) or that it is large enough to satisfy the |
| 10269 | * requested mode. |
| 10270 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10271 | fb = mode_fits_in_fbdev(dev, mode); |
| 10272 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10273 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10274 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 10275 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10276 | } else |
| 10277 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10278 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10279 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10280 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10281 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10282 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10283 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 10284 | if (ret) |
| 10285 | goto fail; |
| 10286 | |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10287 | drm_mode_copy(&crtc_state->base.mode, mode); |
| 10288 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 10289 | if (drm_atomic_commit(state)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10290 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10291 | if (old->release_fb) |
| 10292 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10293 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10294 | } |
Daniel Vetter | 9128b04 | 2015-03-03 17:31:21 +0100 | [diff] [blame] | 10295 | crtc->primary->crtc = crtc; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10296 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10297 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 10298 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10299 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10300 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10301 | fail: |
Ander Conselvan de Oliveira | e5d958e | 2015-04-21 17:12:57 +0300 | [diff] [blame] | 10302 | drm_atomic_state_free(state); |
| 10303 | state = NULL; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10304 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10305 | if (ret == -EDEADLK) { |
| 10306 | drm_modeset_backoff(ctx); |
| 10307 | goto retry; |
| 10308 | } |
| 10309 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10310 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10311 | } |
| 10312 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10313 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10314 | struct intel_load_detect_pipe *old, |
| 10315 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10316 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10317 | struct drm_device *dev = connector->dev; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10318 | struct intel_encoder *intel_encoder = |
| 10319 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10320 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 10321 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10322 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10323 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10324 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10325 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10326 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10327 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10328 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10329 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10330 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10331 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10332 | if (old->load_detect_temp) { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10333 | state = drm_atomic_state_alloc(dev); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10334 | if (!state) |
| 10335 | goto fail; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10336 | |
| 10337 | state->acquire_ctx = ctx; |
| 10338 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10339 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10340 | if (IS_ERR(connector_state)) |
| 10341 | goto fail; |
| 10342 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10343 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10344 | if (IS_ERR(crtc_state)) |
| 10345 | goto fail; |
| 10346 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10347 | connector_state->best_encoder = NULL; |
| 10348 | connector_state->crtc = NULL; |
| 10349 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10350 | crtc_state->base.enable = crtc_state->base.active = false; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10351 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10352 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
| 10353 | 0, 0); |
| 10354 | if (ret) |
| 10355 | goto fail; |
| 10356 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 10357 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 10358 | if (ret) |
| 10359 | goto fail; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10360 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 10361 | if (old->release_fb) { |
| 10362 | drm_framebuffer_unregister_private(old->release_fb); |
| 10363 | drm_framebuffer_unreference(old->release_fb); |
| 10364 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10365 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10366 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10367 | } |
| 10368 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 10369 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 10370 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 10371 | connector->funcs->dpms(connector, old->dpms_mode); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10372 | |
| 10373 | return; |
| 10374 | fail: |
| 10375 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); |
| 10376 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10377 | } |
| 10378 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10379 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10380 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10381 | { |
| 10382 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10383 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10384 | |
| 10385 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10386 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10387 | else if (HAS_PCH_SPLIT(dev)) |
| 10388 | return 120000; |
| 10389 | else if (!IS_GEN2(dev)) |
| 10390 | return 96000; |
| 10391 | else |
| 10392 | return 48000; |
| 10393 | } |
| 10394 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10395 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10396 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10397 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10398 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10399 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10400 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10401 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10402 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10403 | u32 fp; |
| 10404 | intel_clock_t clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10405 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10406 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10407 | |
| 10408 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10409 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10410 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10411 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10412 | |
| 10413 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10414 | if (IS_PINEVIEW(dev)) { |
| 10415 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10416 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10417 | } else { |
| 10418 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10419 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10420 | } |
| 10421 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 10422 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10423 | if (IS_PINEVIEW(dev)) |
| 10424 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10425 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10426 | else |
| 10427 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10428 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10429 | |
| 10430 | switch (dpll & DPLL_MODE_MASK) { |
| 10431 | case DPLLB_MODE_DAC_SERIAL: |
| 10432 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10433 | 5 : 10; |
| 10434 | break; |
| 10435 | case DPLLB_MODE_LVDS: |
| 10436 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10437 | 7 : 14; |
| 10438 | break; |
| 10439 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10440 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10441 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10442 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10443 | } |
| 10444 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10445 | if (IS_PINEVIEW(dev)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10446 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10447 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10448 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10449 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 10450 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10451 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10452 | |
| 10453 | if (is_lvds) { |
| 10454 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10455 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10456 | |
| 10457 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10458 | clock.p2 = 7; |
| 10459 | else |
| 10460 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10461 | } else { |
| 10462 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10463 | clock.p1 = 2; |
| 10464 | else { |
| 10465 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10466 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10467 | } |
| 10468 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10469 | clock.p2 = 4; |
| 10470 | else |
| 10471 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10472 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10473 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10474 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10475 | } |
| 10476 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10477 | /* |
| 10478 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10479 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10480 | * encoder's get_config() function. |
| 10481 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10482 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10483 | } |
| 10484 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10485 | int intel_dotclock_calculate(int link_freq, |
| 10486 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10487 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10488 | /* |
| 10489 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10490 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10491 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10492 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10493 | * |
| 10494 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10495 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10496 | */ |
| 10497 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10498 | if (!m_n->link_n) |
| 10499 | return 0; |
| 10500 | |
| 10501 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 10502 | } |
| 10503 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10504 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10505 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10506 | { |
| 10507 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10508 | |
| 10509 | /* read out port_clock from the DPLL */ |
| 10510 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10511 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10512 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10513 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10514 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10515 | * agree once we know their relationship in the encoder's |
| 10516 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10517 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10518 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10519 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 10520 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10521 | } |
| 10522 | |
| 10523 | /** Returns the currently programmed mode of the given pipe. */ |
| 10524 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 10525 | struct drm_crtc *crtc) |
| 10526 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 10527 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10528 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10529 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10530 | struct drm_display_mode *mode; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10531 | struct intel_crtc_state pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10532 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 10533 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10534 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 10535 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10536 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10537 | |
| 10538 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10539 | if (!mode) |
| 10540 | return NULL; |
| 10541 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10542 | /* |
| 10543 | * Construct a pipe_config sufficient for getting the clock info |
| 10544 | * back out of crtc_clock_get. |
| 10545 | * |
| 10546 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 10547 | * to use a real value here instead. |
| 10548 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10549 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10550 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10551 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 10552 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 10553 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10554 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 10555 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 10556 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10557 | mode->hdisplay = (htot & 0xffff) + 1; |
| 10558 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 10559 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 10560 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 10561 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 10562 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 10563 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 10564 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 10565 | |
| 10566 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10567 | |
| 10568 | return mode; |
| 10569 | } |
| 10570 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10571 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10572 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10573 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10574 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10575 | if (dev_priv->mm.busy) |
| 10576 | return; |
| 10577 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10578 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10579 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 10580 | if (INTEL_INFO(dev)->gen >= 6) |
| 10581 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10582 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10583 | } |
| 10584 | |
| 10585 | void intel_mark_idle(struct drm_device *dev) |
| 10586 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10587 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 10588 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10589 | if (!dev_priv->mm.busy) |
| 10590 | return; |
| 10591 | |
| 10592 | dev_priv->mm.busy = false; |
| 10593 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 10594 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 10595 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 10596 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10597 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10598 | } |
| 10599 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10600 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10601 | { |
| 10602 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10603 | struct drm_device *dev = crtc->dev; |
| 10604 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10605 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10606 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10607 | work = intel_crtc->unpin_work; |
| 10608 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10609 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10610 | |
| 10611 | if (work) { |
| 10612 | cancel_work_sync(&work->work); |
| 10613 | kfree(work); |
| 10614 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10615 | |
| 10616 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10617 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10618 | kfree(intel_crtc); |
| 10619 | } |
| 10620 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10621 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 10622 | { |
| 10623 | struct intel_unpin_work *work = |
| 10624 | container_of(__work, struct intel_unpin_work, work); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10625 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 10626 | struct drm_device *dev = crtc->base.dev; |
| 10627 | struct drm_plane *primary = crtc->base.primary; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10628 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10629 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10630 | intel_unpin_fb_obj(work->old_fb, primary->state); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10631 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 10632 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10633 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10634 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10635 | mutex_unlock(&dev->struct_mutex); |
| 10636 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10637 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10638 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10639 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10640 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
| 10641 | atomic_dec(&crtc->unpin_work_count); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10642 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10643 | kfree(work); |
| 10644 | } |
| 10645 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10646 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10647 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10648 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10649 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10650 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10651 | unsigned long flags; |
| 10652 | |
| 10653 | /* Ignore early vblank irqs */ |
| 10654 | if (intel_crtc == NULL) |
| 10655 | return; |
| 10656 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10657 | /* |
| 10658 | * This is called both by irq handlers and the reset code (to complete |
| 10659 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10660 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10661 | spin_lock_irqsave(&dev->event_lock, flags); |
| 10662 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10663 | |
| 10664 | /* Ensure we don't miss a work->pending update ... */ |
| 10665 | smp_rmb(); |
| 10666 | |
| 10667 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10668 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10669 | return; |
| 10670 | } |
| 10671 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10672 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 10673 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10674 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10675 | } |
| 10676 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10677 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 10678 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10679 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10680 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10681 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10682 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10683 | } |
| 10684 | |
| 10685 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 10686 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10687 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10688 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 10689 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10690 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10691 | } |
| 10692 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10693 | /* Is 'a' after or equal to 'b'? */ |
| 10694 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 10695 | { |
| 10696 | return !((a - b) & 0x80000000); |
| 10697 | } |
| 10698 | |
| 10699 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 10700 | { |
| 10701 | struct drm_device *dev = crtc->base.dev; |
| 10702 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10703 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 10704 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 10705 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 10706 | return true; |
| 10707 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10708 | /* |
| 10709 | * The relevant registers doen't exist on pre-ctg. |
| 10710 | * As the flip done interrupt doesn't trigger for mmio |
| 10711 | * flips on gmch platforms, a flip count check isn't |
| 10712 | * really needed there. But since ctg has the registers, |
| 10713 | * include it in the check anyway. |
| 10714 | */ |
| 10715 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 10716 | return true; |
| 10717 | |
| 10718 | /* |
| 10719 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 10720 | * used the same base address. In that case the mmio flip might |
| 10721 | * have completed, but the CS hasn't even executed the flip yet. |
| 10722 | * |
| 10723 | * A flip count check isn't enough as the CS might have updated |
| 10724 | * the base address just after start of vblank, but before we |
| 10725 | * managed to process the interrupt. This means we'd complete the |
| 10726 | * CS flip too soon. |
| 10727 | * |
| 10728 | * Combining both checks should get us a good enough result. It may |
| 10729 | * still happen that the CS flip has been executed, but has not |
| 10730 | * yet actually completed. But in case the base address is the same |
| 10731 | * anyway, we don't really care. |
| 10732 | */ |
| 10733 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 10734 | crtc->unpin_work->gtt_offset && |
| 10735 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 10736 | crtc->unpin_work->flip_count); |
| 10737 | } |
| 10738 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10739 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 10740 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10741 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10742 | struct intel_crtc *intel_crtc = |
| 10743 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 10744 | unsigned long flags; |
| 10745 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10746 | |
| 10747 | /* |
| 10748 | * This is called both by irq handlers and the reset code (to complete |
| 10749 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10750 | * |
| 10751 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10752 | * generate a page-flip completion irq, i.e. every modeset |
| 10753 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 10754 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10755 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10756 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10757 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10758 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10759 | } |
| 10760 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10761 | 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] | 10762 | { |
| 10763 | /* Ensure that the work item is consistent when activating it ... */ |
| 10764 | smp_wmb(); |
| 10765 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 10766 | /* and that it is marked active as soon as the irq could fire. */ |
| 10767 | smp_wmb(); |
| 10768 | } |
| 10769 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10770 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 10771 | struct drm_crtc *crtc, |
| 10772 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10773 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10774 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10775 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10776 | { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10777 | struct intel_engine_cs *ring = req->ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10778 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10779 | u32 flip_mask; |
| 10780 | int ret; |
| 10781 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10782 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10783 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10784 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10785 | |
| 10786 | /* Can't queue multiple flips, so wait for the previous |
| 10787 | * one to finish before executing the next. |
| 10788 | */ |
| 10789 | if (intel_crtc->plane) |
| 10790 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10791 | else |
| 10792 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10793 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 10794 | intel_ring_emit(ring, MI_NOOP); |
| 10795 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10796 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10797 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10798 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10799 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10800 | |
| 10801 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10802 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10803 | } |
| 10804 | |
| 10805 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 10806 | struct drm_crtc *crtc, |
| 10807 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10808 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10809 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10810 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10811 | { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10812 | struct intel_engine_cs *ring = req->ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10813 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10814 | u32 flip_mask; |
| 10815 | int ret; |
| 10816 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10817 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10818 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10819 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10820 | |
| 10821 | if (intel_crtc->plane) |
| 10822 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10823 | else |
| 10824 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10825 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 10826 | intel_ring_emit(ring, MI_NOOP); |
| 10827 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 10828 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10829 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10830 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10831 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10832 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10833 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10834 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10835 | } |
| 10836 | |
| 10837 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 10838 | struct drm_crtc *crtc, |
| 10839 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10840 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10841 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10842 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10843 | { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10844 | struct intel_engine_cs *ring = req->ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10845 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10846 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10847 | uint32_t pf, pipesrc; |
| 10848 | int ret; |
| 10849 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10850 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10851 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10852 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10853 | |
| 10854 | /* i965+ uses the linear or tiled offsets from the |
| 10855 | * Display Registers (which do not change across a page-flip) |
| 10856 | * so we need only reprogram the base address. |
| 10857 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10858 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10859 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10860 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10861 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 10862 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10863 | |
| 10864 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 10865 | * untested on non-native modes, so ignore it for now. |
| 10866 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 10867 | */ |
| 10868 | pf = 0; |
| 10869 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10870 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10871 | |
| 10872 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10873 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10874 | } |
| 10875 | |
| 10876 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 10877 | struct drm_crtc *crtc, |
| 10878 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10879 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10880 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10881 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10882 | { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10883 | struct intel_engine_cs *ring = req->ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10884 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10885 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10886 | uint32_t pf, pipesrc; |
| 10887 | int ret; |
| 10888 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10889 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10890 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10891 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10892 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10893 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 10894 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 10895 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10896 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10897 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 10898 | /* Contrary to the suggestions in the documentation, |
| 10899 | * "Enable Panel Fitter" does not seem to be required when page |
| 10900 | * flipping with a non-native mode, and worse causes a normal |
| 10901 | * modeset to fail. |
| 10902 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 10903 | */ |
| 10904 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10905 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10906 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10907 | |
| 10908 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10909 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10910 | } |
| 10911 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10912 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 10913 | struct drm_crtc *crtc, |
| 10914 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10915 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10916 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10917 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10918 | { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10919 | struct intel_engine_cs *ring = req->ring; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10920 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10921 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10922 | int len, ret; |
| 10923 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10924 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10925 | case PLANE_A: |
| 10926 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 10927 | break; |
| 10928 | case PLANE_B: |
| 10929 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 10930 | break; |
| 10931 | case PLANE_C: |
| 10932 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 10933 | break; |
| 10934 | default: |
| 10935 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10936 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10937 | } |
| 10938 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10939 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10940 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10941 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10942 | /* |
| 10943 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 10944 | * 48bits addresses, and we need a NOOP for the batch size to |
| 10945 | * stay even. |
| 10946 | */ |
| 10947 | if (IS_GEN8(dev)) |
| 10948 | len += 2; |
| 10949 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10950 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 10951 | /* |
| 10952 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 10953 | * "The full packet must be contained within the same cache line." |
| 10954 | * |
| 10955 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 10956 | * cacheline, if we ever start emitting more commands before |
| 10957 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 10958 | * then do the cacheline alignment, and finally emit the |
| 10959 | * MI_DISPLAY_FLIP. |
| 10960 | */ |
John Harrison | bba09b1 | 2015-05-29 17:44:06 +0100 | [diff] [blame] | 10961 | ret = intel_ring_cacheline_align(req); |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 10962 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10963 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 10964 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10965 | ret = intel_ring_begin(req, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10966 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10967 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10968 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10969 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 10970 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 10971 | * more than one flip event at any time (or ensure that one flip message |
| 10972 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 10973 | * Experimentation says that BCS works despite DERRMR masking all |
| 10974 | * flip-done completion events and that unmasking all planes at once |
| 10975 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 10976 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 10977 | */ |
| 10978 | if (ring->id == RCS) { |
| 10979 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 10980 | intel_ring_emit(ring, DERRMR); |
| 10981 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 10982 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 10983 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10984 | if (IS_GEN8(dev)) |
Arun Siluvery | f1afe24 | 2015-08-04 16:22:20 +0100 | [diff] [blame] | 10985 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10986 | MI_SRM_LRM_GLOBAL_GTT); |
| 10987 | else |
Arun Siluvery | f1afe24 | 2015-08-04 16:22:20 +0100 | [diff] [blame] | 10988 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10989 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10990 | intel_ring_emit(ring, DERRMR); |
| 10991 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10992 | if (IS_GEN8(dev)) { |
| 10993 | intel_ring_emit(ring, 0); |
| 10994 | intel_ring_emit(ring, MI_NOOP); |
| 10995 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10996 | } |
| 10997 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10998 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10999 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11000 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11001 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11002 | |
| 11003 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11004 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11005 | } |
| 11006 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11007 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 11008 | struct drm_i915_gem_object *obj) |
| 11009 | { |
| 11010 | /* |
| 11011 | * This is not being used for older platforms, because |
| 11012 | * non-availability of flip done interrupt forces us to use |
| 11013 | * CS flips. Older platforms derive flip done using some clever |
| 11014 | * tricks involving the flip_pending status bits and vblank irqs. |
| 11015 | * So using MMIO flips there would disrupt this mechanism. |
| 11016 | */ |
| 11017 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11018 | if (ring == NULL) |
| 11019 | return true; |
| 11020 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11021 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 11022 | return false; |
| 11023 | |
| 11024 | if (i915.use_mmio_flip < 0) |
| 11025 | return false; |
| 11026 | else if (i915.use_mmio_flip > 0) |
| 11027 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 11028 | else if (i915.enable_execlists) |
| 11029 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11030 | else |
Chris Wilson | b471618 | 2015-04-27 13:41:17 +0100 | [diff] [blame] | 11031 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11032 | } |
| 11033 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11034 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 11035 | { |
| 11036 | struct drm_device *dev = intel_crtc->base.dev; |
| 11037 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11038 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11039 | const enum pipe pipe = intel_crtc->pipe; |
| 11040 | u32 ctl, stride; |
| 11041 | |
| 11042 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 11043 | ctl &= ~PLANE_CTL_TILED_MASK; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11044 | switch (fb->modifier[0]) { |
| 11045 | case DRM_FORMAT_MOD_NONE: |
| 11046 | break; |
| 11047 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11048 | ctl |= PLANE_CTL_TILED_X; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11049 | break; |
| 11050 | case I915_FORMAT_MOD_Y_TILED: |
| 11051 | ctl |= PLANE_CTL_TILED_Y; |
| 11052 | break; |
| 11053 | case I915_FORMAT_MOD_Yf_TILED: |
| 11054 | ctl |= PLANE_CTL_TILED_YF; |
| 11055 | break; |
| 11056 | default: |
| 11057 | MISSING_CASE(fb->modifier[0]); |
| 11058 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11059 | |
| 11060 | /* |
| 11061 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 11062 | * linear buffers or in number of tiles for tiled buffers. |
| 11063 | */ |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11064 | stride = fb->pitches[0] / |
| 11065 | intel_fb_stride_alignment(dev, fb->modifier[0], |
| 11066 | fb->pixel_format); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11067 | |
| 11068 | /* |
| 11069 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 11070 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 11071 | */ |
| 11072 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 11073 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 11074 | |
| 11075 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); |
| 11076 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 11077 | } |
| 11078 | |
| 11079 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11080 | { |
| 11081 | struct drm_device *dev = intel_crtc->base.dev; |
| 11082 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11083 | struct intel_framebuffer *intel_fb = |
| 11084 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 11085 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 11086 | u32 dspcntr; |
| 11087 | u32 reg; |
| 11088 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11089 | reg = DSPCNTR(intel_crtc->plane); |
| 11090 | dspcntr = I915_READ(reg); |
| 11091 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 11092 | if (obj->tiling_mode != I915_TILING_NONE) |
| 11093 | dspcntr |= DISPPLANE_TILED; |
| 11094 | else |
| 11095 | dspcntr &= ~DISPPLANE_TILED; |
| 11096 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11097 | I915_WRITE(reg, dspcntr); |
| 11098 | |
| 11099 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 11100 | intel_crtc->unpin_work->gtt_offset); |
| 11101 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 11102 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11103 | } |
| 11104 | |
| 11105 | /* |
| 11106 | * XXX: This is the temporary way to update the plane registers until we get |
| 11107 | * around to using the usual plane update functions for MMIO flips |
| 11108 | */ |
| 11109 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 11110 | { |
| 11111 | struct drm_device *dev = intel_crtc->base.dev; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11112 | u32 start_vbl_count; |
| 11113 | |
| 11114 | intel_mark_page_flip_active(intel_crtc); |
| 11115 | |
Maarten Lankhorst | 8f539a8 | 2015-07-13 16:30:32 +0200 | [diff] [blame] | 11116 | intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11117 | |
| 11118 | if (INTEL_INFO(dev)->gen >= 9) |
| 11119 | skl_do_mmio_flip(intel_crtc); |
| 11120 | else |
| 11121 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 11122 | ilk_do_mmio_flip(intel_crtc); |
| 11123 | |
Maarten Lankhorst | 8f539a8 | 2015-07-13 16:30:32 +0200 | [diff] [blame] | 11124 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11125 | } |
| 11126 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 11127 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11128 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11129 | struct intel_mmio_flip *mmio_flip = |
| 11130 | container_of(work, struct intel_mmio_flip, work); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11131 | |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11132 | if (mmio_flip->req) |
| 11133 | WARN_ON(__i915_wait_request(mmio_flip->req, |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11134 | mmio_flip->crtc->reset_counter, |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11135 | false, NULL, |
| 11136 | &mmio_flip->i915->rps.mmioflips)); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11137 | |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11138 | intel_do_mmio_flip(mmio_flip->crtc); |
| 11139 | |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11140 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11141 | kfree(mmio_flip); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11142 | } |
| 11143 | |
| 11144 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 11145 | struct drm_crtc *crtc, |
| 11146 | struct drm_framebuffer *fb, |
| 11147 | struct drm_i915_gem_object *obj, |
| 11148 | struct intel_engine_cs *ring, |
| 11149 | uint32_t flags) |
| 11150 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11151 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11152 | |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11153 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); |
| 11154 | if (mmio_flip == NULL) |
| 11155 | return -ENOMEM; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11156 | |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11157 | mmio_flip->i915 = to_i915(dev); |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11158 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11159 | mmio_flip->crtc = to_intel_crtc(crtc); |
| 11160 | |
| 11161 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
| 11162 | schedule_work(&mmio_flip->work); |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 11163 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11164 | return 0; |
| 11165 | } |
| 11166 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11167 | static int intel_default_queue_flip(struct drm_device *dev, |
| 11168 | struct drm_crtc *crtc, |
| 11169 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11170 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11171 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11172 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11173 | { |
| 11174 | return -ENODEV; |
| 11175 | } |
| 11176 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11177 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 11178 | struct drm_crtc *crtc) |
| 11179 | { |
| 11180 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11181 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11182 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 11183 | u32 addr; |
| 11184 | |
| 11185 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 11186 | return true; |
| 11187 | |
Chris Wilson | 908565c | 2015-08-12 13:08:22 +0100 | [diff] [blame] | 11188 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
| 11189 | return false; |
| 11190 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11191 | if (!work->enable_stall_check) |
| 11192 | return false; |
| 11193 | |
| 11194 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 11195 | if (work->flip_queued_req && |
| 11196 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11197 | return false; |
| 11198 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11199 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11200 | } |
| 11201 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11202 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11203 | return false; |
| 11204 | |
| 11205 | /* Potential stall - if we see that the flip has happened, |
| 11206 | * assume a missed interrupt. */ |
| 11207 | if (INTEL_INFO(dev)->gen >= 4) |
| 11208 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 11209 | else |
| 11210 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 11211 | |
| 11212 | /* There is a potential issue here with a false positive after a flip |
| 11213 | * to the same address. We could address this by checking for a |
| 11214 | * non-incrementing frame counter. |
| 11215 | */ |
| 11216 | return addr == work->gtt_offset; |
| 11217 | } |
| 11218 | |
| 11219 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 11220 | { |
| 11221 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11222 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 11223 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11224 | struct intel_unpin_work *work; |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11225 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 11226 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11227 | |
| 11228 | if (crtc == NULL) |
| 11229 | return; |
| 11230 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11231 | spin_lock(&dev->event_lock); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11232 | work = intel_crtc->unpin_work; |
| 11233 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11234 | 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] | 11235 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11236 | page_flip_completed(intel_crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11237 | work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11238 | } |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11239 | if (work != NULL && |
| 11240 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) |
| 11241 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11242 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11243 | } |
| 11244 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11245 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 11246 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11247 | struct drm_pending_vblank_event *event, |
| 11248 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11249 | { |
| 11250 | struct drm_device *dev = crtc->dev; |
| 11251 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11252 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11253 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11254 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11255 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11256 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11257 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 11258 | struct intel_engine_cs *ring; |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11259 | bool mmio_flip; |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11260 | struct drm_i915_gem_request *request = NULL; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 11261 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11262 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11263 | /* |
| 11264 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 11265 | * check to be safe. In the future we may enable pageflipping from |
| 11266 | * a disabled primary plane. |
| 11267 | */ |
| 11268 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 11269 | return -EBUSY; |
| 11270 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11271 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11272 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11273 | return -EINVAL; |
| 11274 | |
| 11275 | /* |
| 11276 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 11277 | * Note that pitch changes could also affect these register. |
| 11278 | */ |
| 11279 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11280 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 11281 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11282 | return -EINVAL; |
| 11283 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11284 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 11285 | goto out_hang; |
| 11286 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 11287 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11288 | if (work == NULL) |
| 11289 | return -ENOMEM; |
| 11290 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11291 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11292 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11293 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11294 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 11295 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11296 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11297 | if (ret) |
| 11298 | goto free_work; |
| 11299 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11300 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11301 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11302 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11303 | /* Before declaring the flip queue wedged, check if |
| 11304 | * the hardware completed the operation behind our backs. |
| 11305 | */ |
| 11306 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 11307 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 11308 | page_flip_completed(intel_crtc); |
| 11309 | } else { |
| 11310 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11311 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 11312 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11313 | drm_crtc_vblank_put(crtc); |
| 11314 | kfree(work); |
| 11315 | return -EBUSY; |
| 11316 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11317 | } |
| 11318 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11319 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11320 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11321 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 11322 | flush_workqueue(dev_priv->wq); |
| 11323 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 11324 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11325 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 11326 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11327 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11328 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11329 | update_state_fb(crtc->primary); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 11330 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11331 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11332 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11333 | ret = i915_mutex_lock_interruptible(dev); |
| 11334 | if (ret) |
| 11335 | goto cleanup; |
| 11336 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11337 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 11338 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11339 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11340 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11341 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11342 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11343 | if (IS_VALLEYVIEW(dev)) { |
| 11344 | ring = &dev_priv->ring[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11345 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11346 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 11347 | ring = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 11348 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 11349 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11350 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Chris Wilson | b471618 | 2015-04-27 13:41:17 +0100 | [diff] [blame] | 11351 | ring = i915_gem_request_get_ring(obj->last_write_req); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11352 | if (ring == NULL || ring->id != RCS) |
| 11353 | ring = &dev_priv->ring[BCS]; |
| 11354 | } else { |
| 11355 | ring = &dev_priv->ring[RCS]; |
| 11356 | } |
| 11357 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11358 | mmio_flip = use_mmio_flip(ring, obj); |
| 11359 | |
| 11360 | /* When using CS flips, we want to emit semaphores between rings. |
| 11361 | * However, when using mmio flips we will create a task to do the |
| 11362 | * synchronisation, so all we want here is to pin the framebuffer |
| 11363 | * into the display plane and skip any waits. |
| 11364 | */ |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 11365 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11366 | crtc->primary->state, |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11367 | mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring, &request); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11368 | if (ret) |
| 11369 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11370 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 11371 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
| 11372 | + intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11373 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11374 | if (mmio_flip) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11375 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 11376 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11377 | if (ret) |
| 11378 | goto cleanup_unpin; |
| 11379 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 11380 | i915_gem_request_assign(&work->flip_queued_req, |
| 11381 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11382 | } else { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11383 | if (!request) { |
| 11384 | ret = i915_gem_request_alloc(ring, ring->default_context, &request); |
| 11385 | if (ret) |
| 11386 | goto cleanup_unpin; |
| 11387 | } |
| 11388 | |
| 11389 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11390 | page_flip_flags); |
| 11391 | if (ret) |
| 11392 | goto cleanup_unpin; |
| 11393 | |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11394 | i915_gem_request_assign(&work->flip_queued_req, request); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11395 | } |
| 11396 | |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11397 | if (request) |
John Harrison | 7528987 | 2015-05-29 17:43:49 +0100 | [diff] [blame] | 11398 | i915_add_request_no_flush(request); |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11399 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11400 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11401 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11402 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11403 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11404 | to_intel_plane(primary)->frontbuffer_bit); |
Paulo Zanoni | c80ac85 | 2015-07-02 19:25:13 -0300 | [diff] [blame] | 11405 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11406 | |
Paulo Zanoni | 4e1e26f | 2015-07-14 16:29:13 -0300 | [diff] [blame] | 11407 | intel_fbc_disable_crtc(intel_crtc); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11408 | intel_frontbuffer_flip_prepare(dev, |
| 11409 | to_intel_plane(primary)->frontbuffer_bit); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11410 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 11411 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 11412 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11413 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11414 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11415 | cleanup_unpin: |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 11416 | intel_unpin_fb_obj(fb, crtc->primary->state); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11417 | cleanup_pending: |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11418 | if (request) |
| 11419 | i915_gem_request_cancel(request); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11420 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11421 | mutex_unlock(&dev->struct_mutex); |
| 11422 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11423 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11424 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11425 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11426 | drm_gem_object_unreference_unlocked(&obj->base); |
| 11427 | drm_framebuffer_unreference(work->old_fb); |
| 11428 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11429 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11430 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11431 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11432 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11433 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11434 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11435 | kfree(work); |
| 11436 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11437 | if (ret == -EIO) { |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11438 | struct drm_atomic_state *state; |
| 11439 | struct drm_plane_state *plane_state; |
| 11440 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11441 | out_hang: |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11442 | state = drm_atomic_state_alloc(dev); |
| 11443 | if (!state) |
| 11444 | return -ENOMEM; |
| 11445 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 11446 | |
| 11447 | retry: |
| 11448 | plane_state = drm_atomic_get_plane_state(state, primary); |
| 11449 | ret = PTR_ERR_OR_ZERO(plane_state); |
| 11450 | if (!ret) { |
| 11451 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 11452 | |
| 11453 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 11454 | if (!ret) |
| 11455 | ret = drm_atomic_commit(state); |
| 11456 | } |
| 11457 | |
| 11458 | if (ret == -EDEADLK) { |
| 11459 | drm_modeset_backoff(state->acquire_ctx); |
| 11460 | drm_atomic_state_clear(state); |
| 11461 | goto retry; |
| 11462 | } |
| 11463 | |
| 11464 | if (ret) |
| 11465 | drm_atomic_state_free(state); |
| 11466 | |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11467 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11468 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11469 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11470 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11471 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11472 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11473 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11474 | } |
| 11475 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11476 | |
| 11477 | /** |
| 11478 | * intel_wm_need_update - Check whether watermarks need updating |
| 11479 | * @plane: drm plane |
| 11480 | * @state: new plane state |
| 11481 | * |
| 11482 | * Check current plane state versus the new one to determine whether |
| 11483 | * watermarks need to be recalculated. |
| 11484 | * |
| 11485 | * Returns true or false. |
| 11486 | */ |
| 11487 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 11488 | struct drm_plane_state *state) |
| 11489 | { |
| 11490 | /* Update watermarks on tiling changes. */ |
| 11491 | if (!plane->state->fb || !state->fb || |
| 11492 | plane->state->fb->modifier[0] != state->fb->modifier[0] || |
| 11493 | plane->state->rotation != state->rotation) |
| 11494 | return true; |
| 11495 | |
| 11496 | if (plane->state->crtc_w != state->crtc_w) |
| 11497 | return true; |
| 11498 | |
| 11499 | return false; |
| 11500 | } |
| 11501 | |
| 11502 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
| 11503 | struct drm_plane_state *plane_state) |
| 11504 | { |
| 11505 | struct drm_crtc *crtc = crtc_state->crtc; |
| 11506 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11507 | struct drm_plane *plane = plane_state->plane; |
| 11508 | struct drm_device *dev = crtc->dev; |
| 11509 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11510 | struct intel_plane_state *old_plane_state = |
| 11511 | to_intel_plane_state(plane->state); |
| 11512 | int idx = intel_crtc->base.base.id, ret; |
| 11513 | int i = drm_plane_index(plane); |
| 11514 | bool mode_changed = needs_modeset(crtc_state); |
| 11515 | bool was_crtc_enabled = crtc->state->active; |
| 11516 | bool is_crtc_enabled = crtc_state->active; |
| 11517 | |
| 11518 | bool turn_off, turn_on, visible, was_visible; |
| 11519 | struct drm_framebuffer *fb = plane_state->fb; |
| 11520 | |
| 11521 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && |
| 11522 | plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11523 | ret = skl_update_scaler_plane( |
| 11524 | to_intel_crtc_state(crtc_state), |
| 11525 | to_intel_plane_state(plane_state)); |
| 11526 | if (ret) |
| 11527 | return ret; |
| 11528 | } |
| 11529 | |
| 11530 | /* |
| 11531 | * Disabling a plane is always okay; we just need to update |
| 11532 | * fb tracking in a special way since cleanup_fb() won't |
| 11533 | * get called by the plane helpers. |
| 11534 | */ |
| 11535 | if (old_plane_state->base.fb && !fb) |
| 11536 | intel_crtc->atomic.disabled_planes |= 1 << i; |
| 11537 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11538 | was_visible = old_plane_state->visible; |
| 11539 | visible = to_intel_plane_state(plane_state)->visible; |
| 11540 | |
| 11541 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 11542 | was_visible = false; |
| 11543 | |
| 11544 | if (!is_crtc_enabled && WARN_ON(visible)) |
| 11545 | visible = false; |
| 11546 | |
| 11547 | if (!was_visible && !visible) |
| 11548 | return 0; |
| 11549 | |
| 11550 | turn_off = was_visible && (!visible || mode_changed); |
| 11551 | turn_on = visible && (!was_visible || mode_changed); |
| 11552 | |
| 11553 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, |
| 11554 | plane->base.id, fb ? fb->base.id : -1); |
| 11555 | |
| 11556 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", |
| 11557 | plane->base.id, was_visible, visible, |
| 11558 | turn_off, turn_on, mode_changed); |
| 11559 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11560 | if (turn_on) { |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 11561 | intel_crtc->atomic.update_wm_pre = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11562 | /* must disable cxsr around plane enable/disable */ |
| 11563 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11564 | intel_crtc->atomic.disable_cxsr = true; |
| 11565 | /* to potentially re-enable cxsr */ |
| 11566 | intel_crtc->atomic.wait_vblank = true; |
| 11567 | intel_crtc->atomic.update_wm_post = true; |
| 11568 | } |
| 11569 | } else if (turn_off) { |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 11570 | intel_crtc->atomic.update_wm_post = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11571 | /* must disable cxsr around plane enable/disable */ |
| 11572 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11573 | if (is_crtc_enabled) |
| 11574 | intel_crtc->atomic.wait_vblank = true; |
| 11575 | intel_crtc->atomic.disable_cxsr = true; |
| 11576 | } |
| 11577 | } else if (intel_wm_need_update(plane, plane_state)) { |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 11578 | intel_crtc->atomic.update_wm_pre = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11579 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11580 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 11581 | if (visible || was_visible) |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11582 | intel_crtc->atomic.fb_bits |= |
| 11583 | to_intel_plane(plane)->frontbuffer_bit; |
| 11584 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11585 | switch (plane->type) { |
| 11586 | case DRM_PLANE_TYPE_PRIMARY: |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11587 | intel_crtc->atomic.wait_for_flips = true; |
| 11588 | intel_crtc->atomic.pre_disable_primary = turn_off; |
| 11589 | intel_crtc->atomic.post_enable_primary = turn_on; |
| 11590 | |
Rodrigo Vivi | 066cf55b | 2015-06-26 13:55:54 -0700 | [diff] [blame] | 11591 | if (turn_off) { |
| 11592 | /* |
| 11593 | * FIXME: Actually if we will still have any other |
| 11594 | * plane enabled on the pipe we could let IPS enabled |
| 11595 | * still, but for now lets consider that when we make |
| 11596 | * primary invisible by setting DSPCNTR to 0 on |
| 11597 | * update_primary_plane function IPS needs to be |
| 11598 | * disable. |
| 11599 | */ |
| 11600 | intel_crtc->atomic.disable_ips = true; |
| 11601 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11602 | intel_crtc->atomic.disable_fbc = true; |
Rodrigo Vivi | 066cf55b | 2015-06-26 13:55:54 -0700 | [diff] [blame] | 11603 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11604 | |
| 11605 | /* |
| 11606 | * FBC does not work on some platforms for rotated |
| 11607 | * planes, so disable it when rotation is not 0 and |
| 11608 | * update it when rotation is set back to 0. |
| 11609 | * |
| 11610 | * FIXME: This is redundant with the fbc update done in |
| 11611 | * the primary plane enable function except that that |
| 11612 | * one is done too late. We eventually need to unify |
| 11613 | * this. |
| 11614 | */ |
| 11615 | |
| 11616 | if (visible && |
| 11617 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 11618 | dev_priv->fbc.crtc == intel_crtc && |
| 11619 | plane_state->rotation != BIT(DRM_ROTATE_0)) |
| 11620 | intel_crtc->atomic.disable_fbc = true; |
| 11621 | |
| 11622 | /* |
| 11623 | * BDW signals flip done immediately if the plane |
| 11624 | * is disabled, even if the plane enable is already |
| 11625 | * armed to occur at the next vblank :( |
| 11626 | */ |
| 11627 | if (turn_on && IS_BROADWELL(dev)) |
| 11628 | intel_crtc->atomic.wait_vblank = true; |
| 11629 | |
| 11630 | intel_crtc->atomic.update_fbc |= visible || mode_changed; |
| 11631 | break; |
| 11632 | case DRM_PLANE_TYPE_CURSOR: |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11633 | break; |
| 11634 | case DRM_PLANE_TYPE_OVERLAY: |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 11635 | if (turn_off && !mode_changed) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11636 | intel_crtc->atomic.wait_vblank = true; |
| 11637 | intel_crtc->atomic.update_sprite_watermarks |= |
| 11638 | 1 << i; |
| 11639 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11640 | } |
| 11641 | return 0; |
| 11642 | } |
| 11643 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11644 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11645 | const struct intel_encoder *b) |
| 11646 | { |
| 11647 | /* masks could be asymmetric, so check both ways */ |
| 11648 | return a == b || (a->cloneable & (1 << b->type) && |
| 11649 | b->cloneable & (1 << a->type)); |
| 11650 | } |
| 11651 | |
| 11652 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11653 | struct intel_crtc *crtc, |
| 11654 | struct intel_encoder *encoder) |
| 11655 | { |
| 11656 | struct intel_encoder *source_encoder; |
| 11657 | struct drm_connector *connector; |
| 11658 | struct drm_connector_state *connector_state; |
| 11659 | int i; |
| 11660 | |
| 11661 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11662 | if (connector_state->crtc != &crtc->base) |
| 11663 | continue; |
| 11664 | |
| 11665 | source_encoder = |
| 11666 | to_intel_encoder(connector_state->best_encoder); |
| 11667 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11668 | return false; |
| 11669 | } |
| 11670 | |
| 11671 | return true; |
| 11672 | } |
| 11673 | |
| 11674 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 11675 | struct intel_crtc *crtc) |
| 11676 | { |
| 11677 | struct intel_encoder *encoder; |
| 11678 | struct drm_connector *connector; |
| 11679 | struct drm_connector_state *connector_state; |
| 11680 | int i; |
| 11681 | |
| 11682 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11683 | if (connector_state->crtc != &crtc->base) |
| 11684 | continue; |
| 11685 | |
| 11686 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11687 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
| 11688 | return false; |
| 11689 | } |
| 11690 | |
| 11691 | return true; |
| 11692 | } |
| 11693 | |
| 11694 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 11695 | struct drm_crtc_state *crtc_state) |
| 11696 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11697 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11698 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11699 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11700 | struct intel_crtc_state *pipe_config = |
| 11701 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11702 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11703 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11704 | bool mode_changed = needs_modeset(crtc_state); |
| 11705 | |
| 11706 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { |
| 11707 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11708 | return -EINVAL; |
| 11709 | } |
| 11710 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11711 | if (mode_changed && !crtc_state->active) |
| 11712 | intel_crtc->atomic.update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11713 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11714 | if (mode_changed && crtc_state->enable && |
| 11715 | dev_priv->display.crtc_compute_clock && |
| 11716 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { |
| 11717 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11718 | pipe_config); |
| 11719 | if (ret) |
| 11720 | return ret; |
| 11721 | } |
| 11722 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11723 | ret = 0; |
| 11724 | if (INTEL_INFO(dev)->gen >= 9) { |
| 11725 | if (mode_changed) |
| 11726 | ret = skl_update_scaler_crtc(pipe_config); |
| 11727 | |
| 11728 | if (!ret) |
| 11729 | ret = intel_atomic_setup_scalers(dev, intel_crtc, |
| 11730 | pipe_config); |
| 11731 | } |
| 11732 | |
| 11733 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11734 | } |
| 11735 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11736 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11737 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 11738 | .load_lut = intel_crtc_load_lut, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 11739 | .atomic_begin = intel_begin_crtc_commit, |
| 11740 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11741 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11742 | }; |
| 11743 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11744 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11745 | { |
| 11746 | struct intel_connector *connector; |
| 11747 | |
| 11748 | for_each_intel_connector(dev, connector) { |
| 11749 | if (connector->base.encoder) { |
| 11750 | connector->base.state->best_encoder = |
| 11751 | connector->base.encoder; |
| 11752 | connector->base.state->crtc = |
| 11753 | connector->base.encoder->crtc; |
| 11754 | } else { |
| 11755 | connector->base.state->best_encoder = NULL; |
| 11756 | connector->base.state->crtc = NULL; |
| 11757 | } |
| 11758 | } |
| 11759 | } |
| 11760 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11761 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 11762 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11763 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11764 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11765 | int bpp = pipe_config->pipe_bpp; |
| 11766 | |
| 11767 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 11768 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11769 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11770 | |
| 11771 | /* Don't use an invalid EDID bpc value */ |
| 11772 | if (connector->base.display_info.bpc && |
| 11773 | connector->base.display_info.bpc * 3 < bpp) { |
| 11774 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 11775 | bpp, connector->base.display_info.bpc*3); |
| 11776 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 11777 | } |
| 11778 | |
| 11779 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 11780 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 11781 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 11782 | bpp); |
| 11783 | pipe_config->pipe_bpp = 24; |
| 11784 | } |
| 11785 | } |
| 11786 | |
| 11787 | static int |
| 11788 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11789 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11790 | { |
| 11791 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11792 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11793 | struct drm_connector *connector; |
| 11794 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11795 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11796 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11797 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11798 | bpp = 10*3; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11799 | else if (INTEL_INFO(dev)->gen >= 5) |
| 11800 | bpp = 12*3; |
| 11801 | else |
| 11802 | bpp = 8*3; |
| 11803 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11804 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11805 | pipe_config->pipe_bpp = bpp; |
| 11806 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11807 | state = pipe_config->base.state; |
| 11808 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11809 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11810 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11811 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11812 | continue; |
| 11813 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11814 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 11815 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11816 | } |
| 11817 | |
| 11818 | return bpp; |
| 11819 | } |
| 11820 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11821 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11822 | { |
| 11823 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11824 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11825 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11826 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11827 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11828 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11829 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11830 | } |
| 11831 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11832 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11833 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11834 | const char *context) |
| 11835 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11836 | struct drm_device *dev = crtc->base.dev; |
| 11837 | struct drm_plane *plane; |
| 11838 | struct intel_plane *intel_plane; |
| 11839 | struct intel_plane_state *state; |
| 11840 | struct drm_framebuffer *fb; |
| 11841 | |
| 11842 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 11843 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11844 | |
| 11845 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 11846 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 11847 | pipe_config->pipe_bpp, pipe_config->dither); |
| 11848 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11849 | pipe_config->has_pch_encoder, |
| 11850 | pipe_config->fdi_lanes, |
| 11851 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 11852 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 11853 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11854 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11855 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11856 | pipe_config->lane_count, |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11857 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 11858 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 11859 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11860 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11861 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11862 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11863 | pipe_config->lane_count, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11864 | pipe_config->dp_m2_n2.gmch_m, |
| 11865 | pipe_config->dp_m2_n2.gmch_n, |
| 11866 | pipe_config->dp_m2_n2.link_m, |
| 11867 | pipe_config->dp_m2_n2.link_n, |
| 11868 | pipe_config->dp_m2_n2.tu); |
| 11869 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11870 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 11871 | pipe_config->has_audio, |
| 11872 | pipe_config->has_infoframe); |
| 11873 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11874 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11875 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11876 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11877 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11878 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 11879 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 11880 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 11881 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Tvrtko Ursulin | 0ec463d | 2015-05-13 16:51:08 +0100 | [diff] [blame] | 11882 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11883 | crtc->num_scalers, |
| 11884 | pipe_config->scaler_state.scaler_users, |
| 11885 | pipe_config->scaler_state.scaler_id); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11886 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11887 | pipe_config->gmch_pfit.control, |
| 11888 | pipe_config->gmch_pfit.pgm_ratios, |
| 11889 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11890 | 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] | 11891 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11892 | pipe_config->pch_pfit.size, |
| 11893 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 11894 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 11895 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11896 | |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11897 | if (IS_BROXTON(dev)) { |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 11898 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11899 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 11900 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11901 | pipe_config->ddi_pll_sel, |
| 11902 | pipe_config->dpll_hw_state.ebb0, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 11903 | pipe_config->dpll_hw_state.ebb4, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11904 | pipe_config->dpll_hw_state.pll0, |
| 11905 | pipe_config->dpll_hw_state.pll1, |
| 11906 | pipe_config->dpll_hw_state.pll2, |
| 11907 | pipe_config->dpll_hw_state.pll3, |
| 11908 | pipe_config->dpll_hw_state.pll6, |
| 11909 | pipe_config->dpll_hw_state.pll8, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 11910 | pipe_config->dpll_hw_state.pll9, |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 11911 | pipe_config->dpll_hw_state.pll10, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11912 | pipe_config->dpll_hw_state.pcsdw12); |
| 11913 | } else if (IS_SKYLAKE(dev)) { |
| 11914 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
| 11915 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", |
| 11916 | pipe_config->ddi_pll_sel, |
| 11917 | pipe_config->dpll_hw_state.ctrl1, |
| 11918 | pipe_config->dpll_hw_state.cfgcr1, |
| 11919 | pipe_config->dpll_hw_state.cfgcr2); |
| 11920 | } else if (HAS_DDI(dev)) { |
| 11921 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", |
| 11922 | pipe_config->ddi_pll_sel, |
| 11923 | pipe_config->dpll_hw_state.wrpll); |
| 11924 | } else { |
| 11925 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " |
| 11926 | "fp0: 0x%x, fp1: 0x%x\n", |
| 11927 | pipe_config->dpll_hw_state.dpll, |
| 11928 | pipe_config->dpll_hw_state.dpll_md, |
| 11929 | pipe_config->dpll_hw_state.fp0, |
| 11930 | pipe_config->dpll_hw_state.fp1); |
| 11931 | } |
| 11932 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11933 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11934 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 11935 | intel_plane = to_intel_plane(plane); |
| 11936 | if (intel_plane->pipe != crtc->pipe) |
| 11937 | continue; |
| 11938 | |
| 11939 | state = to_intel_plane_state(plane->state); |
| 11940 | fb = state->base.fb; |
| 11941 | if (!fb) { |
| 11942 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 11943 | "disabled, scaler_id = %d\n", |
| 11944 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 11945 | plane->base.id, intel_plane->pipe, |
| 11946 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 11947 | drm_plane_index(plane), state->scaler_id); |
| 11948 | continue; |
| 11949 | } |
| 11950 | |
| 11951 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 11952 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 11953 | plane->base.id, intel_plane->pipe, |
| 11954 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 11955 | drm_plane_index(plane)); |
| 11956 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 11957 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 11958 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 11959 | state->scaler_id, |
| 11960 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 11961 | drm_rect_width(&state->src) >> 16, |
| 11962 | drm_rect_height(&state->src) >> 16, |
| 11963 | state->dst.x1, state->dst.y1, |
| 11964 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 11965 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11966 | } |
| 11967 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11968 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11969 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11970 | struct drm_device *dev = state->dev; |
| 11971 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11972 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11973 | struct drm_connector_state *connector_state; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11974 | unsigned int used_ports = 0; |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11975 | int i; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11976 | |
| 11977 | /* |
| 11978 | * Walk the connector list instead of the encoder |
| 11979 | * list to detect the problem on ddi platforms |
| 11980 | * where there's just one encoder per digital port. |
| 11981 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11982 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11983 | if (!connector_state->best_encoder) |
| 11984 | continue; |
| 11985 | |
| 11986 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11987 | |
| 11988 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11989 | |
| 11990 | switch (encoder->type) { |
| 11991 | unsigned int port_mask; |
| 11992 | case INTEL_OUTPUT_UNKNOWN: |
| 11993 | if (WARN_ON(!HAS_DDI(dev))) |
| 11994 | break; |
| 11995 | case INTEL_OUTPUT_DISPLAYPORT: |
| 11996 | case INTEL_OUTPUT_HDMI: |
| 11997 | case INTEL_OUTPUT_EDP: |
| 11998 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 11999 | |
| 12000 | /* the same port mustn't appear more than once */ |
| 12001 | if (used_ports & port_mask) |
| 12002 | return false; |
| 12003 | |
| 12004 | used_ports |= port_mask; |
| 12005 | default: |
| 12006 | break; |
| 12007 | } |
| 12008 | } |
| 12009 | |
| 12010 | return true; |
| 12011 | } |
| 12012 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12013 | static void |
| 12014 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 12015 | { |
| 12016 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12017 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12018 | struct intel_dpll_hw_state dpll_hw_state; |
| 12019 | enum intel_dpll_id shared_dpll; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12020 | uint32_t ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12021 | bool force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12022 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 12023 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 12024 | * kzalloc'd. Code that depends on any field being zero should be |
| 12025 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 12026 | * only fields that are know to not cause problems are preserved. */ |
| 12027 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12028 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12029 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12030 | shared_dpll = crtc_state->shared_dpll; |
| 12031 | dpll_hw_state = crtc_state->dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12032 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12033 | force_thru = crtc_state->pch_pfit.force_thru; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12034 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12035 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12036 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12037 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12038 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12039 | crtc_state->shared_dpll = shared_dpll; |
| 12040 | crtc_state->dpll_hw_state = dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12041 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12042 | crtc_state->pch_pfit.force_thru = force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12043 | } |
| 12044 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12045 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12046 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12047 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12048 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12049 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12050 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12051 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12052 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12053 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12054 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12055 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12056 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12057 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12058 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 12059 | pipe_config->cpu_transcoder = |
| 12060 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12061 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12062 | /* |
| 12063 | * Sanitize sync polarity flags based on requested ones. If neither |
| 12064 | * positive or negative polarity is requested, treat this as meaning |
| 12065 | * negative polarity. |
| 12066 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12067 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12068 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12069 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12070 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12071 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12072 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12073 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12074 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12075 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 12076 | * plane pixel format and any sink constraints into account. Returns the |
| 12077 | * source plane bpp so that dithering can be selected on mismatches |
| 12078 | * after encoders and crtc also have had their say. */ |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12079 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 12080 | pipe_config); |
| 12081 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12082 | goto fail; |
| 12083 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12084 | /* |
| 12085 | * Determine the real pipe dimensions. Note that stereo modes can |
| 12086 | * increase the actual pipe size due to the frame doubling and |
| 12087 | * insertion of additional space for blanks between the frame. This |
| 12088 | * is stored in the crtc timings. We use the requested mode to do this |
| 12089 | * computation to clearly distinguish it from the adjusted mode, which |
| 12090 | * can be changed by the connectors in the below retry loop. |
| 12091 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12092 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 12093 | &pipe_config->pipe_src_w, |
| 12094 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12095 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12096 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12097 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12098 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12099 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12100 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12101 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12102 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 12103 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12104 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12105 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 12106 | * adjust it according to limitations or connector properties, and also |
| 12107 | * a chance to reject the mode entirely. |
| 12108 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12109 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12110 | if (connector_state->crtc != crtc) |
| 12111 | continue; |
| 12112 | |
| 12113 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12114 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 12115 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 12116 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12117 | goto fail; |
| 12118 | } |
| 12119 | } |
| 12120 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12121 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 12122 | * done afterwards in case the encoder adjusts the mode. */ |
| 12123 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12124 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 12125 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12126 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 12127 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12128 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12129 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 12130 | goto fail; |
| 12131 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12132 | |
| 12133 | if (ret == RETRY) { |
| 12134 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 12135 | ret = -EINVAL; |
| 12136 | goto fail; |
| 12137 | } |
| 12138 | |
| 12139 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 12140 | retry = false; |
| 12141 | goto encoder_retry; |
| 12142 | } |
| 12143 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 12144 | /* Dithering seems to not pass-through bits correctly when it should, so |
| 12145 | * only enable it on 6bpc panels. */ |
| 12146 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12147 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12148 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12149 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12150 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12151 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12152 | } |
| 12153 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12154 | static void |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12155 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12156 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12157 | struct drm_crtc *crtc; |
| 12158 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 8a75d157c | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12159 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12160 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12161 | /* Double check state. */ |
Maarten Lankhorst | 8a75d157c | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12162 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 3cb480b | 2015-06-01 12:49:49 +0200 | [diff] [blame] | 12163 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 12164 | |
| 12165 | /* Update hwmode for vblank functions */ |
| 12166 | if (crtc->state->active) |
| 12167 | crtc->hwmode = crtc->state->adjusted_mode; |
| 12168 | else |
| 12169 | crtc->hwmode.crtc_clock = 0; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12170 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12171 | } |
| 12172 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12173 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12174 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12175 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12176 | |
| 12177 | if (clock1 == clock2) |
| 12178 | return true; |
| 12179 | |
| 12180 | if (!clock1 || !clock2) |
| 12181 | return false; |
| 12182 | |
| 12183 | diff = abs(clock1 - clock2); |
| 12184 | |
| 12185 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 12186 | return true; |
| 12187 | |
| 12188 | return false; |
| 12189 | } |
| 12190 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12191 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 12192 | list_for_each_entry((intel_crtc), \ |
| 12193 | &(dev)->mode_config.crtc_list, \ |
| 12194 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 12195 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12196 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12197 | |
| 12198 | static bool |
| 12199 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 12200 | unsigned int m2, unsigned int n2, |
| 12201 | bool exact) |
| 12202 | { |
| 12203 | if (m == m2 && n == n2) |
| 12204 | return true; |
| 12205 | |
| 12206 | if (exact || !m || !n || !m2 || !n2) |
| 12207 | return false; |
| 12208 | |
| 12209 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 12210 | |
| 12211 | if (m > m2) { |
| 12212 | while (m > m2) { |
| 12213 | m2 <<= 1; |
| 12214 | n2 <<= 1; |
| 12215 | } |
| 12216 | } else if (m < m2) { |
| 12217 | while (m < m2) { |
| 12218 | m <<= 1; |
| 12219 | n <<= 1; |
| 12220 | } |
| 12221 | } |
| 12222 | |
| 12223 | return m == m2 && n == n2; |
| 12224 | } |
| 12225 | |
| 12226 | static bool |
| 12227 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 12228 | struct intel_link_m_n *m2_n2, |
| 12229 | bool adjust) |
| 12230 | { |
| 12231 | if (m_n->tu == m2_n2->tu && |
| 12232 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 12233 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 12234 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 12235 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 12236 | if (adjust) |
| 12237 | *m2_n2 = *m_n; |
| 12238 | |
| 12239 | return true; |
| 12240 | } |
| 12241 | |
| 12242 | return false; |
| 12243 | } |
| 12244 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12245 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12246 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12247 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12248 | struct intel_crtc_state *pipe_config, |
| 12249 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12250 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12251 | bool ret = true; |
| 12252 | |
| 12253 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ |
| 12254 | do { \ |
| 12255 | if (!adjust) \ |
| 12256 | DRM_ERROR(fmt, ##__VA_ARGS__); \ |
| 12257 | else \ |
| 12258 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ |
| 12259 | } while (0) |
| 12260 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12261 | #define PIPE_CONF_CHECK_X(name) \ |
| 12262 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12263 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12264 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 12265 | current_config->name, \ |
| 12266 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12267 | ret = false; \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12268 | } |
| 12269 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12270 | #define PIPE_CONF_CHECK_I(name) \ |
| 12271 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12272 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12273 | "(expected %i, found %i)\n", \ |
| 12274 | current_config->name, \ |
| 12275 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12276 | ret = false; \ |
| 12277 | } |
| 12278 | |
| 12279 | #define PIPE_CONF_CHECK_M_N(name) \ |
| 12280 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12281 | &pipe_config->name,\ |
| 12282 | adjust)) { \ |
| 12283 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12284 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12285 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12286 | current_config->name.tu, \ |
| 12287 | current_config->name.gmch_m, \ |
| 12288 | current_config->name.gmch_n, \ |
| 12289 | current_config->name.link_m, \ |
| 12290 | current_config->name.link_n, \ |
| 12291 | pipe_config->name.tu, \ |
| 12292 | pipe_config->name.gmch_m, \ |
| 12293 | pipe_config->name.gmch_n, \ |
| 12294 | pipe_config->name.link_m, \ |
| 12295 | pipe_config->name.link_n); \ |
| 12296 | ret = false; \ |
| 12297 | } |
| 12298 | |
| 12299 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
| 12300 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12301 | &pipe_config->name, adjust) && \ |
| 12302 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 12303 | &pipe_config->name, adjust)) { \ |
| 12304 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12305 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12306 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 12307 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12308 | current_config->name.tu, \ |
| 12309 | current_config->name.gmch_m, \ |
| 12310 | current_config->name.gmch_n, \ |
| 12311 | current_config->name.link_m, \ |
| 12312 | current_config->name.link_n, \ |
| 12313 | current_config->alt_name.tu, \ |
| 12314 | current_config->alt_name.gmch_m, \ |
| 12315 | current_config->alt_name.gmch_n, \ |
| 12316 | current_config->alt_name.link_m, \ |
| 12317 | current_config->alt_name.link_n, \ |
| 12318 | pipe_config->name.tu, \ |
| 12319 | pipe_config->name.gmch_m, \ |
| 12320 | pipe_config->name.gmch_n, \ |
| 12321 | pipe_config->name.link_m, \ |
| 12322 | pipe_config->name.link_n); \ |
| 12323 | ret = false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 12324 | } |
| 12325 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12326 | /* This is required for BDW+ where there is only one set of registers for |
| 12327 | * switching between high and low RR. |
| 12328 | * This macro can be used whenever a comparison has to be made between one |
| 12329 | * hw state and multiple sw state variables. |
| 12330 | */ |
| 12331 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 12332 | if ((current_config->name != pipe_config->name) && \ |
| 12333 | (current_config->alt_name != pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12334 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12335 | "(expected %i or %i, found %i)\n", \ |
| 12336 | current_config->name, \ |
| 12337 | current_config->alt_name, \ |
| 12338 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12339 | ret = false; \ |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12340 | } |
| 12341 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12342 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 12343 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12344 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12345 | "(expected %i, found %i)\n", \ |
| 12346 | current_config->name & (mask), \ |
| 12347 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12348 | ret = false; \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12349 | } |
| 12350 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12351 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 12352 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12353 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12354 | "(expected %i, found %i)\n", \ |
| 12355 | current_config->name, \ |
| 12356 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12357 | ret = false; \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12358 | } |
| 12359 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12360 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12361 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12362 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12363 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12364 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12365 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 12366 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12367 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12368 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12369 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12370 | PIPE_CONF_CHECK_I(lane_count); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12371 | |
| 12372 | if (INTEL_INFO(dev)->gen < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12373 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12374 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12375 | PIPE_CONF_CHECK_I(has_drrs); |
| 12376 | if (current_config->has_drrs) |
| 12377 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12378 | } else |
| 12379 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12380 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12381 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12382 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12383 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12384 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12385 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12386 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12387 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12388 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12389 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12390 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12391 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12392 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12393 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12394 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12395 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 12396 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12397 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 12398 | IS_VALLEYVIEW(dev)) |
| 12399 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 12400 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12401 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12402 | PIPE_CONF_CHECK_I(has_audio); |
| 12403 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12404 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12405 | DRM_MODE_FLAG_INTERLACE); |
| 12406 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12407 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12408 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12409 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12410 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12411 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12412 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12413 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12414 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12415 | DRM_MODE_FLAG_NVSYNC); |
| 12416 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12417 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 12418 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12419 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12420 | |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12421 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 12422 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 12423 | if (INTEL_INFO(dev)->gen < 4) |
| 12424 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 12425 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12426 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12427 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 12428 | if (current_config->pch_pfit.enabled) { |
| 12429 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 12430 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 12431 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12432 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12433 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 12434 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 12435 | /* BDW+ don't expose a synchronous way to read the state */ |
| 12436 | if (IS_HASWELL(dev)) |
| 12437 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12438 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12439 | PIPE_CONF_CHECK_I(double_wide); |
| 12440 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 12441 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 12442 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12443 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12444 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12445 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12446 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12447 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12448 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12449 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12450 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12451 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12452 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12453 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 12454 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12455 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12456 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12457 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12458 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12459 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12460 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12461 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12462 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12463 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12464 | #undef PIPE_CONF_QUIRK |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12465 | #undef INTEL_ERR_OR_DBG_KMS |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12466 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12467 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12468 | } |
| 12469 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12470 | static void check_wm_state(struct drm_device *dev) |
| 12471 | { |
| 12472 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12473 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 12474 | struct intel_crtc *intel_crtc; |
| 12475 | int plane; |
| 12476 | |
| 12477 | if (INTEL_INFO(dev)->gen < 9) |
| 12478 | return; |
| 12479 | |
| 12480 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12481 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12482 | |
| 12483 | for_each_intel_crtc(dev, intel_crtc) { |
| 12484 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 12485 | const enum pipe pipe = intel_crtc->pipe; |
| 12486 | |
| 12487 | if (!intel_crtc->active) |
| 12488 | continue; |
| 12489 | |
| 12490 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 12491 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12492 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 12493 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 12494 | |
| 12495 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12496 | continue; |
| 12497 | |
| 12498 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 12499 | "(expected (%u,%u), found (%u,%u))\n", |
| 12500 | pipe_name(pipe), plane + 1, |
| 12501 | sw_entry->start, sw_entry->end, |
| 12502 | hw_entry->start, hw_entry->end); |
| 12503 | } |
| 12504 | |
| 12505 | /* cursor */ |
| 12506 | hw_entry = &hw_ddb.cursor[pipe]; |
| 12507 | sw_entry = &sw_ddb->cursor[pipe]; |
| 12508 | |
| 12509 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12510 | continue; |
| 12511 | |
| 12512 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 12513 | "(expected (%u,%u), found (%u,%u))\n", |
| 12514 | pipe_name(pipe), |
| 12515 | sw_entry->start, sw_entry->end, |
| 12516 | hw_entry->start, hw_entry->end); |
| 12517 | } |
| 12518 | } |
| 12519 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12520 | static void |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12521 | check_connector_state(struct drm_device *dev, |
| 12522 | struct drm_atomic_state *old_state) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12523 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12524 | struct drm_connector_state *old_conn_state; |
| 12525 | struct drm_connector *connector; |
| 12526 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12527 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12528 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 12529 | struct drm_encoder *encoder = connector->encoder; |
| 12530 | struct drm_connector_state *state = connector->state; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12531 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12532 | /* This also checks the encoder/connector hw state with the |
| 12533 | * ->get_hw_state callbacks. */ |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12534 | intel_connector_check_state(to_intel_connector(connector)); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12535 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12536 | I915_STATE_WARN(state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12537 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12538 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12539 | } |
| 12540 | |
| 12541 | static void |
| 12542 | check_encoder_state(struct drm_device *dev) |
| 12543 | { |
| 12544 | struct intel_encoder *encoder; |
| 12545 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12546 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12547 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12548 | bool enabled = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12549 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12550 | |
| 12551 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12552 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12553 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12554 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12555 | for_each_intel_connector(dev, connector) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12556 | if (connector->base.state->best_encoder != &encoder->base) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12557 | continue; |
| 12558 | enabled = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12559 | |
| 12560 | I915_STATE_WARN(connector->base.state->crtc != |
| 12561 | encoder->base.crtc, |
| 12562 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12563 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12564 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12565 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12566 | "encoder's enabled state mismatch " |
| 12567 | "(expected %i, found %i)\n", |
| 12568 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12569 | |
| 12570 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12571 | bool active; |
| 12572 | |
| 12573 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12574 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12575 | "encoder detached but still enabled on pipe %c.\n", |
| 12576 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12577 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12578 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12579 | } |
| 12580 | |
| 12581 | static void |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12582 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12583 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12584 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12585 | struct intel_encoder *encoder; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12586 | struct drm_crtc_state *old_crtc_state; |
| 12587 | struct drm_crtc *crtc; |
| 12588 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12589 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12590 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 12591 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12592 | struct intel_crtc_state *pipe_config, *sw_config; |
Maarten Lankhorst | 7b89b8d | 2015-08-05 12:37:03 +0200 | [diff] [blame] | 12593 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12594 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12595 | if (!needs_modeset(crtc->state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12596 | continue; |
| 12597 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12598 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
| 12599 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12600 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12601 | pipe_config->base.crtc = crtc; |
| 12602 | pipe_config->base.state = old_state; |
| 12603 | |
| 12604 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 12605 | crtc->base.id); |
| 12606 | |
| 12607 | active = dev_priv->display.get_pipe_config(intel_crtc, |
| 12608 | pipe_config); |
| 12609 | |
| 12610 | /* hw state is inconsistent with the pipe quirk */ |
| 12611 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 12612 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 12613 | active = crtc->state->active; |
| 12614 | |
| 12615 | I915_STATE_WARN(crtc->state->active != active, |
| 12616 | "crtc active state doesn't match with hw state " |
| 12617 | "(expected %i, found %i)\n", crtc->state->active, active); |
| 12618 | |
| 12619 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
| 12620 | "transitional active state does not match atomic hw state " |
| 12621 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
| 12622 | |
| 12623 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12624 | enum pipe pipe; |
| 12625 | |
| 12626 | active = encoder->get_hw_state(encoder, &pipe); |
| 12627 | I915_STATE_WARN(active != crtc->state->active, |
| 12628 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12629 | encoder->base.base.id, active, crtc->state->active); |
| 12630 | |
| 12631 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12632 | "Encoder connected to wrong pipe %c\n", |
| 12633 | pipe_name(pipe)); |
| 12634 | |
| 12635 | if (active) |
| 12636 | encoder->get_config(encoder, pipe_config); |
| 12637 | } |
| 12638 | |
| 12639 | if (!crtc->state->active) |
| 12640 | continue; |
| 12641 | |
| 12642 | sw_config = to_intel_crtc_state(crtc->state); |
| 12643 | if (!intel_pipe_config_compare(dev, sw_config, |
| 12644 | pipe_config, false)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12645 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12646 | intel_dump_pipe_config(intel_crtc, pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12647 | "[hw state]"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12648 | intel_dump_pipe_config(intel_crtc, sw_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12649 | "[sw state]"); |
| 12650 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12651 | } |
| 12652 | } |
| 12653 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12654 | static void |
| 12655 | check_shared_dpll_state(struct drm_device *dev) |
| 12656 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12657 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12658 | struct intel_crtc *crtc; |
| 12659 | struct intel_dpll_hw_state dpll_hw_state; |
| 12660 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12661 | |
| 12662 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 12663 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 12664 | int enabled_crtcs = 0, active_crtcs = 0; |
| 12665 | bool active; |
| 12666 | |
| 12667 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12668 | |
| 12669 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 12670 | |
| 12671 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 12672 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12673 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12674 | "more active pll users than references: %i vs %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12675 | pll->active, hweight32(pll->config.crtc_mask)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12676 | I915_STATE_WARN(pll->active && !pll->on, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12677 | "pll in active use but not on in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12678 | I915_STATE_WARN(pll->on && !pll->active, |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 12679 | "pll in on but not on in use in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12680 | I915_STATE_WARN(pll->on != active, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12681 | "pll on state mismatch (expected %i, found %i)\n", |
| 12682 | pll->on, active); |
| 12683 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12684 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12685 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12686 | enabled_crtcs++; |
| 12687 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 12688 | active_crtcs++; |
| 12689 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12690 | I915_STATE_WARN(pll->active != active_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12691 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 12692 | pll->active, active_crtcs); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12693 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12694 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12695 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12696 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12697 | 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] | 12698 | sizeof(dpll_hw_state)), |
| 12699 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12700 | } |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 12701 | } |
| 12702 | |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 12703 | static void |
| 12704 | intel_modeset_check_state(struct drm_device *dev, |
| 12705 | struct drm_atomic_state *old_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12706 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12707 | check_wm_state(dev); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12708 | check_connector_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12709 | check_encoder_state(dev); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12710 | check_crtc_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12711 | check_shared_dpll_state(dev); |
| 12712 | } |
| 12713 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12714 | 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] | 12715 | int dotclock) |
| 12716 | { |
| 12717 | /* |
| 12718 | * FDI already provided one idea for the dotclock. |
| 12719 | * Yell if the encoder disagrees. |
| 12720 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12721 | 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] | 12722 | "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] | 12723 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 12724 | } |
| 12725 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12726 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 12727 | { |
| 12728 | struct drm_device *dev = crtc->base.dev; |
| 12729 | |
| 12730 | /* |
| 12731 | * The scanline counter increments at the leading edge of hsync. |
| 12732 | * |
| 12733 | * On most platforms it starts counting from vtotal-1 on the |
| 12734 | * first active line. That means the scanline counter value is |
| 12735 | * always one less than what we would expect. Ie. just after |
| 12736 | * start of vblank, which also occurs at start of hsync (on the |
| 12737 | * last active line), the scanline counter will read vblank_start-1. |
| 12738 | * |
| 12739 | * On gen2 the scanline counter starts counting from 1 instead |
| 12740 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12741 | * to keep the value positive), instead of adding one. |
| 12742 | * |
| 12743 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12744 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12745 | * there's an extra 1 line difference. So we need to add two instead of |
| 12746 | * one to the value. |
| 12747 | */ |
| 12748 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12749 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12750 | int vtotal; |
| 12751 | |
| 12752 | vtotal = mode->crtc_vtotal; |
| 12753 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 12754 | vtotal /= 2; |
| 12755 | |
| 12756 | crtc->scanline_offset = vtotal - 1; |
| 12757 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 12758 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12759 | crtc->scanline_offset = 2; |
| 12760 | } else |
| 12761 | crtc->scanline_offset = 1; |
| 12762 | } |
| 12763 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12764 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12765 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12766 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12767 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12768 | struct intel_shared_dpll_config *shared_dpll = NULL; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12769 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12770 | struct intel_crtc_state *intel_crtc_state; |
| 12771 | struct drm_crtc *crtc; |
| 12772 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12773 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12774 | |
| 12775 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12776 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12777 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12778 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12779 | int dpll; |
| 12780 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12781 | intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12782 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12783 | dpll = intel_crtc_state->shared_dpll; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12784 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12785 | if (!needs_modeset(crtc_state) || dpll == DPLL_ID_PRIVATE) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12786 | continue; |
| 12787 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12788 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12789 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12790 | if (!shared_dpll) |
| 12791 | shared_dpll = intel_atomic_get_shared_dpll_state(state); |
| 12792 | |
| 12793 | shared_dpll[dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12794 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12795 | } |
| 12796 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12797 | /* |
| 12798 | * This implements the workaround described in the "notes" section of the mode |
| 12799 | * set sequence documentation. When going from no pipes or single pipe to |
| 12800 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12801 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12802 | */ |
| 12803 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12804 | { |
| 12805 | struct drm_crtc_state *crtc_state; |
| 12806 | struct intel_crtc *intel_crtc; |
| 12807 | struct drm_crtc *crtc; |
| 12808 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12809 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12810 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12811 | int i; |
| 12812 | |
| 12813 | /* look at all crtc's that are going to be enabled in during modeset */ |
| 12814 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 12815 | intel_crtc = to_intel_crtc(crtc); |
| 12816 | |
| 12817 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12818 | continue; |
| 12819 | |
| 12820 | if (first_crtc_state) { |
| 12821 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12822 | break; |
| 12823 | } else { |
| 12824 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12825 | first_pipe = intel_crtc->pipe; |
| 12826 | } |
| 12827 | } |
| 12828 | |
| 12829 | /* No workaround needed? */ |
| 12830 | if (!first_crtc_state) |
| 12831 | return 0; |
| 12832 | |
| 12833 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12834 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12835 | struct intel_crtc_state *pipe_config; |
| 12836 | |
| 12837 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12838 | if (IS_ERR(pipe_config)) |
| 12839 | return PTR_ERR(pipe_config); |
| 12840 | |
| 12841 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12842 | |
| 12843 | if (!pipe_config->base.active || |
| 12844 | needs_modeset(&pipe_config->base)) |
| 12845 | continue; |
| 12846 | |
| 12847 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12848 | if (enabled_pipe != INVALID_PIPE) |
| 12849 | return 0; |
| 12850 | |
| 12851 | enabled_pipe = intel_crtc->pipe; |
| 12852 | } |
| 12853 | |
| 12854 | if (enabled_pipe != INVALID_PIPE) |
| 12855 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12856 | else if (other_crtc_state) |
| 12857 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12858 | |
| 12859 | return 0; |
| 12860 | } |
| 12861 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12862 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12863 | { |
| 12864 | struct drm_crtc *crtc; |
| 12865 | struct drm_crtc_state *crtc_state; |
| 12866 | int ret = 0; |
| 12867 | |
| 12868 | /* add all active pipes to the state */ |
| 12869 | for_each_crtc(state->dev, crtc) { |
| 12870 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12871 | if (IS_ERR(crtc_state)) |
| 12872 | return PTR_ERR(crtc_state); |
| 12873 | |
| 12874 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12875 | continue; |
| 12876 | |
| 12877 | crtc_state->mode_changed = true; |
| 12878 | |
| 12879 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12880 | if (ret) |
| 12881 | break; |
| 12882 | |
| 12883 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12884 | if (ret) |
| 12885 | break; |
| 12886 | } |
| 12887 | |
| 12888 | return ret; |
| 12889 | } |
| 12890 | |
| 12891 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12892 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12893 | { |
| 12894 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12895 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12896 | int ret; |
| 12897 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12898 | if (!check_digital_port_conflicts(state)) { |
| 12899 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12900 | return -EINVAL; |
| 12901 | } |
| 12902 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12903 | /* |
| 12904 | * See if the config requires any additional preparation, e.g. |
| 12905 | * to adjust global state with pipes off. We need to do this |
| 12906 | * here so we can get the modeset_pipe updated config for the new |
| 12907 | * mode set on this crtc. For other crtcs we need to use the |
| 12908 | * adjusted_mode bits in the crtc directly. |
| 12909 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12910 | if (dev_priv->display.modeset_calc_cdclk) { |
| 12911 | unsigned int cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 12912 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12913 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12914 | |
| 12915 | cdclk = to_intel_atomic_state(state)->cdclk; |
| 12916 | if (!ret && cdclk != dev_priv->cdclk_freq) |
| 12917 | ret = intel_modeset_all_pipes(state); |
| 12918 | |
| 12919 | if (ret < 0) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12920 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12921 | } else |
| 12922 | to_intel_atomic_state(state)->cdclk = dev_priv->cdclk_freq; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12923 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12924 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12925 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12926 | if (IS_HASWELL(dev)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12927 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12928 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12929 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12930 | } |
| 12931 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12932 | /** |
| 12933 | * intel_atomic_check - validate state object |
| 12934 | * @dev: drm device |
| 12935 | * @state: state to validate |
| 12936 | */ |
| 12937 | static int intel_atomic_check(struct drm_device *dev, |
| 12938 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12939 | { |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12940 | struct drm_crtc *crtc; |
| 12941 | struct drm_crtc_state *crtc_state; |
| 12942 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12943 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12944 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12945 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12946 | if (ret) |
| 12947 | return ret; |
| 12948 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12949 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12950 | struct intel_crtc_state *pipe_config = |
| 12951 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12952 | |
| 12953 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12954 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) |
| 12955 | crtc_state->mode_changed = true; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12956 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12957 | if (!crtc_state->enable) { |
| 12958 | if (needs_modeset(crtc_state)) |
| 12959 | any_ms = true; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12960 | continue; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12961 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12962 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12963 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12964 | continue; |
| 12965 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12966 | /* FIXME: For only active_changed we shouldn't need to do any |
| 12967 | * state recomputation at all. */ |
| 12968 | |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12969 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12970 | if (ret) |
| 12971 | return ret; |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12972 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12973 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12974 | if (ret) |
| 12975 | return ret; |
| 12976 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12977 | if (i915.fastboot && |
| 12978 | intel_pipe_config_compare(state->dev, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12979 | to_intel_crtc_state(crtc->state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12980 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12981 | crtc_state->mode_changed = false; |
| 12982 | } |
| 12983 | |
| 12984 | if (needs_modeset(crtc_state)) { |
| 12985 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12986 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12987 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12988 | if (ret) |
| 12989 | return ret; |
| 12990 | } |
| 12991 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12992 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12993 | needs_modeset(crtc_state) ? |
| 12994 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12995 | } |
| 12996 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12997 | if (any_ms) { |
| 12998 | ret = intel_modeset_checks(state); |
| 12999 | |
| 13000 | if (ret) |
| 13001 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13002 | } else |
| 13003 | to_intel_atomic_state(state)->cdclk = |
| 13004 | to_i915(state->dev)->cdclk_freq; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13005 | |
| 13006 | return drm_atomic_helper_check_planes(state->dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13007 | } |
| 13008 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13009 | /** |
| 13010 | * intel_atomic_commit - commit validated state object |
| 13011 | * @dev: DRM device |
| 13012 | * @state: the top-level driver state object |
| 13013 | * @async: asynchronous commit |
| 13014 | * |
| 13015 | * This function commits a top-level state object that has been validated |
| 13016 | * with drm_atomic_helper_check(). |
| 13017 | * |
| 13018 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment |
| 13019 | * we can only handle plane-related operations and do not yet support |
| 13020 | * asynchronous commit. |
| 13021 | * |
| 13022 | * RETURNS |
| 13023 | * Zero for success or -errno. |
| 13024 | */ |
| 13025 | static int intel_atomic_commit(struct drm_device *dev, |
| 13026 | struct drm_atomic_state *state, |
| 13027 | bool async) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13028 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13029 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13030 | struct drm_crtc *crtc; |
| 13031 | struct drm_crtc_state *crtc_state; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13032 | int ret = 0; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13033 | int i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13034 | bool any_ms = false; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13035 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13036 | if (async) { |
| 13037 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); |
| 13038 | return -EINVAL; |
| 13039 | } |
| 13040 | |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13041 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 13042 | if (ret) |
| 13043 | return ret; |
| 13044 | |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13045 | drm_atomic_helper_swap_state(dev, state); |
| 13046 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13047 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13048 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13049 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13050 | if (!needs_modeset(crtc->state)) |
| 13051 | continue; |
| 13052 | |
| 13053 | any_ms = true; |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13054 | intel_pre_plane_update(intel_crtc); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13055 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13056 | if (crtc_state->active) { |
| 13057 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); |
| 13058 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13059 | intel_crtc->active = false; |
| 13060 | intel_disable_shared_dpll(intel_crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13061 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13062 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13063 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13064 | /* Only after disabling all output pipelines that will be changed can we |
| 13065 | * update the the output configuration. */ |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13066 | intel_modeset_update_crtc_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13067 | |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13068 | if (any_ms) { |
| 13069 | intel_shared_dpll_commit(state); |
| 13070 | |
| 13071 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13072 | modeset_update_crtc_power_domains(state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13073 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13074 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13075 | /* 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] | 13076 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13077 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13078 | bool modeset = needs_modeset(crtc->state); |
| 13079 | |
| 13080 | if (modeset && crtc->state->active) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13081 | update_scanline_offset(to_intel_crtc(crtc)); |
| 13082 | dev_priv->display.crtc_enable(crtc); |
| 13083 | } |
| 13084 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13085 | if (!modeset) |
| 13086 | intel_pre_plane_update(intel_crtc); |
| 13087 | |
Maarten Lankhorst | 5ac1c4b | 2015-06-01 12:50:01 +0200 | [diff] [blame] | 13088 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13089 | intel_post_plane_update(intel_crtc); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13090 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13091 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13092 | /* FIXME: add subpixel order */ |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13093 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13094 | drm_atomic_helper_wait_for_vblanks(dev, state); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13095 | drm_atomic_helper_cleanup_planes(dev, state); |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13096 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13097 | if (any_ms) |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 13098 | intel_modeset_check_state(dev, state); |
| 13099 | |
| 13100 | drm_atomic_state_free(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 13101 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13102 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13103 | } |
| 13104 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13105 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 13106 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13107 | struct drm_device *dev = crtc->dev; |
| 13108 | struct drm_atomic_state *state; |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13109 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13110 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13111 | |
| 13112 | state = drm_atomic_state_alloc(dev); |
| 13113 | if (!state) { |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13114 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13115 | crtc->base.id); |
| 13116 | return; |
| 13117 | } |
| 13118 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13119 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13120 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13121 | retry: |
| 13122 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13123 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 13124 | if (!ret) { |
| 13125 | if (!crtc_state->active) |
| 13126 | goto out; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13127 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13128 | crtc_state->mode_changed = true; |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13129 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13130 | } |
| 13131 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13132 | if (ret == -EDEADLK) { |
| 13133 | drm_atomic_state_clear(state); |
| 13134 | drm_modeset_backoff(state->acquire_ctx); |
| 13135 | goto retry; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 13136 | } |
| 13137 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13138 | if (ret) |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13139 | out: |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13140 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13141 | } |
| 13142 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 13143 | #undef for_each_intel_crtc_masked |
| 13144 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13145 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13146 | .gamma_set = intel_crtc_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13147 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13148 | .destroy = intel_crtc_destroy, |
| 13149 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13150 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13151 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13152 | }; |
| 13153 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13154 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 13155 | struct intel_shared_dpll *pll, |
| 13156 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13157 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13158 | uint32_t val; |
| 13159 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 13160 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 13161 | return false; |
| 13162 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13163 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13164 | hw_state->dpll = val; |
| 13165 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 13166 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13167 | |
| 13168 | return val & DPLL_VCO_ENABLE; |
| 13169 | } |
| 13170 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13171 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 13172 | struct intel_shared_dpll *pll) |
| 13173 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13174 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
| 13175 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13176 | } |
| 13177 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13178 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 13179 | struct intel_shared_dpll *pll) |
| 13180 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13181 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 13182 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13183 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13184 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13185 | |
| 13186 | /* Wait for the clocks to stabilize. */ |
| 13187 | POSTING_READ(PCH_DPLL(pll->id)); |
| 13188 | udelay(150); |
| 13189 | |
| 13190 | /* The pixel multiplier can only be updated once the |
| 13191 | * DPLL is enabled and the clocks are stable. |
| 13192 | * |
| 13193 | * So write it again. |
| 13194 | */ |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13195 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13196 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13197 | udelay(200); |
| 13198 | } |
| 13199 | |
| 13200 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 13201 | struct intel_shared_dpll *pll) |
| 13202 | { |
| 13203 | struct drm_device *dev = dev_priv->dev; |
| 13204 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13205 | |
| 13206 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13207 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13208 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 13209 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 13210 | } |
| 13211 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13212 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 13213 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13214 | udelay(200); |
| 13215 | } |
| 13216 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 13217 | static char *ibx_pch_dpll_names[] = { |
| 13218 | "PCH DPLL A", |
| 13219 | "PCH DPLL B", |
| 13220 | }; |
| 13221 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13222 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13223 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13224 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13225 | int i; |
| 13226 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13227 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13228 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 13229 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 13230 | dev_priv->shared_dplls[i].id = i; |
| 13231 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 13232 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13233 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 13234 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13235 | dev_priv->shared_dplls[i].get_hw_state = |
| 13236 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13237 | } |
| 13238 | } |
| 13239 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13240 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 13241 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 13242 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13243 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 13244 | intel_update_cdclk(dev); |
| 13245 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 13246 | if (HAS_DDI(dev)) |
| 13247 | intel_ddi_pll_init(dev); |
| 13248 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13249 | ibx_pch_dpll_init(dev); |
| 13250 | else |
| 13251 | dev_priv->num_shared_dpll = 0; |
| 13252 | |
| 13253 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 13254 | } |
| 13255 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13256 | /** |
| 13257 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13258 | * @plane: drm plane to prepare for |
| 13259 | * @fb: framebuffer to prepare for presentation |
| 13260 | * |
| 13261 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13262 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13263 | * bits. Some older platforms need special physical address handling for |
| 13264 | * cursor planes. |
| 13265 | * |
| 13266 | * Returns 0 on success, negative error code on failure. |
| 13267 | */ |
| 13268 | int |
| 13269 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13270 | struct drm_framebuffer *fb, |
| 13271 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13272 | { |
| 13273 | struct drm_device *dev = plane->dev; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13274 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13275 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13276 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13277 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13278 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13279 | if (!obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13280 | return 0; |
| 13281 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 13282 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13283 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13284 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
| 13285 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 13286 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 13287 | ret = i915_gem_object_attach_phys(obj, align); |
| 13288 | if (ret) |
| 13289 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 13290 | } else { |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 13291 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL, NULL); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13292 | } |
| 13293 | |
| 13294 | if (ret == 0) |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13295 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13296 | |
| 13297 | mutex_unlock(&dev->struct_mutex); |
| 13298 | |
| 13299 | return ret; |
| 13300 | } |
| 13301 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13302 | /** |
| 13303 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13304 | * @plane: drm plane to clean up for |
| 13305 | * @fb: old framebuffer that was on plane |
| 13306 | * |
| 13307 | * Cleans up a framebuffer that has just been removed from a plane. |
| 13308 | */ |
| 13309 | void |
| 13310 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13311 | struct drm_framebuffer *fb, |
| 13312 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13313 | { |
| 13314 | struct drm_device *dev = plane->dev; |
| 13315 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13316 | |
| 13317 | if (WARN_ON(!obj)) |
| 13318 | return; |
| 13319 | |
| 13320 | if (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 13321 | !INTEL_INFO(dev)->cursor_needs_physical) { |
| 13322 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 13323 | intel_unpin_fb_obj(fb, old_state); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13324 | mutex_unlock(&dev->struct_mutex); |
| 13325 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13326 | } |
| 13327 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13328 | int |
| 13329 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 13330 | { |
| 13331 | int max_scale; |
| 13332 | struct drm_device *dev; |
| 13333 | struct drm_i915_private *dev_priv; |
| 13334 | int crtc_clock, cdclk; |
| 13335 | |
| 13336 | if (!intel_crtc || !crtc_state) |
| 13337 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13338 | |
| 13339 | dev = intel_crtc->base.dev; |
| 13340 | dev_priv = dev->dev_private; |
| 13341 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13342 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13343 | |
| 13344 | if (!crtc_clock || !cdclk) |
| 13345 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13346 | |
| 13347 | /* |
| 13348 | * skl max scale is lower of: |
| 13349 | * close to 3 but not 3, -1 is for that purpose |
| 13350 | * or |
| 13351 | * cdclk/crtc_clock |
| 13352 | */ |
| 13353 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 13354 | |
| 13355 | return max_scale; |
| 13356 | } |
| 13357 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13358 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13359 | intel_check_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13360 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13361 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13362 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13363 | struct drm_crtc *crtc = state->base.crtc; |
| 13364 | struct drm_framebuffer *fb = state->base.fb; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13365 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13366 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 13367 | bool can_position = false; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13368 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13369 | /* use scaler when colorkey is not required */ |
| 13370 | if (INTEL_INFO(plane->dev)->gen >= 9 && |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 13371 | state->ckey.flags == I915_SET_COLORKEY_NONE) { |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13372 | min_scale = 1; |
| 13373 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13374 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13375 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13376 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13377 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 13378 | &state->dst, &state->clip, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13379 | min_scale, max_scale, |
| 13380 | can_position, true, |
| 13381 | &state->visible); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13382 | } |
| 13383 | |
Gustavo Padovan | 14af293 | 2014-10-24 14:51:31 +0100 | [diff] [blame] | 13384 | static void |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13385 | intel_commit_primary_plane(struct drm_plane *plane, |
| 13386 | struct intel_plane_state *state) |
| 13387 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13388 | struct drm_crtc *crtc = state->base.crtc; |
| 13389 | struct drm_framebuffer *fb = state->base.fb; |
| 13390 | struct drm_device *dev = plane->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13391 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13392 | struct intel_crtc *intel_crtc; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13393 | struct drm_rect *src = &state->src; |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13394 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13395 | crtc = crtc ? crtc : plane->crtc; |
| 13396 | intel_crtc = to_intel_crtc(crtc); |
| 13397 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13398 | plane->fb = fb; |
Matt Roper | 9dc806f | 2014-11-17 18:10:38 -0800 | [diff] [blame] | 13399 | crtc->x = src->x1 >> 16; |
| 13400 | crtc->y = src->y1 >> 16; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13401 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13402 | if (!crtc->state->active) |
Maarten Lankhorst | 302d19a | 2015-06-15 12:33:45 +0200 | [diff] [blame] | 13403 | return; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13404 | |
Maarten Lankhorst | 302d19a | 2015-06-15 12:33:45 +0200 | [diff] [blame] | 13405 | if (state->visible) |
| 13406 | /* FIXME: kill this fastboot hack */ |
| 13407 | intel_update_pipe_size(intel_crtc); |
| 13408 | |
| 13409 | dev_priv->display.update_primary_plane(crtc, fb, crtc->x, crtc->y); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13410 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13411 | |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13412 | static void |
| 13413 | intel_disable_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 13414 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13415 | { |
| 13416 | struct drm_device *dev = plane->dev; |
| 13417 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13418 | |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13419 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
| 13420 | } |
| 13421 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13422 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13423 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13424 | { |
| 13425 | struct drm_device *dev = crtc->dev; |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13426 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13427 | |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 13428 | if (intel_crtc->atomic.update_wm_pre) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13429 | intel_update_watermarks(crtc); |
| 13430 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 13431 | /* Perform vblank evasion around commit operation */ |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13432 | if (crtc->state->active) |
Maarten Lankhorst | 8f539a8 | 2015-07-13 16:30:32 +0200 | [diff] [blame] | 13433 | intel_pipe_update_start(intel_crtc, &intel_crtc->start_vbl_count); |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 13434 | |
| 13435 | if (!needs_modeset(crtc->state) && INTEL_INFO(dev)->gen >= 9) |
| 13436 | skl_detach_scalers(intel_crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13437 | } |
| 13438 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13439 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13440 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13441 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13442 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13443 | |
Maarten Lankhorst | 8f539a8 | 2015-07-13 16:30:32 +0200 | [diff] [blame] | 13444 | if (crtc->state->active) |
| 13445 | intel_pipe_update_end(intel_crtc, intel_crtc->start_vbl_count); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13446 | } |
| 13447 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13448 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13449 | * intel_plane_destroy - destroy a plane |
| 13450 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13451 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13452 | * Common destruction function for all types of planes (primary, cursor, |
| 13453 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13454 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13455 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13456 | { |
| 13457 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13458 | drm_plane_cleanup(plane); |
| 13459 | kfree(intel_plane); |
| 13460 | } |
| 13461 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13462 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 13463 | .update_plane = drm_atomic_helper_update_plane, |
| 13464 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13465 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 13466 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 13467 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13468 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13469 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13470 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13471 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13472 | }; |
| 13473 | |
| 13474 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 13475 | int pipe) |
| 13476 | { |
| 13477 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13478 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13479 | const uint32_t *intel_primary_formats; |
| 13480 | int num_formats; |
| 13481 | |
| 13482 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 13483 | if (primary == NULL) |
| 13484 | return NULL; |
| 13485 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13486 | state = intel_create_plane_state(&primary->base); |
| 13487 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13488 | kfree(primary); |
| 13489 | return NULL; |
| 13490 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13491 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13492 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13493 | primary->can_scale = false; |
| 13494 | primary->max_downscale = 1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13495 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13496 | primary->can_scale = true; |
Chandra Konduru | af99ceda | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13497 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13498 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13499 | primary->pipe = pipe; |
| 13500 | primary->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13501 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13502 | primary->check_plane = intel_check_primary_plane; |
| 13503 | primary->commit_plane = intel_commit_primary_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13504 | primary->disable_plane = intel_disable_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13505 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 13506 | primary->plane = !pipe; |
| 13507 | |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13508 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13509 | intel_primary_formats = skl_primary_formats; |
| 13510 | num_formats = ARRAY_SIZE(skl_primary_formats); |
| 13511 | } else if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13512 | intel_primary_formats = i965_primary_formats; |
| 13513 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13514 | } else { |
| 13515 | intel_primary_formats = i8xx_primary_formats; |
| 13516 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13517 | } |
| 13518 | |
| 13519 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13520 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13521 | intel_primary_formats, num_formats, |
| 13522 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13523 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13524 | if (INTEL_INFO(dev)->gen >= 4) |
| 13525 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13526 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13527 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 13528 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13529 | return &primary->base; |
| 13530 | } |
| 13531 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13532 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 13533 | { |
| 13534 | if (!dev->mode_config.rotation_property) { |
| 13535 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 13536 | BIT(DRM_ROTATE_180); |
| 13537 | |
| 13538 | if (INTEL_INFO(dev)->gen >= 9) |
| 13539 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 13540 | |
| 13541 | dev->mode_config.rotation_property = |
| 13542 | drm_mode_create_rotation_property(dev, flags); |
| 13543 | } |
| 13544 | if (dev->mode_config.rotation_property) |
| 13545 | drm_object_attach_property(&plane->base.base, |
| 13546 | dev->mode_config.rotation_property, |
| 13547 | plane->base.state->rotation); |
| 13548 | } |
| 13549 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13550 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13551 | intel_check_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13552 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13553 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13554 | { |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13555 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13556 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13557 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13558 | unsigned stride; |
| 13559 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13560 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13561 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 13562 | &state->dst, &state->clip, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13563 | DRM_PLANE_HELPER_NO_SCALING, |
| 13564 | DRM_PLANE_HELPER_NO_SCALING, |
| 13565 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13566 | if (ret) |
| 13567 | return ret; |
| 13568 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13569 | /* if we want to turn off the cursor ignore width and height */ |
| 13570 | if (!obj) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13571 | return 0; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13572 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13573 | /* Check for which cursor types we support */ |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13574 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13575 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 13576 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13577 | return -EINVAL; |
| 13578 | } |
| 13579 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13580 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 13581 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13582 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 13583 | return -ENOMEM; |
| 13584 | } |
| 13585 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 13586 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13587 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13588 | return -EINVAL; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13589 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13590 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13591 | return 0; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13592 | } |
| 13593 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13594 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13595 | intel_disable_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 13596 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13597 | { |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13598 | intel_crtc_update_cursor(crtc, false); |
| 13599 | } |
| 13600 | |
| 13601 | static void |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13602 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 13603 | struct intel_plane_state *state) |
| 13604 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13605 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13606 | struct drm_device *dev = plane->dev; |
| 13607 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13608 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13609 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13610 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13611 | crtc = crtc ? crtc : plane->crtc; |
| 13612 | intel_crtc = to_intel_crtc(crtc); |
Sonika Jindal | a919db9 | 2014-10-23 07:41:33 -0700 | [diff] [blame] | 13613 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13614 | plane->fb = state->base.fb; |
| 13615 | crtc->cursor_x = state->base.crtc_x; |
| 13616 | crtc->cursor_y = state->base.crtc_y; |
| 13617 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13618 | if (intel_crtc->cursor_bo == obj) |
| 13619 | goto update; |
| 13620 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13621 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13622 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13623 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13624 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13625 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13626 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13627 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13628 | intel_crtc->cursor_addr = addr; |
| 13629 | intel_crtc->cursor_bo = obj; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13630 | |
Maarten Lankhorst | 302d19a | 2015-06-15 12:33:45 +0200 | [diff] [blame] | 13631 | update: |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13632 | if (crtc->state->active) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13633 | intel_crtc_update_cursor(crtc, state->visible); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13634 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13635 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13636 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 13637 | int pipe) |
| 13638 | { |
| 13639 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13640 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13641 | |
| 13642 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 13643 | if (cursor == NULL) |
| 13644 | return NULL; |
| 13645 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13646 | state = intel_create_plane_state(&cursor->base); |
| 13647 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13648 | kfree(cursor); |
| 13649 | return NULL; |
| 13650 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13651 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13652 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13653 | cursor->can_scale = false; |
| 13654 | cursor->max_downscale = 1; |
| 13655 | cursor->pipe = pipe; |
| 13656 | cursor->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13657 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13658 | cursor->check_plane = intel_check_cursor_plane; |
| 13659 | cursor->commit_plane = intel_commit_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 13660 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13661 | |
| 13662 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13663 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13664 | intel_cursor_formats, |
| 13665 | ARRAY_SIZE(intel_cursor_formats), |
| 13666 | DRM_PLANE_TYPE_CURSOR); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13667 | |
| 13668 | if (INTEL_INFO(dev)->gen >= 4) { |
| 13669 | if (!dev->mode_config.rotation_property) |
| 13670 | dev->mode_config.rotation_property = |
| 13671 | drm_mode_create_rotation_property(dev, |
| 13672 | BIT(DRM_ROTATE_0) | |
| 13673 | BIT(DRM_ROTATE_180)); |
| 13674 | if (dev->mode_config.rotation_property) |
| 13675 | drm_object_attach_property(&cursor->base.base, |
| 13676 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13677 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13678 | } |
| 13679 | |
Chandra Konduru | af99ceda | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13680 | if (INTEL_INFO(dev)->gen >=9) |
| 13681 | state->scaler_id = -1; |
| 13682 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13683 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13684 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13685 | return &cursor->base; |
| 13686 | } |
| 13687 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13688 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 13689 | struct intel_crtc_state *crtc_state) |
| 13690 | { |
| 13691 | int i; |
| 13692 | struct intel_scaler *intel_scaler; |
| 13693 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 13694 | |
| 13695 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 13696 | intel_scaler = &scaler_state->scalers[i]; |
| 13697 | intel_scaler->in_use = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13698 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 13699 | } |
| 13700 | |
| 13701 | scaler_state->scaler_id = -1; |
| 13702 | } |
| 13703 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 13704 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13705 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13706 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13707 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13708 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13709 | struct drm_plane *primary = NULL; |
| 13710 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13711 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13712 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13713 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13714 | if (intel_crtc == NULL) |
| 13715 | return; |
| 13716 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13717 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 13718 | if (!crtc_state) |
| 13719 | goto fail; |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 13720 | intel_crtc->config = crtc_state; |
| 13721 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13722 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13723 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13724 | /* initialize shared scalers */ |
| 13725 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13726 | if (pipe == PIPE_C) |
| 13727 | intel_crtc->num_scalers = 1; |
| 13728 | else |
| 13729 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 13730 | |
| 13731 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 13732 | } |
| 13733 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13734 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13735 | if (!primary) |
| 13736 | goto fail; |
| 13737 | |
| 13738 | cursor = intel_cursor_plane_create(dev, pipe); |
| 13739 | if (!cursor) |
| 13740 | goto fail; |
| 13741 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13742 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13743 | cursor, &intel_crtc_funcs); |
| 13744 | if (ret) |
| 13745 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13746 | |
| 13747 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13748 | for (i = 0; i < 256; i++) { |
| 13749 | intel_crtc->lut_r[i] = i; |
| 13750 | intel_crtc->lut_g[i] = i; |
| 13751 | intel_crtc->lut_b[i] = i; |
| 13752 | } |
| 13753 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 13754 | /* |
| 13755 | * 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] | 13756 | * 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] | 13757 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13758 | intel_crtc->pipe = pipe; |
| 13759 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 13760 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 13761 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 13762 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13763 | } |
| 13764 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 13765 | intel_crtc->cursor_base = ~0; |
| 13766 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 13767 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 13768 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 13769 | intel_crtc->wm.cxsr_allowed = true; |
| 13770 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13771 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13772 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 13773 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 13774 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 13775 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13776 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13777 | |
| 13778 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13779 | return; |
| 13780 | |
| 13781 | fail: |
| 13782 | if (primary) |
| 13783 | drm_plane_cleanup(primary); |
| 13784 | if (cursor) |
| 13785 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13786 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13787 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13788 | } |
| 13789 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13790 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 13791 | { |
| 13792 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13793 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13794 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 13795 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13796 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 13797 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13798 | return INVALID_PIPE; |
| 13799 | |
| 13800 | return to_intel_crtc(encoder->crtc)->pipe; |
| 13801 | } |
| 13802 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13803 | 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] | 13804 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13805 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13806 | 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] | 13807 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13808 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13809 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13810 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13811 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13812 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13813 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 13814 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13815 | } |
| 13816 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13817 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13818 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13819 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13820 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13821 | } |
| 13822 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13823 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13824 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13825 | struct drm_device *dev = encoder->base.dev; |
| 13826 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13827 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13828 | int entry = 0; |
| 13829 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13830 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 13831 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13832 | index_mask |= (1 << entry); |
| 13833 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13834 | entry++; |
| 13835 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13836 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13837 | return index_mask; |
| 13838 | } |
| 13839 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13840 | static bool has_edp_a(struct drm_device *dev) |
| 13841 | { |
| 13842 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13843 | |
| 13844 | if (!IS_MOBILE(dev)) |
| 13845 | return false; |
| 13846 | |
| 13847 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 13848 | return false; |
| 13849 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 13850 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13851 | return false; |
| 13852 | |
| 13853 | return true; |
| 13854 | } |
| 13855 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13856 | static bool intel_crt_present(struct drm_device *dev) |
| 13857 | { |
| 13858 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13859 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 13860 | if (INTEL_INFO(dev)->gen >= 9) |
| 13861 | return false; |
| 13862 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 13863 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13864 | return false; |
| 13865 | |
| 13866 | if (IS_CHERRYVIEW(dev)) |
| 13867 | return false; |
| 13868 | |
| 13869 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 13870 | return false; |
| 13871 | |
| 13872 | return true; |
| 13873 | } |
| 13874 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13875 | static void intel_setup_outputs(struct drm_device *dev) |
| 13876 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13877 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13878 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13879 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13880 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 13881 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13882 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13883 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 13884 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13885 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 13886 | if (IS_BROXTON(dev)) { |
| 13887 | /* |
| 13888 | * FIXME: Broxton doesn't support port detection via the |
| 13889 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 13890 | * detect the ports. |
| 13891 | */ |
| 13892 | intel_ddi_init(dev, PORT_A); |
| 13893 | intel_ddi_init(dev, PORT_B); |
| 13894 | intel_ddi_init(dev, PORT_C); |
| 13895 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13896 | int found; |
| 13897 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13898 | /* |
| 13899 | * Haswell uses DDI functions to detect digital outputs. |
| 13900 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 13901 | * it's there. |
| 13902 | */ |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13903 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13904 | /* WaIgnoreDDIAStrap: skl */ |
Jani Nikula | 5a2376d | 2015-08-14 10:53:17 +0300 | [diff] [blame] | 13905 | if (found || IS_SKYLAKE(dev)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13906 | intel_ddi_init(dev, PORT_A); |
| 13907 | |
| 13908 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 13909 | * register */ |
| 13910 | found = I915_READ(SFUSE_STRAP); |
| 13911 | |
| 13912 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 13913 | intel_ddi_init(dev, PORT_B); |
| 13914 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 13915 | intel_ddi_init(dev, PORT_C); |
| 13916 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 13917 | intel_ddi_init(dev, PORT_D); |
| 13918 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13919 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 13920 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13921 | |
| 13922 | if (has_edp_a(dev)) |
| 13923 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13924 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13925 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 13926 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 13927 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13928 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13929 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13930 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13931 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13932 | } |
| 13933 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13934 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13935 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13936 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13937 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13938 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13939 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13940 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13941 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13942 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13943 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13944 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 13945 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13946 | /* |
| 13947 | * The DP_DETECTED bit is the latched state of the DDC |
| 13948 | * SDA pin at boot. However since eDP doesn't require DDC |
| 13949 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 13950 | * eDP ports may have been muxed to an alternate function. |
| 13951 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 13952 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 13953 | * detect eDP ports. |
| 13954 | */ |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13955 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
| 13956 | !intel_dp_is_edp(dev, PORT_B)) |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13957 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 13958 | PORT_B); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13959 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
| 13960 | intel_dp_is_edp(dev, PORT_B)) |
| 13961 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13962 | |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13963 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
| 13964 | !intel_dp_is_edp(dev, PORT_C)) |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 13965 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 13966 | PORT_C); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13967 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
| 13968 | intel_dp_is_edp(dev, PORT_C)) |
| 13969 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 13970 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13971 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13972 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13973 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 13974 | PORT_D); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13975 | /* eDP not supported on port D, so don't check VBT */ |
| 13976 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 13977 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13978 | } |
| 13979 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 13980 | intel_dsi_init(dev); |
Daniel Vetter | 09da55d | 2015-07-07 11:44:32 +0200 | [diff] [blame] | 13981 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13982 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 13983 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13984 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13985 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13986 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 13987 | if (!found && IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13988 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13989 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13990 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13991 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 13992 | if (!found && IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13993 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13994 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13995 | |
| 13996 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13997 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13998 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13999 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14000 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14001 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14002 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14003 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14004 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14005 | if (IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14006 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14007 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14008 | } |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14009 | if (IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14010 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14011 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14012 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14013 | if (IS_G4X(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 14014 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14015 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 14016 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14017 | intel_dvo_init(dev); |
| 14018 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 14019 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14020 | intel_tv_init(dev); |
| 14021 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 14022 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14023 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14024 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14025 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14026 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14027 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14028 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14029 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 14030 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14031 | |
| 14032 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14033 | } |
| 14034 | |
| 14035 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14036 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14037 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14038 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14039 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14040 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14041 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14042 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14043 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 14044 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14045 | kfree(intel_fb); |
| 14046 | } |
| 14047 | |
| 14048 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14049 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14050 | unsigned int *handle) |
| 14051 | { |
| 14052 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14053 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14054 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14055 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14056 | } |
| 14057 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14058 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14059 | struct drm_file *file, |
| 14060 | unsigned flags, unsigned color, |
| 14061 | struct drm_clip_rect *clips, |
| 14062 | unsigned num_clips) |
| 14063 | { |
| 14064 | struct drm_device *dev = fb->dev; |
| 14065 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 14066 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 14067 | |
| 14068 | mutex_lock(&dev->struct_mutex); |
Paulo Zanoni | 74b4ea1 | 2015-07-14 16:29:14 -0300 | [diff] [blame] | 14069 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14070 | mutex_unlock(&dev->struct_mutex); |
| 14071 | |
| 14072 | return 0; |
| 14073 | } |
| 14074 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14075 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14076 | .destroy = intel_user_framebuffer_destroy, |
| 14077 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14078 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14079 | }; |
| 14080 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14081 | static |
| 14082 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 14083 | uint32_t pixel_format) |
| 14084 | { |
| 14085 | u32 gen = INTEL_INFO(dev)->gen; |
| 14086 | |
| 14087 | if (gen >= 9) { |
| 14088 | /* "The stride in bytes must not exceed the of the size of 8K |
| 14089 | * pixels and 32K bytes." |
| 14090 | */ |
| 14091 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); |
| 14092 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 14093 | return 32*1024; |
| 14094 | } else if (gen >= 4) { |
| 14095 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14096 | return 16*1024; |
| 14097 | else |
| 14098 | return 32*1024; |
| 14099 | } else if (gen >= 3) { |
| 14100 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14101 | return 8*1024; |
| 14102 | else |
| 14103 | return 16*1024; |
| 14104 | } else { |
| 14105 | /* XXX DSPC is limited to 4k tiled */ |
| 14106 | return 8*1024; |
| 14107 | } |
| 14108 | } |
| 14109 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 14110 | static int intel_framebuffer_init(struct drm_device *dev, |
| 14111 | struct intel_framebuffer *intel_fb, |
| 14112 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 14113 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14114 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 14115 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14116 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14117 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14118 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14119 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 14120 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14121 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 14122 | /* Enforce that fb modifier and tiling mode match, but only for |
| 14123 | * X-tiled. This is needed for FBC. */ |
| 14124 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 14125 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 14126 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 14127 | return -EINVAL; |
| 14128 | } |
| 14129 | } else { |
| 14130 | if (obj->tiling_mode == I915_TILING_X) |
| 14131 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 14132 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 14133 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 14134 | return -EINVAL; |
| 14135 | } |
| 14136 | } |
| 14137 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14138 | /* Passed in modifier sanity checking. */ |
| 14139 | switch (mode_cmd->modifier[0]) { |
| 14140 | case I915_FORMAT_MOD_Y_TILED: |
| 14141 | case I915_FORMAT_MOD_Yf_TILED: |
| 14142 | if (INTEL_INFO(dev)->gen < 9) { |
| 14143 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 14144 | mode_cmd->modifier[0]); |
| 14145 | return -EINVAL; |
| 14146 | } |
| 14147 | case DRM_FORMAT_MOD_NONE: |
| 14148 | case I915_FORMAT_MOD_X_TILED: |
| 14149 | break; |
| 14150 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 14151 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 14152 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14153 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14154 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14155 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14156 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
| 14157 | mode_cmd->pixel_format); |
| 14158 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 14159 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 14160 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14161 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14162 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14163 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14164 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 14165 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14166 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14167 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 14168 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14169 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14170 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14171 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14172 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14173 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14174 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14175 | mode_cmd->pitches[0] != obj->stride) { |
| 14176 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 14177 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14178 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14179 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14180 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14181 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14182 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14183 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14184 | case DRM_FORMAT_RGB565: |
| 14185 | case DRM_FORMAT_XRGB8888: |
| 14186 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14187 | break; |
| 14188 | case DRM_FORMAT_XRGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14189 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14190 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14191 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14192 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14193 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14194 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14195 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14196 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
| 14197 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14198 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14199 | return -EINVAL; |
| 14200 | } |
| 14201 | break; |
| 14202 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14203 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14204 | case DRM_FORMAT_XBGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14205 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14206 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14207 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14208 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14209 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14210 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14211 | case DRM_FORMAT_ABGR2101010: |
| 14212 | if (!IS_VALLEYVIEW(dev)) { |
| 14213 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14214 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14215 | return -EINVAL; |
| 14216 | } |
| 14217 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14218 | case DRM_FORMAT_YUYV: |
| 14219 | case DRM_FORMAT_UYVY: |
| 14220 | case DRM_FORMAT_YVYU: |
| 14221 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14222 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14223 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14224 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14225 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14226 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14227 | break; |
| 14228 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14229 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14230 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14231 | return -EINVAL; |
| 14232 | } |
| 14233 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14234 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14235 | if (mode_cmd->offsets[0] != 0) |
| 14236 | return -EINVAL; |
| 14237 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 14238 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 14239 | mode_cmd->pixel_format, |
| 14240 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 14241 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 14242 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 14243 | return -EINVAL; |
| 14244 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14245 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 14246 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 14247 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14248 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14249 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 14250 | if (ret) { |
| 14251 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 14252 | return ret; |
| 14253 | } |
| 14254 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14255 | return 0; |
| 14256 | } |
| 14257 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14258 | static struct drm_framebuffer * |
| 14259 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14260 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14261 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14262 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14263 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14264 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14265 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 14266 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 14267 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14268 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14269 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 14270 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14271 | } |
| 14272 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14273 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14274 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14275 | { |
| 14276 | } |
| 14277 | #endif |
| 14278 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14279 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14280 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14281 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14282 | .atomic_check = intel_atomic_check, |
| 14283 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14284 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14285 | .atomic_state_clear = intel_atomic_state_clear, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14286 | }; |
| 14287 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14288 | /* Set up chip specific display functions */ |
| 14289 | static void intel_init_display(struct drm_device *dev) |
| 14290 | { |
| 14291 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14292 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14293 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 14294 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 14295 | else if (IS_CHERRYVIEW(dev)) |
| 14296 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14297 | else if (IS_VALLEYVIEW(dev)) |
| 14298 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 14299 | else if (IS_PINEVIEW(dev)) |
| 14300 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 14301 | else |
| 14302 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 14303 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14304 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14305 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14306 | dev_priv->display.get_initial_plane_config = |
| 14307 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14308 | dev_priv->display.crtc_compute_clock = |
| 14309 | haswell_crtc_compute_clock; |
| 14310 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14311 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14312 | dev_priv->display.update_primary_plane = |
| 14313 | skylake_update_primary_plane; |
| 14314 | } else if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14315 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14316 | dev_priv->display.get_initial_plane_config = |
| 14317 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14318 | dev_priv->display.crtc_compute_clock = |
| 14319 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14320 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14321 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14322 | dev_priv->display.update_primary_plane = |
| 14323 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 14324 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14325 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14326 | dev_priv->display.get_initial_plane_config = |
| 14327 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14328 | dev_priv->display.crtc_compute_clock = |
| 14329 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14330 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14331 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14332 | dev_priv->display.update_primary_plane = |
| 14333 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14334 | } else if (IS_VALLEYVIEW(dev)) { |
| 14335 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14336 | dev_priv->display.get_initial_plane_config = |
| 14337 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14338 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14339 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14340 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14341 | dev_priv->display.update_primary_plane = |
| 14342 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14343 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14344 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14345 | dev_priv->display.get_initial_plane_config = |
| 14346 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14347 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14348 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14349 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 14350 | dev_priv->display.update_primary_plane = |
| 14351 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14352 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14353 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14354 | /* Returns the core display clock speed */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14355 | if (IS_SKYLAKE(dev)) |
| 14356 | dev_priv->display.get_display_clock_speed = |
| 14357 | skylake_get_display_clock_speed; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 14358 | else if (IS_BROXTON(dev)) |
| 14359 | dev_priv->display.get_display_clock_speed = |
| 14360 | broxton_get_display_clock_speed; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14361 | else if (IS_BROADWELL(dev)) |
| 14362 | dev_priv->display.get_display_clock_speed = |
| 14363 | broadwell_get_display_clock_speed; |
| 14364 | else if (IS_HASWELL(dev)) |
| 14365 | dev_priv->display.get_display_clock_speed = |
| 14366 | haswell_get_display_clock_speed; |
| 14367 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 14368 | dev_priv->display.get_display_clock_speed = |
| 14369 | valleyview_get_display_clock_speed; |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 14370 | else if (IS_GEN5(dev)) |
| 14371 | dev_priv->display.get_display_clock_speed = |
| 14372 | ilk_get_display_clock_speed; |
Ville Syrjälä | a7c66cd | 2015-03-31 14:11:56 +0300 | [diff] [blame] | 14373 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14374 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14375 | dev_priv->display.get_display_clock_speed = |
| 14376 | i945_get_display_clock_speed; |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14377 | else if (IS_GM45(dev)) |
| 14378 | dev_priv->display.get_display_clock_speed = |
| 14379 | gm45_get_display_clock_speed; |
| 14380 | else if (IS_CRESTLINE(dev)) |
| 14381 | dev_priv->display.get_display_clock_speed = |
| 14382 | i965gm_get_display_clock_speed; |
| 14383 | else if (IS_PINEVIEW(dev)) |
| 14384 | dev_priv->display.get_display_clock_speed = |
| 14385 | pnv_get_display_clock_speed; |
| 14386 | else if (IS_G33(dev) || IS_G4X(dev)) |
| 14387 | dev_priv->display.get_display_clock_speed = |
| 14388 | g33_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14389 | else if (IS_I915G(dev)) |
| 14390 | dev_priv->display.get_display_clock_speed = |
| 14391 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 14392 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14393 | dev_priv->display.get_display_clock_speed = |
| 14394 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 14395 | else if (IS_PINEVIEW(dev)) |
| 14396 | dev_priv->display.get_display_clock_speed = |
| 14397 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14398 | else if (IS_I915GM(dev)) |
| 14399 | dev_priv->display.get_display_clock_speed = |
| 14400 | i915gm_get_display_clock_speed; |
| 14401 | else if (IS_I865G(dev)) |
| 14402 | dev_priv->display.get_display_clock_speed = |
| 14403 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 14404 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14405 | dev_priv->display.get_display_clock_speed = |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 14406 | i85x_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14407 | else { /* 830 */ |
| 14408 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14409 | dev_priv->display.get_display_clock_speed = |
| 14410 | i830_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14411 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14412 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 14413 | if (IS_GEN5(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14414 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14415 | } else if (IS_GEN6(dev)) { |
| 14416 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14417 | } else if (IS_IVYBRIDGE(dev)) { |
| 14418 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14419 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 14420 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14421 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14422 | if (IS_BROADWELL(dev)) { |
| 14423 | dev_priv->display.modeset_commit_cdclk = |
| 14424 | broadwell_modeset_commit_cdclk; |
| 14425 | dev_priv->display.modeset_calc_cdclk = |
| 14426 | broadwell_modeset_calc_cdclk; |
| 14427 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 14428 | } else if (IS_VALLEYVIEW(dev)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14429 | dev_priv->display.modeset_commit_cdclk = |
| 14430 | valleyview_modeset_commit_cdclk; |
| 14431 | dev_priv->display.modeset_calc_cdclk = |
| 14432 | valleyview_modeset_calc_cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 14433 | } else if (IS_BROXTON(dev)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14434 | dev_priv->display.modeset_commit_cdclk = |
| 14435 | broxton_modeset_commit_cdclk; |
| 14436 | dev_priv->display.modeset_calc_cdclk = |
| 14437 | broxton_modeset_calc_cdclk; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14438 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14439 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14440 | switch (INTEL_INFO(dev)->gen) { |
| 14441 | case 2: |
| 14442 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 14443 | break; |
| 14444 | |
| 14445 | case 3: |
| 14446 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 14447 | break; |
| 14448 | |
| 14449 | case 4: |
| 14450 | case 5: |
| 14451 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 14452 | break; |
| 14453 | |
| 14454 | case 6: |
| 14455 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 14456 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14457 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 14458 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14459 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 14460 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 14461 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 14462 | /* Drop through - unsupported since execlist only. */ |
| 14463 | default: |
| 14464 | /* Default just returns -ENODEV to indicate unsupported */ |
| 14465 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14466 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 14467 | |
| 14468 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 14469 | |
| 14470 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14471 | } |
| 14472 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14473 | /* |
| 14474 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 14475 | * resume, or other times. This quirk makes sure that's the case for |
| 14476 | * affected systems. |
| 14477 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 14478 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14479 | { |
| 14480 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14481 | |
| 14482 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14483 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14484 | } |
| 14485 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 14486 | static void quirk_pipeb_force(struct drm_device *dev) |
| 14487 | { |
| 14488 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14489 | |
| 14490 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 14491 | DRM_INFO("applying pipe b force quirk\n"); |
| 14492 | } |
| 14493 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14494 | /* |
| 14495 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 14496 | */ |
| 14497 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 14498 | { |
| 14499 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14500 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14501 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14502 | } |
| 14503 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14504 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14505 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 14506 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14507 | */ |
| 14508 | static void quirk_invert_brightness(struct drm_device *dev) |
| 14509 | { |
| 14510 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14511 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14512 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14513 | } |
| 14514 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14515 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 14516 | static void quirk_backlight_present(struct drm_device *dev) |
| 14517 | { |
| 14518 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14519 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 14520 | DRM_INFO("applying backlight present quirk\n"); |
| 14521 | } |
| 14522 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14523 | struct intel_quirk { |
| 14524 | int device; |
| 14525 | int subsystem_vendor; |
| 14526 | int subsystem_device; |
| 14527 | void (*hook)(struct drm_device *dev); |
| 14528 | }; |
| 14529 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14530 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 14531 | struct intel_dmi_quirk { |
| 14532 | void (*hook)(struct drm_device *dev); |
| 14533 | const struct dmi_system_id (*dmi_id_list)[]; |
| 14534 | }; |
| 14535 | |
| 14536 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 14537 | { |
| 14538 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 14539 | return 1; |
| 14540 | } |
| 14541 | |
| 14542 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 14543 | { |
| 14544 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 14545 | { |
| 14546 | .callback = intel_dmi_reverse_brightness, |
| 14547 | .ident = "NCR Corporation", |
| 14548 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 14549 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 14550 | }, |
| 14551 | }, |
| 14552 | { } /* terminating entry */ |
| 14553 | }, |
| 14554 | .hook = quirk_invert_brightness, |
| 14555 | }, |
| 14556 | }; |
| 14557 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 14558 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14559 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 14560 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 14561 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14562 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 14563 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 14564 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 14565 | /* 830 needs to leave pipe A & dpll A up */ |
| 14566 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 14567 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 14568 | /* 830 needs to leave pipe B & dpll B up */ |
| 14569 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 14570 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14571 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 14572 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 14573 | |
| 14574 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 14575 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14576 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 14577 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 14578 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 14579 | |
| 14580 | /* Acer/eMachines G725 */ |
| 14581 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 14582 | |
| 14583 | /* Acer/eMachines e725 */ |
| 14584 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 14585 | |
| 14586 | /* Acer/Packard Bell NCL20 */ |
| 14587 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 14588 | |
| 14589 | /* Acer Aspire 4736Z */ |
| 14590 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 14591 | |
| 14592 | /* Acer Aspire 5336 */ |
| 14593 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 14594 | |
| 14595 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 14596 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14597 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 14598 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 14599 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 14600 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 14601 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 14602 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 14603 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14604 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 14605 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 14606 | |
| 14607 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 14608 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 14609 | |
| 14610 | /* Dell Chromebook 11 */ |
| 14611 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14612 | }; |
| 14613 | |
| 14614 | static void intel_init_quirks(struct drm_device *dev) |
| 14615 | { |
| 14616 | struct pci_dev *d = dev->pdev; |
| 14617 | int i; |
| 14618 | |
| 14619 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 14620 | struct intel_quirk *q = &intel_quirks[i]; |
| 14621 | |
| 14622 | if (d->device == q->device && |
| 14623 | (d->subsystem_vendor == q->subsystem_vendor || |
| 14624 | q->subsystem_vendor == PCI_ANY_ID) && |
| 14625 | (d->subsystem_device == q->subsystem_device || |
| 14626 | q->subsystem_device == PCI_ANY_ID)) |
| 14627 | q->hook(dev); |
| 14628 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14629 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 14630 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 14631 | intel_dmi_quirks[i].hook(dev); |
| 14632 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14633 | } |
| 14634 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14635 | /* Disable the VGA plane that we never use */ |
| 14636 | static void i915_disable_vga(struct drm_device *dev) |
| 14637 | { |
| 14638 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14639 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14640 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14641 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14642 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14643 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14644 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14645 | sr1 = inb(VGA_SR_DATA); |
| 14646 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 14647 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 14648 | udelay(300); |
| 14649 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14650 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14651 | POSTING_READ(vga_reg); |
| 14652 | } |
| 14653 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14654 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14655 | { |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 14656 | intel_update_cdclk(dev); |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 14657 | intel_prepare_ddi(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14658 | intel_init_clock_gating(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 14659 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14660 | } |
| 14661 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14662 | void intel_modeset_init(struct drm_device *dev) |
| 14663 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14664 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14665 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14666 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14667 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14668 | |
| 14669 | drm_mode_config_init(dev); |
| 14670 | |
| 14671 | dev->mode_config.min_width = 0; |
| 14672 | dev->mode_config.min_height = 0; |
| 14673 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 14674 | dev->mode_config.preferred_depth = 24; |
| 14675 | dev->mode_config.prefer_shadow = 1; |
| 14676 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 14677 | dev->mode_config.allow_fb_modifiers = true; |
| 14678 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 14679 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14680 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14681 | intel_init_quirks(dev); |
| 14682 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 14683 | intel_init_pm(dev); |
| 14684 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 14685 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14686 | return; |
| 14687 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14688 | intel_init_display(dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 14689 | intel_init_audio(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14690 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14691 | if (IS_GEN2(dev)) { |
| 14692 | dev->mode_config.max_width = 2048; |
| 14693 | dev->mode_config.max_height = 2048; |
| 14694 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 14695 | dev->mode_config.max_width = 4096; |
| 14696 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14697 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14698 | dev->mode_config.max_width = 8192; |
| 14699 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14700 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14701 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14702 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 14703 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 14704 | dev->mode_config.cursor_height = 1023; |
| 14705 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14706 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 14707 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 14708 | } else { |
| 14709 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 14710 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 14711 | } |
| 14712 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 14713 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14714 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14715 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14716 | INTEL_INFO(dev)->num_pipes, |
| 14717 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14718 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14719 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14720 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 14721 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14722 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14723 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 14724 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14725 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14726 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14727 | } |
| 14728 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 14729 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14730 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14731 | /* Just disable it once at startup */ |
| 14732 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14733 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 14734 | |
| 14735 | /* Just in case the BIOS is doing something questionable. */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 14736 | intel_fbc_disable(dev_priv); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 14737 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14738 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 14739 | intel_modeset_setup_hw_state(dev); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14740 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14741 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14742 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 14743 | struct intel_initial_plane_config plane_config = {}; |
| 14744 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14745 | if (!crtc->active) |
| 14746 | continue; |
| 14747 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14748 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14749 | * Note that reserving the BIOS fb up front prevents us |
| 14750 | * from stuffing other stolen allocations like the ring |
| 14751 | * on top. This prevents some ugliness at boot time, and |
| 14752 | * can even allow for smooth boot transitions if the BIOS |
| 14753 | * fb is large enough for the active pipe configuration. |
| 14754 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 14755 | dev_priv->display.get_initial_plane_config(crtc, |
| 14756 | &plane_config); |
| 14757 | |
| 14758 | /* |
| 14759 | * If the fb is shared between multiple heads, we'll |
| 14760 | * just get the first one. |
| 14761 | */ |
| 14762 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14763 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14764 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 14765 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14766 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 14767 | { |
| 14768 | struct intel_connector *connector; |
| 14769 | struct drm_connector *crt = NULL; |
| 14770 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14771 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14772 | |
| 14773 | /* We can't just switch on the pipe A, we need to set things up with a |
| 14774 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 14775 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14776 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14777 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 14778 | crt = &connector->base; |
| 14779 | break; |
| 14780 | } |
| 14781 | } |
| 14782 | |
| 14783 | if (!crt) |
| 14784 | return; |
| 14785 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14786 | 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] | 14787 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14788 | } |
| 14789 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14790 | static bool |
| 14791 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 14792 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14793 | struct drm_device *dev = crtc->base.dev; |
| 14794 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14795 | u32 reg, val; |
| 14796 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14797 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14798 | return true; |
| 14799 | |
| 14800 | reg = DSPCNTR(!crtc->plane); |
| 14801 | val = I915_READ(reg); |
| 14802 | |
| 14803 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 14804 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 14805 | return false; |
| 14806 | |
| 14807 | return true; |
| 14808 | } |
| 14809 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14810 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 14811 | { |
| 14812 | struct drm_device *dev = crtc->base.dev; |
| 14813 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14814 | struct intel_encoder *encoder; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14815 | u32 reg; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14816 | bool enable; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14817 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14818 | /* 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] | 14819 | reg = PIPECONF(crtc->config->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14820 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 14821 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14822 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14823 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 14824 | if (crtc->active) { |
Maarten Lankhorst | 3a03dfb | 2015-07-14 13:46:40 +0200 | [diff] [blame] | 14825 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 14826 | update_scanline_offset(crtc); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14827 | drm_crtc_vblank_on(&crtc->base); |
| 14828 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14829 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14830 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14831 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 14832 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 14833 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14834 | bool plane; |
| 14835 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14836 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 14837 | crtc->base.base.id); |
| 14838 | |
| 14839 | /* Pipe has the wrong plane attached and the plane is active. |
| 14840 | * Temporarily change the plane mapping and disable everything |
| 14841 | * ... */ |
| 14842 | plane = crtc->plane; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 14843 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14844 | crtc->plane = !plane; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14845 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14846 | crtc->plane = plane; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14847 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14848 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14849 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 14850 | crtc->pipe == PIPE_A && !crtc->active) { |
| 14851 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 14852 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 14853 | * call below we restore the pipe to the right state, but leave |
| 14854 | * the required bits on. */ |
| 14855 | intel_enable_pipe_a(dev); |
| 14856 | } |
| 14857 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14858 | /* Adjust the state of the output pipe according to whether we |
| 14859 | * have active connectors/encoders. */ |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14860 | enable = false; |
Maarten Lankhorst | 873ffe6 | 2015-08-05 12:37:07 +0200 | [diff] [blame] | 14861 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 14862 | enable = true; |
| 14863 | break; |
| 14864 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14865 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14866 | if (!enable) |
| 14867 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14868 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 14869 | if (crtc->active != crtc->base.state->active) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14870 | |
| 14871 | /* This can happen either due to bugs in the get_hw_state |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 14872 | * functions or because of calls to intel_crtc_disable_noatomic, |
| 14873 | * or because the pipe is force-enabled due to the |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14874 | * pipe A quirk. */ |
| 14875 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 14876 | crtc->base.base.id, |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14877 | crtc->base.state->enable ? "enabled" : "disabled", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14878 | crtc->active ? "enabled" : "disabled"); |
| 14879 | |
Maarten Lankhorst | 4be40c9 | 2015-07-14 13:45:32 +0200 | [diff] [blame] | 14880 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 14881 | crtc->base.state->active = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14882 | crtc->base.enabled = crtc->active; |
| 14883 | |
| 14884 | /* Because we only establish the connector -> encoder -> |
| 14885 | * crtc links if something is active, this means the |
| 14886 | * crtc is now deactivated. Break the links. connector |
| 14887 | * -> encoder links are only establish when things are |
| 14888 | * actually up, hence no need to break them. */ |
| 14889 | WARN_ON(crtc->active); |
| 14890 | |
Maarten Lankhorst | 2d406bb | 2015-08-05 12:37:09 +0200 | [diff] [blame] | 14891 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14892 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14893 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14894 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 14895 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14896 | /* |
| 14897 | * We start out with underrun reporting disabled to avoid races. |
| 14898 | * For correct bookkeeping mark this on active crtcs. |
| 14899 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14900 | * Also on gmch platforms we dont have any hardware bits to |
| 14901 | * disable the underrun reporting. Which means we need to start |
| 14902 | * out with underrun reporting disabled also on inactive pipes, |
| 14903 | * since otherwise we'll complain about the garbage we read when |
| 14904 | * e.g. coming up after runtime pm. |
| 14905 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14906 | * No protection against concurrent access is required - at |
| 14907 | * worst a fifo underrun happens which also sets this to false. |
| 14908 | */ |
| 14909 | crtc->cpu_fifo_underrun_disabled = true; |
| 14910 | crtc->pch_fifo_underrun_disabled = true; |
| 14911 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14912 | } |
| 14913 | |
| 14914 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 14915 | { |
| 14916 | struct intel_connector *connector; |
| 14917 | struct drm_device *dev = encoder->base.dev; |
Maarten Lankhorst | 873ffe6 | 2015-08-05 12:37:07 +0200 | [diff] [blame] | 14918 | bool active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14919 | |
| 14920 | /* We need to check both for a crtc link (meaning that the |
| 14921 | * encoder is active and trying to read from a pipe) and the |
| 14922 | * pipe itself being active. */ |
| 14923 | bool has_active_crtc = encoder->base.crtc && |
| 14924 | to_intel_crtc(encoder->base.crtc)->active; |
| 14925 | |
Maarten Lankhorst | 873ffe6 | 2015-08-05 12:37:07 +0200 | [diff] [blame] | 14926 | for_each_intel_connector(dev, connector) { |
| 14927 | if (connector->base.encoder != &encoder->base) |
| 14928 | continue; |
| 14929 | |
| 14930 | active = true; |
| 14931 | break; |
| 14932 | } |
| 14933 | |
| 14934 | if (active && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14935 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 14936 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14937 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14938 | |
| 14939 | /* Connector is active, but has no active pipe. This is |
| 14940 | * fallout from our resume register restoring. Disable |
| 14941 | * the encoder manually again. */ |
| 14942 | if (encoder->base.crtc) { |
| 14943 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 14944 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14945 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14946 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 14947 | if (encoder->post_disable) |
| 14948 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14949 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14950 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14951 | |
| 14952 | /* Inconsistent output/port/pipe state happens presumably due to |
| 14953 | * a bug in one of the get_hw_state functions. Or someplace else |
| 14954 | * in our code, like the register restore mess on resume. Clamp |
| 14955 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14956 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14957 | if (connector->encoder != encoder) |
| 14958 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14959 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14960 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14961 | } |
| 14962 | } |
| 14963 | /* Enabled encoders without active connectors will be fixed in |
| 14964 | * the crtc fixup. */ |
| 14965 | } |
| 14966 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14967 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14968 | { |
| 14969 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14970 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14971 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14972 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 14973 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 14974 | i915_disable_vga(dev); |
| 14975 | } |
| 14976 | } |
| 14977 | |
| 14978 | void i915_redisable_vga(struct drm_device *dev) |
| 14979 | { |
| 14980 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14981 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14982 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 14983 | * at a very early point in our resume sequence, where the power well |
| 14984 | * structures are not yet restored. Since this function is at a very |
| 14985 | * paranoid "someone might have enabled VGA while we were not looking" |
| 14986 | * level, just check if the power well is enabled instead of trying to |
| 14987 | * follow the "don't touch the power well if we don't need it" policy |
| 14988 | * the rest of the driver uses. */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14989 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14990 | return; |
| 14991 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14992 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14993 | } |
| 14994 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14995 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 14996 | { |
| 14997 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 14998 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 14999 | return !!(I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE); |
| 15000 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15001 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15002 | static void readout_plane_state(struct intel_crtc *crtc, |
| 15003 | struct intel_crtc_state *crtc_state) |
| 15004 | { |
| 15005 | struct intel_plane *p; |
Maarten Lankhorst | 4cf0ebb | 2015-07-13 16:30:20 +0200 | [diff] [blame] | 15006 | struct intel_plane_state *plane_state; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15007 | bool active = crtc_state->base.active; |
| 15008 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15009 | for_each_intel_plane(crtc->base.dev, p) { |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15010 | if (crtc->pipe != p->pipe) |
| 15011 | continue; |
| 15012 | |
Maarten Lankhorst | 4cf0ebb | 2015-07-13 16:30:20 +0200 | [diff] [blame] | 15013 | plane_state = to_intel_plane_state(p->base.state); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 15014 | |
Maarten Lankhorst | 4cf0ebb | 2015-07-13 16:30:20 +0200 | [diff] [blame] | 15015 | if (p->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 15016 | plane_state->visible = primary_get_hw_state(crtc); |
| 15017 | else { |
| 15018 | if (active) |
| 15019 | p->disable_plane(&p->base, &crtc->base); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 15020 | |
Maarten Lankhorst | 4cf0ebb | 2015-07-13 16:30:20 +0200 | [diff] [blame] | 15021 | plane_state->visible = false; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15022 | } |
| 15023 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15024 | } |
| 15025 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15026 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15027 | { |
| 15028 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15029 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15030 | struct intel_crtc *crtc; |
| 15031 | struct intel_encoder *encoder; |
| 15032 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15033 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15034 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15035 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | b06f8b0 | 2015-07-14 13:42:49 +0200 | [diff] [blame] | 15036 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, crtc->base.state); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15037 | memset(crtc->config, 0, sizeof(*crtc->config)); |
Maarten Lankhorst | f721790 | 2015-06-10 10:24:20 +0200 | [diff] [blame] | 15038 | crtc->config->base.crtc = &crtc->base; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15039 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15040 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15041 | crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15042 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 15043 | crtc->base.state->active = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15044 | crtc->base.enabled = crtc->active; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15045 | |
Maarten Lankhorst | 5c1e342 | 2015-07-14 15:58:28 +0200 | [diff] [blame] | 15046 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
| 15047 | if (crtc->base.state->active) { |
| 15048 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); |
| 15049 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); |
| 15050 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15051 | |
| 15052 | /* |
| 15053 | * The initial mode needs to be set in order to keep |
| 15054 | * the atomic core happy. It wants a valid mode if the |
| 15055 | * crtc's enabled, so we do the above call. |
| 15056 | * |
| 15057 | * At this point some state updated by the connectors |
| 15058 | * in their ->detect() callback has not run yet, so |
| 15059 | * no recalculation can be done yet. |
| 15060 | * |
| 15061 | * Even if we could do a recalculation and modeset |
| 15062 | * right now it would cause a double modeset if |
| 15063 | * fbdev or userspace chooses a different initial mode. |
| 15064 | * |
Maarten Lankhorst | 5c1e342 | 2015-07-14 15:58:28 +0200 | [diff] [blame] | 15065 | * If that happens, someone indicated they wanted a |
| 15066 | * mode change, which means it's safe to do a full |
| 15067 | * recalculation. |
| 15068 | */ |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 15069 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
Maarten Lankhorst | 5c1e342 | 2015-07-14 15:58:28 +0200 | [diff] [blame] | 15070 | } |
| 15071 | |
| 15072 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15073 | readout_plane_state(crtc, to_intel_crtc_state(crtc->base.state)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15074 | |
| 15075 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 15076 | crtc->base.base.id, |
| 15077 | crtc->active ? "enabled" : "disabled"); |
| 15078 | } |
| 15079 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15080 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15081 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15082 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15083 | pll->on = pll->get_hw_state(dev_priv, pll, |
| 15084 | &pll->config.hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15085 | pll->active = 0; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15086 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15087 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15088 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15089 | pll->active++; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15090 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15091 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15092 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15093 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15094 | 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] | 15095 | pll->name, pll->config.crtc_mask, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 15096 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15097 | if (pll->config.crtc_mask) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 15098 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15099 | } |
| 15100 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15101 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15102 | pipe = 0; |
| 15103 | |
| 15104 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15105 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15106 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15107 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15108 | } else { |
| 15109 | encoder->base.crtc = NULL; |
| 15110 | } |
| 15111 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15112 | 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] | 15113 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15114 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15115 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15116 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15117 | } |
| 15118 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15119 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15120 | if (connector->get_hw_state(connector)) { |
| 15121 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15122 | connector->base.encoder = &connector->encoder->base; |
| 15123 | } else { |
| 15124 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15125 | connector->base.encoder = NULL; |
| 15126 | } |
| 15127 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 15128 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 15129 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15130 | connector->base.encoder ? "enabled" : "disabled"); |
| 15131 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15132 | } |
| 15133 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15134 | /* Scan out the current hw modeset state, |
| 15135 | * and sanitizes it to the current state |
| 15136 | */ |
| 15137 | static void |
| 15138 | intel_modeset_setup_hw_state(struct drm_device *dev) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15139 | { |
| 15140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15141 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15142 | struct intel_crtc *crtc; |
| 15143 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15144 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15145 | |
| 15146 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15147 | |
| 15148 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15149 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15150 | intel_sanitize_encoder(encoder); |
| 15151 | } |
| 15152 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15153 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15154 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15155 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15156 | intel_dump_pipe_config(crtc, crtc->config, |
| 15157 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15158 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15159 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15160 | intel_modeset_update_connector_atomic_state(dev); |
| 15161 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15162 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15163 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15164 | |
| 15165 | if (!pll->on || pll->active) |
| 15166 | continue; |
| 15167 | |
| 15168 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 15169 | |
| 15170 | pll->disable(dev_priv, pll); |
| 15171 | pll->on = false; |
| 15172 | } |
| 15173 | |
Ville Syrjälä | 26e1fe4 | 2015-06-24 22:00:06 +0300 | [diff] [blame] | 15174 | if (IS_VALLEYVIEW(dev)) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15175 | vlv_wm_get_hw_state(dev); |
| 15176 | else if (IS_GEN9(dev)) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15177 | skl_wm_get_hw_state(dev); |
| 15178 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15179 | ilk_wm_get_hw_state(dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15180 | |
| 15181 | for_each_intel_crtc(dev, crtc) { |
| 15182 | unsigned long put_domains; |
| 15183 | |
| 15184 | put_domains = modeset_get_crtc_power_domains(&crtc->base); |
| 15185 | if (WARN_ON(put_domains)) |
| 15186 | modeset_put_power_domains(dev_priv, put_domains); |
| 15187 | } |
| 15188 | intel_display_set_init_power(dev_priv, false); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15189 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15190 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15191 | void intel_display_resume(struct drm_device *dev) |
| 15192 | { |
| 15193 | struct drm_atomic_state *state = drm_atomic_state_alloc(dev); |
| 15194 | struct intel_connector *conn; |
| 15195 | struct intel_plane *plane; |
| 15196 | struct drm_crtc *crtc; |
| 15197 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15198 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15199 | if (!state) |
| 15200 | return; |
| 15201 | |
| 15202 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 15203 | |
| 15204 | /* preserve complete old state, including dpll */ |
| 15205 | intel_atomic_get_shared_dpll_state(state); |
| 15206 | |
| 15207 | for_each_crtc(dev, crtc) { |
| 15208 | struct drm_crtc_state *crtc_state = |
| 15209 | drm_atomic_get_crtc_state(state, crtc); |
| 15210 | |
| 15211 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 15212 | if (ret) |
| 15213 | goto err; |
| 15214 | |
| 15215 | /* force a restore */ |
| 15216 | crtc_state->mode_changed = true; |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 15217 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 15218 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15219 | for_each_intel_plane(dev, plane) { |
| 15220 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(state, &plane->base)); |
| 15221 | if (ret) |
| 15222 | goto err; |
| 15223 | } |
| 15224 | |
| 15225 | for_each_intel_connector(dev, conn) { |
| 15226 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(state, &conn->base)); |
| 15227 | if (ret) |
| 15228 | goto err; |
| 15229 | } |
| 15230 | |
| 15231 | intel_modeset_setup_hw_state(dev); |
| 15232 | |
| 15233 | i915_redisable_vga(dev); |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 15234 | ret = drm_atomic_commit(state); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15235 | if (!ret) |
| 15236 | return; |
| 15237 | |
| 15238 | err: |
| 15239 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 15240 | drm_atomic_state_free(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15241 | } |
| 15242 | |
| 15243 | void intel_modeset_gem_init(struct drm_device *dev) |
| 15244 | { |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 15245 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15246 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15247 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15248 | int ret; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15249 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15250 | mutex_lock(&dev->struct_mutex); |
| 15251 | intel_init_gt_powersave(dev); |
| 15252 | mutex_unlock(&dev->struct_mutex); |
| 15253 | |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 15254 | /* |
| 15255 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15256 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15257 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15258 | * indicates as much. |
| 15259 | */ |
| 15260 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 15261 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15262 | DREF_SSC1_ENABLE); |
| 15263 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 15264 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 15265 | |
| 15266 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15267 | |
| 15268 | /* |
| 15269 | * Make sure any fbs we allocated at startup are properly |
| 15270 | * pinned & fenced. When we do the allocation it's too early |
| 15271 | * for this. |
| 15272 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 15273 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15274 | obj = intel_fb_obj(c->primary->fb); |
| 15275 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15276 | continue; |
| 15277 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15278 | mutex_lock(&dev->struct_mutex); |
| 15279 | ret = intel_pin_and_fence_fb_obj(c->primary, |
| 15280 | c->primary->fb, |
| 15281 | c->primary->state, |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 15282 | NULL, NULL); |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15283 | mutex_unlock(&dev->struct_mutex); |
| 15284 | if (ret) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15285 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 15286 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 15287 | drm_framebuffer_unreference(c->primary->fb); |
| 15288 | c->primary->fb = NULL; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15289 | c->primary->crtc = c->primary->state->crtc = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 15290 | update_state_fb(c->primary); |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15291 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15292 | } |
| 15293 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15294 | |
| 15295 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15296 | } |
| 15297 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15298 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 15299 | { |
| 15300 | struct drm_connector *connector = &intel_connector->base; |
| 15301 | |
| 15302 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 15303 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15304 | } |
| 15305 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15306 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15307 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15308 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 15309 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15310 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15311 | intel_disable_gt_powersave(dev); |
| 15312 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15313 | intel_backlight_unregister(dev); |
| 15314 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15315 | /* |
| 15316 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15317 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15318 | * experience fancy races otherwise. |
| 15319 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15320 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15321 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15322 | /* |
| 15323 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15324 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15325 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 15326 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15327 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15328 | intel_unregister_dsm_handler(); |
| 15329 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 15330 | intel_fbc_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15331 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15332 | /* flush any delayed tasks or pending work */ |
| 15333 | flush_scheduled_work(); |
| 15334 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 15335 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 15336 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15337 | struct intel_connector *intel_connector; |
| 15338 | |
| 15339 | intel_connector = to_intel_connector(connector); |
| 15340 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 15341 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 15342 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15343 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15344 | |
| 15345 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15346 | |
| 15347 | mutex_lock(&dev->struct_mutex); |
| 15348 | intel_cleanup_gt_powersave(dev); |
| 15349 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15350 | } |
| 15351 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15352 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 15353 | * Return which encoder is currently attached for connector. |
| 15354 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15355 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15356 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15357 | return &intel_attached_encoder(connector)->base; |
| 15358 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15359 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15360 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 15361 | struct intel_encoder *encoder) |
| 15362 | { |
| 15363 | connector->encoder = encoder; |
| 15364 | drm_mode_connector_attach_encoder(&connector->base, |
| 15365 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15366 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15367 | |
| 15368 | /* |
| 15369 | * set vga decode state - true == enable VGA decode |
| 15370 | */ |
| 15371 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 15372 | { |
| 15373 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 15374 | 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] | 15375 | u16 gmch_ctrl; |
| 15376 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15377 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15378 | DRM_ERROR("failed to read control word\n"); |
| 15379 | return -EIO; |
| 15380 | } |
| 15381 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15382 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15383 | return 0; |
| 15384 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15385 | if (state) |
| 15386 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15387 | else |
| 15388 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15389 | |
| 15390 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15391 | DRM_ERROR("failed to write control word\n"); |
| 15392 | return -EIO; |
| 15393 | } |
| 15394 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15395 | return 0; |
| 15396 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15397 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15398 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15399 | |
| 15400 | u32 power_well_driver; |
| 15401 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15402 | int num_transcoders; |
| 15403 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15404 | struct intel_cursor_error_state { |
| 15405 | u32 control; |
| 15406 | u32 position; |
| 15407 | u32 base; |
| 15408 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15409 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15410 | |
| 15411 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15412 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15413 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15414 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15415 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15416 | |
| 15417 | struct intel_plane_error_state { |
| 15418 | u32 control; |
| 15419 | u32 stride; |
| 15420 | u32 size; |
| 15421 | u32 pos; |
| 15422 | u32 addr; |
| 15423 | u32 surface; |
| 15424 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15425 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15426 | |
| 15427 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15428 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15429 | enum transcoder cpu_transcoder; |
| 15430 | |
| 15431 | u32 conf; |
| 15432 | |
| 15433 | u32 htotal; |
| 15434 | u32 hblank; |
| 15435 | u32 hsync; |
| 15436 | u32 vtotal; |
| 15437 | u32 vblank; |
| 15438 | u32 vsync; |
| 15439 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15440 | }; |
| 15441 | |
| 15442 | struct intel_display_error_state * |
| 15443 | intel_display_capture_error_state(struct drm_device *dev) |
| 15444 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 15445 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15446 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15447 | int transcoders[] = { |
| 15448 | TRANSCODER_A, |
| 15449 | TRANSCODER_B, |
| 15450 | TRANSCODER_C, |
| 15451 | TRANSCODER_EDP, |
| 15452 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15453 | int i; |
| 15454 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15455 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 15456 | return NULL; |
| 15457 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15458 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15459 | if (error == NULL) |
| 15460 | return NULL; |
| 15461 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 15462 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15463 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 15464 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15465 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15466 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15467 | __intel_display_power_is_enabled(dev_priv, |
| 15468 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15469 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15470 | continue; |
| 15471 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 15472 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 15473 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 15474 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15475 | |
| 15476 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 15477 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15478 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 15479 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15480 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 15481 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 15482 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 15483 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15484 | if (INTEL_INFO(dev)->gen >= 4) { |
| 15485 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 15486 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 15487 | } |
| 15488 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15489 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15490 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 15491 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15492 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15493 | } |
| 15494 | |
| 15495 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 15496 | if (HAS_DDI(dev_priv->dev)) |
| 15497 | error->num_transcoders++; /* Account for eDP. */ |
| 15498 | |
| 15499 | for (i = 0; i < error->num_transcoders; i++) { |
| 15500 | enum transcoder cpu_transcoder = transcoders[i]; |
| 15501 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15502 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15503 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 15504 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15505 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15506 | continue; |
| 15507 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15508 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 15509 | |
| 15510 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 15511 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 15512 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 15513 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 15514 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 15515 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 15516 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15517 | } |
| 15518 | |
| 15519 | return error; |
| 15520 | } |
| 15521 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15522 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 15523 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15524 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15525 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15526 | struct drm_device *dev, |
| 15527 | struct intel_display_error_state *error) |
| 15528 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15529 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15530 | int i; |
| 15531 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15532 | if (!error) |
| 15533 | return; |
| 15534 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15535 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 15536 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15537 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15538 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15539 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15540 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15541 | err_printf(m, " Power: %s\n", |
| 15542 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15543 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15544 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15545 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15546 | err_printf(m, "Plane [%d]:\n", i); |
| 15547 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 15548 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15549 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15550 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 15551 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15552 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 15553 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15554 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15555 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15556 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 15557 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15558 | } |
| 15559 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15560 | err_printf(m, "Cursor [%d]:\n", i); |
| 15561 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 15562 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 15563 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15564 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15565 | |
| 15566 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 15567 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15568 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15569 | err_printf(m, " Power: %s\n", |
| 15570 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15571 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 15572 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 15573 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 15574 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 15575 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 15576 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 15577 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 15578 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15579 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15580 | |
| 15581 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 15582 | { |
| 15583 | struct intel_crtc *crtc; |
| 15584 | |
| 15585 | for_each_intel_crtc(dev, crtc) { |
| 15586 | struct intel_unpin_work *work; |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15587 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 15588 | spin_lock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15589 | |
| 15590 | work = crtc->unpin_work; |
| 15591 | |
| 15592 | if (work && work->event && |
| 15593 | work->event->base.file_priv == file) { |
| 15594 | kfree(work->event); |
| 15595 | work->event = NULL; |
| 15596 | } |
| 15597 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 15598 | spin_unlock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 15599 | } |
| 15600 | } |