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> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 47 | #include <linux/reservation.h> |
| 48 | #include <linux/dma-buf.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 49 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 50 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 51 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 52 | DRM_FORMAT_C8, |
| 53 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 54 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 55 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 59 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 60 | DRM_FORMAT_C8, |
| 61 | DRM_FORMAT_RGB565, |
| 62 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 63 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 64 | DRM_FORMAT_XRGB2101010, |
| 65 | DRM_FORMAT_XBGR2101010, |
| 66 | }; |
| 67 | |
| 68 | static const uint32_t skl_primary_formats[] = { |
| 69 | DRM_FORMAT_C8, |
| 70 | DRM_FORMAT_RGB565, |
| 71 | DRM_FORMAT_XRGB8888, |
| 72 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 73 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 74 | DRM_FORMAT_ABGR8888, |
| 75 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 76 | DRM_FORMAT_XBGR2101010, |
Kumar, Mahesh | ea916ea | 2015-09-03 16:17:09 +0530 | [diff] [blame] | 77 | DRM_FORMAT_YUYV, |
| 78 | DRM_FORMAT_YVYU, |
| 79 | DRM_FORMAT_UYVY, |
| 80 | DRM_FORMAT_VYUY, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 83 | /* Cursor formats */ |
| 84 | static const uint32_t intel_cursor_formats[] = { |
| 85 | DRM_FORMAT_ARGB8888, |
| 86 | }; |
| 87 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 89 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 91 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 92 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 93 | static int intel_framebuffer_init(struct drm_device *dev, |
| 94 | struct intel_framebuffer *ifb, |
| 95 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 96 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 97 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 98 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 99 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 100 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 101 | struct intel_link_m_n *m_n, |
| 102 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 103 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 104 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 105 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 106 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 107 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 108 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 109 | const struct intel_crtc_state *pipe_config); |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 110 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 111 | 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] | 112 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 113 | struct intel_crtc_state *crtc_state); |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 114 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 115 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
| 116 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); |
| 117 | static void ironlake_pfit_enable(struct intel_crtc *crtc); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 119 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 120 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 121 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 122 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 123 | } intel_range_t; |
| 124 | |
| 125 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 126 | int dot_limit; |
| 127 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 128 | } intel_p2_t; |
| 129 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 130 | typedef struct intel_limit intel_limit_t; |
| 131 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 132 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 133 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 134 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 135 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 136 | /* returns HPLL frequency in kHz */ |
| 137 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
| 138 | { |
| 139 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 140 | |
| 141 | /* Obtain SKU information */ |
| 142 | mutex_lock(&dev_priv->sb_lock); |
| 143 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 144 | CCK_FUSE_HPLL_FREQ_MASK; |
| 145 | mutex_unlock(&dev_priv->sb_lock); |
| 146 | |
| 147 | return vco_freq[hpll_freq] * 1000; |
| 148 | } |
| 149 | |
| 150 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 151 | const char *name, u32 reg) |
| 152 | { |
| 153 | u32 val; |
| 154 | int divider; |
| 155 | |
| 156 | if (dev_priv->hpll_freq == 0) |
| 157 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 158 | |
| 159 | mutex_lock(&dev_priv->sb_lock); |
| 160 | val = vlv_cck_read(dev_priv, reg); |
| 161 | mutex_unlock(&dev_priv->sb_lock); |
| 162 | |
| 163 | divider = val & CCK_FREQUENCY_VALUES; |
| 164 | |
| 165 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 166 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 167 | "%s change in progress\n", name); |
| 168 | |
| 169 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
| 170 | } |
| 171 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 172 | static int |
| 173 | intel_pch_rawclk(struct drm_i915_private *dev_priv) |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 174 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 175 | return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000; |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 178 | static int |
| 179 | intel_vlv_hrawclk(struct drm_i915_private *dev_priv) |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 180 | { |
Ville Syrjälä | 35d38d1 | 2016-03-02 17:22:16 +0200 | [diff] [blame] | 181 | return vlv_get_cck_clock_hpll(dev_priv, "hrawclk", |
| 182 | CCK_DISPLAY_REF_CLOCK_CONTROL); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static int |
| 186 | intel_g4x_hrawclk(struct drm_i915_private *dev_priv) |
| 187 | { |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 188 | uint32_t clkcfg; |
| 189 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 190 | /* hrawclock is 1/4 the FSB frequency */ |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 191 | clkcfg = I915_READ(CLKCFG); |
| 192 | switch (clkcfg & CLKCFG_FSB_MASK) { |
| 193 | case CLKCFG_FSB_400: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 194 | return 100000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 195 | case CLKCFG_FSB_533: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 196 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 197 | case CLKCFG_FSB_667: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 198 | return 166667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 199 | case CLKCFG_FSB_800: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 200 | return 200000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 201 | case CLKCFG_FSB_1067: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 202 | return 266667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 203 | case CLKCFG_FSB_1333: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 204 | return 333333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 205 | /* these two are just a guess; one of them might be right */ |
| 206 | case CLKCFG_FSB_1600: |
| 207 | case CLKCFG_FSB_1600_ALT: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 208 | return 400000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 209 | default: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 210 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 214 | static void intel_update_rawclk(struct drm_i915_private *dev_priv) |
| 215 | { |
| 216 | if (HAS_PCH_SPLIT(dev_priv)) |
| 217 | dev_priv->rawclk_freq = intel_pch_rawclk(dev_priv); |
| 218 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 219 | dev_priv->rawclk_freq = intel_vlv_hrawclk(dev_priv); |
| 220 | else if (IS_G4X(dev_priv) || IS_PINEVIEW(dev_priv)) |
| 221 | dev_priv->rawclk_freq = intel_g4x_hrawclk(dev_priv); |
| 222 | else |
| 223 | return; /* no rawclk on other platforms, or no need to know it */ |
| 224 | |
| 225 | DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv->rawclk_freq); |
| 226 | } |
| 227 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 228 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 229 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 230 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 231 | return; |
| 232 | |
| 233 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 234 | CCK_CZ_CLOCK_CONTROL); |
| 235 | |
| 236 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 237 | } |
| 238 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 239 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 240 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 241 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 242 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 243 | if (HAS_DDI(dev_priv)) |
| 244 | return pipe_config->port_clock; /* SPLL */ |
| 245 | else if (IS_GEN5(dev_priv)) |
| 246 | return ((I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2) * 10000; |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 247 | else |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 248 | return 270000; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 251 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 253 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 254 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 255 | .m = { .min = 96, .max = 140 }, |
| 256 | .m1 = { .min = 18, .max = 26 }, |
| 257 | .m2 = { .min = 6, .max = 16 }, |
| 258 | .p = { .min = 4, .max = 128 }, |
| 259 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 260 | .p2 = { .dot_limit = 165000, |
| 261 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 264 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 265 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 266 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 267 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 268 | .m = { .min = 96, .max = 140 }, |
| 269 | .m1 = { .min = 18, .max = 26 }, |
| 270 | .m2 = { .min = 6, .max = 16 }, |
| 271 | .p = { .min = 4, .max = 128 }, |
| 272 | .p1 = { .min = 2, .max = 33 }, |
| 273 | .p2 = { .dot_limit = 165000, |
| 274 | .p2_slow = 4, .p2_fast = 4 }, |
| 275 | }; |
| 276 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 277 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 278 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 279 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 280 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 281 | .m = { .min = 96, .max = 140 }, |
| 282 | .m1 = { .min = 18, .max = 26 }, |
| 283 | .m2 = { .min = 6, .max = 16 }, |
| 284 | .p = { .min = 4, .max = 128 }, |
| 285 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 286 | .p2 = { .dot_limit = 165000, |
| 287 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 288 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 289 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 290 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 291 | .dot = { .min = 20000, .max = 400000 }, |
| 292 | .vco = { .min = 1400000, .max = 2800000 }, |
| 293 | .n = { .min = 1, .max = 6 }, |
| 294 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 295 | .m1 = { .min = 8, .max = 18 }, |
| 296 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 297 | .p = { .min = 5, .max = 80 }, |
| 298 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 299 | .p2 = { .dot_limit = 200000, |
| 300 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 304 | .dot = { .min = 20000, .max = 400000 }, |
| 305 | .vco = { .min = 1400000, .max = 2800000 }, |
| 306 | .n = { .min = 1, .max = 6 }, |
| 307 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 308 | .m1 = { .min = 8, .max = 18 }, |
| 309 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 310 | .p = { .min = 7, .max = 98 }, |
| 311 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 312 | .p2 = { .dot_limit = 112000, |
| 313 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 316 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 317 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 318 | .dot = { .min = 25000, .max = 270000 }, |
| 319 | .vco = { .min = 1750000, .max = 3500000}, |
| 320 | .n = { .min = 1, .max = 4 }, |
| 321 | .m = { .min = 104, .max = 138 }, |
| 322 | .m1 = { .min = 17, .max = 23 }, |
| 323 | .m2 = { .min = 5, .max = 11 }, |
| 324 | .p = { .min = 10, .max = 30 }, |
| 325 | .p1 = { .min = 1, .max = 3}, |
| 326 | .p2 = { .dot_limit = 270000, |
| 327 | .p2_slow = 10, |
| 328 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 329 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 333 | .dot = { .min = 22000, .max = 400000 }, |
| 334 | .vco = { .min = 1750000, .max = 3500000}, |
| 335 | .n = { .min = 1, .max = 4 }, |
| 336 | .m = { .min = 104, .max = 138 }, |
| 337 | .m1 = { .min = 16, .max = 23 }, |
| 338 | .m2 = { .min = 5, .max = 11 }, |
| 339 | .p = { .min = 5, .max = 80 }, |
| 340 | .p1 = { .min = 1, .max = 8}, |
| 341 | .p2 = { .dot_limit = 165000, |
| 342 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 346 | .dot = { .min = 20000, .max = 115000 }, |
| 347 | .vco = { .min = 1750000, .max = 3500000 }, |
| 348 | .n = { .min = 1, .max = 3 }, |
| 349 | .m = { .min = 104, .max = 138 }, |
| 350 | .m1 = { .min = 17, .max = 23 }, |
| 351 | .m2 = { .min = 5, .max = 11 }, |
| 352 | .p = { .min = 28, .max = 112 }, |
| 353 | .p1 = { .min = 2, .max = 8 }, |
| 354 | .p2 = { .dot_limit = 0, |
| 355 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 356 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 360 | .dot = { .min = 80000, .max = 224000 }, |
| 361 | .vco = { .min = 1750000, .max = 3500000 }, |
| 362 | .n = { .min = 1, .max = 3 }, |
| 363 | .m = { .min = 104, .max = 138 }, |
| 364 | .m1 = { .min = 17, .max = 23 }, |
| 365 | .m2 = { .min = 5, .max = 11 }, |
| 366 | .p = { .min = 14, .max = 42 }, |
| 367 | .p1 = { .min = 2, .max = 6 }, |
| 368 | .p2 = { .dot_limit = 0, |
| 369 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 370 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 371 | }; |
| 372 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 373 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 374 | .dot = { .min = 20000, .max = 400000}, |
| 375 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 376 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 377 | .n = { .min = 3, .max = 6 }, |
| 378 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 379 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 380 | .m1 = { .min = 0, .max = 0 }, |
| 381 | .m2 = { .min = 0, .max = 254 }, |
| 382 | .p = { .min = 5, .max = 80 }, |
| 383 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 384 | .p2 = { .dot_limit = 200000, |
| 385 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 386 | }; |
| 387 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 388 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 389 | .dot = { .min = 20000, .max = 400000 }, |
| 390 | .vco = { .min = 1700000, .max = 3500000 }, |
| 391 | .n = { .min = 3, .max = 6 }, |
| 392 | .m = { .min = 2, .max = 256 }, |
| 393 | .m1 = { .min = 0, .max = 0 }, |
| 394 | .m2 = { .min = 0, .max = 254 }, |
| 395 | .p = { .min = 7, .max = 112 }, |
| 396 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 397 | .p2 = { .dot_limit = 112000, |
| 398 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 401 | /* Ironlake / Sandybridge |
| 402 | * |
| 403 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 404 | * the range value for them is (actual_value - 2). |
| 405 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 406 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 407 | .dot = { .min = 25000, .max = 350000 }, |
| 408 | .vco = { .min = 1760000, .max = 3510000 }, |
| 409 | .n = { .min = 1, .max = 5 }, |
| 410 | .m = { .min = 79, .max = 127 }, |
| 411 | .m1 = { .min = 12, .max = 22 }, |
| 412 | .m2 = { .min = 5, .max = 9 }, |
| 413 | .p = { .min = 5, .max = 80 }, |
| 414 | .p1 = { .min = 1, .max = 8 }, |
| 415 | .p2 = { .dot_limit = 225000, |
| 416 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 417 | }; |
| 418 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 419 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 420 | .dot = { .min = 25000, .max = 350000 }, |
| 421 | .vco = { .min = 1760000, .max = 3510000 }, |
| 422 | .n = { .min = 1, .max = 3 }, |
| 423 | .m = { .min = 79, .max = 118 }, |
| 424 | .m1 = { .min = 12, .max = 22 }, |
| 425 | .m2 = { .min = 5, .max = 9 }, |
| 426 | .p = { .min = 28, .max = 112 }, |
| 427 | .p1 = { .min = 2, .max = 8 }, |
| 428 | .p2 = { .dot_limit = 225000, |
| 429 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 433 | .dot = { .min = 25000, .max = 350000 }, |
| 434 | .vco = { .min = 1760000, .max = 3510000 }, |
| 435 | .n = { .min = 1, .max = 3 }, |
| 436 | .m = { .min = 79, .max = 127 }, |
| 437 | .m1 = { .min = 12, .max = 22 }, |
| 438 | .m2 = { .min = 5, .max = 9 }, |
| 439 | .p = { .min = 14, .max = 56 }, |
| 440 | .p1 = { .min = 2, .max = 8 }, |
| 441 | .p2 = { .dot_limit = 225000, |
| 442 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 443 | }; |
| 444 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 445 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 446 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 447 | .dot = { .min = 25000, .max = 350000 }, |
| 448 | .vco = { .min = 1760000, .max = 3510000 }, |
| 449 | .n = { .min = 1, .max = 2 }, |
| 450 | .m = { .min = 79, .max = 126 }, |
| 451 | .m1 = { .min = 12, .max = 22 }, |
| 452 | .m2 = { .min = 5, .max = 9 }, |
| 453 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 454 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 455 | .p2 = { .dot_limit = 225000, |
| 456 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 460 | .dot = { .min = 25000, .max = 350000 }, |
| 461 | .vco = { .min = 1760000, .max = 3510000 }, |
| 462 | .n = { .min = 1, .max = 3 }, |
| 463 | .m = { .min = 79, .max = 126 }, |
| 464 | .m1 = { .min = 12, .max = 22 }, |
| 465 | .m2 = { .min = 5, .max = 9 }, |
| 466 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 467 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 468 | .p2 = { .dot_limit = 225000, |
| 469 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 470 | }; |
| 471 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 472 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 473 | /* |
| 474 | * These are the data rate limits (measured in fast clocks) |
| 475 | * since those are the strictest limits we have. The fast |
| 476 | * clock and actual rate limits are more relaxed, so checking |
| 477 | * them would make no difference. |
| 478 | */ |
| 479 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 480 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 481 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 482 | .m1 = { .min = 2, .max = 3 }, |
| 483 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 484 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 485 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 488 | static const intel_limit_t intel_limits_chv = { |
| 489 | /* |
| 490 | * These are the data rate limits (measured in fast clocks) |
| 491 | * since those are the strictest limits we have. The fast |
| 492 | * clock and actual rate limits are more relaxed, so checking |
| 493 | * them would make no difference. |
| 494 | */ |
| 495 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 496 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 497 | .n = { .min = 1, .max = 1 }, |
| 498 | .m1 = { .min = 2, .max = 2 }, |
| 499 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 500 | .p1 = { .min = 2, .max = 4 }, |
| 501 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 502 | }; |
| 503 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 504 | static const intel_limit_t intel_limits_bxt = { |
| 505 | /* FIXME: find real dot limits */ |
| 506 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 507 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 508 | .n = { .min = 1, .max = 1 }, |
| 509 | .m1 = { .min = 2, .max = 2 }, |
| 510 | /* FIXME: find real m2 limits */ |
| 511 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 512 | .p1 = { .min = 2, .max = 4 }, |
| 513 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 514 | }; |
| 515 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 516 | static bool |
| 517 | needs_modeset(struct drm_crtc_state *state) |
| 518 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 519 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 522 | /** |
| 523 | * Returns whether any output on the specified pipe is of the specified type |
| 524 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 525 | 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] | 526 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 527 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 528 | struct intel_encoder *encoder; |
| 529 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 530 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 531 | if (encoder->type == type) |
| 532 | return true; |
| 533 | |
| 534 | return false; |
| 535 | } |
| 536 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 537 | /** |
| 538 | * Returns whether any output on the specified pipe will have the specified |
| 539 | * type after a staged modeset is complete, i.e., the same as |
| 540 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 541 | * encoder->crtc. |
| 542 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 543 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 544 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 545 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 546 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 547 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 548 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 549 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 550 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 551 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 552 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 553 | if (connector_state->crtc != crtc_state->base.crtc) |
| 554 | continue; |
| 555 | |
| 556 | num_connectors++; |
| 557 | |
| 558 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 559 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 560 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 564 | |
| 565 | return false; |
| 566 | } |
| 567 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 568 | static const intel_limit_t * |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 569 | intel_g4x_limit(struct intel_crtc_state *crtc_state) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 570 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 571 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 572 | const intel_limit_t *limit; |
| 573 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 574 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 575 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 576 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 577 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 578 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 579 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 580 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 581 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 582 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 583 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 584 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 585 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 586 | |
| 587 | return limit; |
| 588 | } |
| 589 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 590 | static const intel_limit_t * |
| 591 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 592 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 593 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | const intel_limit_t *limit; |
| 595 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 596 | if (IS_BROXTON(dev)) |
| 597 | limit = &intel_limits_bxt; |
Ander Conselvan de Oliveira | 8f0d5b9 | 2016-03-21 18:00:04 +0200 | [diff] [blame] | 598 | else if (WARN_ON(HAS_PCH_SPLIT(dev))) |
| 599 | limit = NULL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 600 | else if (IS_G4X(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 601 | limit = intel_g4x_limit(crtc_state); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 602 | } else if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 603 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 604 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 605 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 606 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 607 | } else if (IS_CHERRYVIEW(dev)) { |
| 608 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 609 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 610 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 611 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 612 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 613 | limit = &intel_limits_i9xx_lvds; |
| 614 | else |
| 615 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 616 | } else { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 617 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 618 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 619 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 620 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 621 | else |
| 622 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 623 | } |
| 624 | return limit; |
| 625 | } |
| 626 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 627 | /* |
| 628 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 629 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 630 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 631 | * The helpers' return value is the rate of the clock that is fed to the |
| 632 | * display engine's pipe which can be the above fast dot clock rate or a |
| 633 | * divided-down version of it. |
| 634 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 635 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 636 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 638 | clock->m = clock->m2 + 2; |
| 639 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 640 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 641 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 642 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 643 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 644 | |
| 645 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 646 | } |
| 647 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 648 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 649 | { |
| 650 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 651 | } |
| 652 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 653 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 654 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 655 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 656 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 657 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 658 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 659 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 660 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 661 | |
| 662 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 665 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 666 | { |
| 667 | clock->m = clock->m1 * clock->m2; |
| 668 | clock->p = clock->p1 * clock->p2; |
| 669 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 670 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 671 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 672 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 673 | |
| 674 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 675 | } |
| 676 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 677 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 678 | { |
| 679 | clock->m = clock->m1 * clock->m2; |
| 680 | clock->p = clock->p1 * clock->p2; |
| 681 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 682 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 683 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 684 | clock->n << 22); |
| 685 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 686 | |
| 687 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 688 | } |
| 689 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 690 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 691 | /** |
| 692 | * Returns whether the given set of divisors are valid for a given refclk with |
| 693 | * the given connectors. |
| 694 | */ |
| 695 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 696 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 697 | const intel_limit_t *limit, |
| 698 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 699 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 700 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 701 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 702 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 703 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 704 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 705 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 706 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 707 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 708 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 709 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && |
| 710 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 711 | if (clock->m1 <= clock->m2) |
| 712 | INTELPllInvalid("m1 <= m2\n"); |
| 713 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 714 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 715 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 716 | INTELPllInvalid("p out of range\n"); |
| 717 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 718 | INTELPllInvalid("m out of range\n"); |
| 719 | } |
| 720 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 721 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 722 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 723 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 724 | * connector, etc., rather than just a single range. |
| 725 | */ |
| 726 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 727 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 728 | |
| 729 | return true; |
| 730 | } |
| 731 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 732 | static int |
| 733 | i9xx_select_p2_div(const intel_limit_t *limit, |
| 734 | const struct intel_crtc_state *crtc_state, |
| 735 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 736 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 737 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 738 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 739 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 740 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 741 | * For LVDS just rely on its current settings for dual-channel. |
| 742 | * We haven't figured out how to reliably set up different |
| 743 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 744 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 745 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 746 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 747 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 748 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 749 | } else { |
| 750 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 751 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 752 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 753 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 754 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static bool |
| 758 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 759 | struct intel_crtc_state *crtc_state, |
| 760 | int target, int refclk, intel_clock_t *match_clock, |
| 761 | intel_clock_t *best_clock) |
| 762 | { |
| 763 | struct drm_device *dev = crtc_state->base.crtc->dev; |
| 764 | intel_clock_t clock; |
| 765 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 766 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 767 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 768 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 769 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 770 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 771 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 772 | clock.m1++) { |
| 773 | for (clock.m2 = limit->m2.min; |
| 774 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 775 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 776 | break; |
| 777 | for (clock.n = limit->n.min; |
| 778 | clock.n <= limit->n.max; clock.n++) { |
| 779 | for (clock.p1 = limit->p1.min; |
| 780 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 781 | int this_err; |
| 782 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 783 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 784 | if (!intel_PLL_is_valid(dev, limit, |
| 785 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 786 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 787 | if (match_clock && |
| 788 | clock.p != match_clock->p) |
| 789 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 790 | |
| 791 | this_err = abs(clock.dot - target); |
| 792 | if (this_err < err) { |
| 793 | *best_clock = clock; |
| 794 | err = this_err; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | return (err != target); |
| 802 | } |
| 803 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 804 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 805 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 806 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 807 | int target, int refclk, intel_clock_t *match_clock, |
| 808 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 809 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 810 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 811 | intel_clock_t clock; |
| 812 | int err = target; |
| 813 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 814 | memset(best_clock, 0, sizeof(*best_clock)); |
| 815 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 816 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 817 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 818 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 819 | clock.m1++) { |
| 820 | for (clock.m2 = limit->m2.min; |
| 821 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 822 | for (clock.n = limit->n.min; |
| 823 | clock.n <= limit->n.max; clock.n++) { |
| 824 | for (clock.p1 = limit->p1.min; |
| 825 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 826 | int this_err; |
| 827 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 828 | pnv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 829 | if (!intel_PLL_is_valid(dev, limit, |
| 830 | &clock)) |
| 831 | continue; |
| 832 | if (match_clock && |
| 833 | clock.p != match_clock->p) |
| 834 | continue; |
| 835 | |
| 836 | this_err = abs(clock.dot - target); |
| 837 | if (this_err < err) { |
| 838 | *best_clock = clock; |
| 839 | err = this_err; |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | return (err != target); |
| 847 | } |
| 848 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 849 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 850 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 851 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 852 | int target, int refclk, intel_clock_t *match_clock, |
| 853 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 854 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 855 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 856 | intel_clock_t clock; |
| 857 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 858 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 859 | /* approximately equals target * 0.00585 */ |
| 860 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 861 | |
| 862 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 863 | |
| 864 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 865 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 866 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 867 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 868 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 869 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 870 | for (clock.m1 = limit->m1.max; |
| 871 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 872 | for (clock.m2 = limit->m2.max; |
| 873 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 874 | for (clock.p1 = limit->p1.max; |
| 875 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 876 | int this_err; |
| 877 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 878 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 879 | if (!intel_PLL_is_valid(dev, limit, |
| 880 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 881 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 882 | |
| 883 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 884 | if (this_err < err_most) { |
| 885 | *best_clock = clock; |
| 886 | err_most = this_err; |
| 887 | max_n = clock.n; |
| 888 | found = true; |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 894 | return found; |
| 895 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 896 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 897 | /* |
| 898 | * Check if the calculated PLL configuration is more optimal compared to the |
| 899 | * best configuration and error found so far. Return the calculated error. |
| 900 | */ |
| 901 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 902 | const intel_clock_t *calculated_clock, |
| 903 | const intel_clock_t *best_clock, |
| 904 | unsigned int best_error_ppm, |
| 905 | unsigned int *error_ppm) |
| 906 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 907 | /* |
| 908 | * For CHV ignore the error and consider only the P value. |
| 909 | * Prefer a bigger P value based on HW requirements. |
| 910 | */ |
| 911 | if (IS_CHERRYVIEW(dev)) { |
| 912 | *error_ppm = 0; |
| 913 | |
| 914 | return calculated_clock->p > best_clock->p; |
| 915 | } |
| 916 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 917 | if (WARN_ON_ONCE(!target_freq)) |
| 918 | return false; |
| 919 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 920 | *error_ppm = div_u64(1000000ULL * |
| 921 | abs(target_freq - calculated_clock->dot), |
| 922 | target_freq); |
| 923 | /* |
| 924 | * Prefer a better P value over a better (smaller) error if the error |
| 925 | * is small. Ensure this preference for future configurations too by |
| 926 | * setting the error to 0. |
| 927 | */ |
| 928 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 929 | *error_ppm = 0; |
| 930 | |
| 931 | return true; |
| 932 | } |
| 933 | |
| 934 | return *error_ppm + 10 < best_error_ppm; |
| 935 | } |
| 936 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 937 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 938 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 939 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 940 | int target, int refclk, intel_clock_t *match_clock, |
| 941 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 942 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 943 | 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] | 944 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 945 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 946 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 947 | /* min update 19.2 MHz */ |
| 948 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 949 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 950 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 951 | target *= 5; /* fast clock */ |
| 952 | |
| 953 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 954 | |
| 955 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 956 | 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] | 957 | 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] | 958 | 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] | 959 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 960 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 961 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 962 | 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] | 963 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 964 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 965 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 966 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 967 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 968 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 969 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 970 | if (!intel_PLL_is_valid(dev, limit, |
| 971 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 972 | continue; |
| 973 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 974 | if (!vlv_PLL_is_optimal(dev, target, |
| 975 | &clock, |
| 976 | best_clock, |
| 977 | bestppm, &ppm)) |
| 978 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 979 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 980 | *best_clock = clock; |
| 981 | bestppm = ppm; |
| 982 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 987 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 988 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 989 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 990 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 991 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 992 | chv_find_best_dpll(const intel_limit_t *limit, |
| 993 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 994 | int target, int refclk, intel_clock_t *match_clock, |
| 995 | intel_clock_t *best_clock) |
| 996 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 997 | 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] | 998 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 999 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1000 | intel_clock_t clock; |
| 1001 | uint64_t m2; |
| 1002 | int found = false; |
| 1003 | |
| 1004 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1005 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1006 | |
| 1007 | /* |
| 1008 | * Based on hardware doc, the n always set to 1, and m1 always |
| 1009 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 1010 | * revisit this because n may not 1 anymore. |
| 1011 | */ |
| 1012 | clock.n = 1, clock.m1 = 2; |
| 1013 | target *= 5; /* fast clock */ |
| 1014 | |
| 1015 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 1016 | for (clock.p2 = limit->p2.p2_fast; |
| 1017 | clock.p2 >= limit->p2.p2_slow; |
| 1018 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1019 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1020 | |
| 1021 | clock.p = clock.p1 * clock.p2; |
| 1022 | |
| 1023 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 1024 | clock.n) << 22, refclk * clock.m1); |
| 1025 | |
| 1026 | if (m2 > INT_MAX/clock.m1) |
| 1027 | continue; |
| 1028 | |
| 1029 | clock.m2 = m2; |
| 1030 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 1031 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1032 | |
| 1033 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 1034 | continue; |
| 1035 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1036 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 1037 | best_error_ppm, &error_ppm)) |
| 1038 | continue; |
| 1039 | |
| 1040 | *best_clock = clock; |
| 1041 | best_error_ppm = error_ppm; |
| 1042 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | return found; |
| 1047 | } |
| 1048 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1049 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
| 1050 | intel_clock_t *best_clock) |
| 1051 | { |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 1052 | int refclk = i9xx_get_refclk(crtc_state); |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1053 | |
| 1054 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, |
| 1055 | target_clock, refclk, NULL, best_clock); |
| 1056 | } |
| 1057 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1058 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 1059 | { |
| 1060 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1061 | |
| 1062 | /* Be paranoid as we can arrive here with only partial |
| 1063 | * state retrieved from the hardware during setup. |
| 1064 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1065 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1066 | * as Haswell has gained clock readout/fastboot support. |
| 1067 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 1068 | * 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] | 1069 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1070 | * |
| 1071 | * FIXME: The intel_crtc->active here should be switched to |
| 1072 | * crtc->state->active once we have proper CRTC states wired up |
| 1073 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1074 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1075 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1076 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1077 | } |
| 1078 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1079 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1080 | enum pipe pipe) |
| 1081 | { |
| 1082 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1083 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1084 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1085 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1088 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 1089 | { |
| 1090 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1091 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1092 | u32 line1, line2; |
| 1093 | u32 line_mask; |
| 1094 | |
| 1095 | if (IS_GEN2(dev)) |
| 1096 | line_mask = DSL_LINEMASK_GEN2; |
| 1097 | else |
| 1098 | line_mask = DSL_LINEMASK_GEN3; |
| 1099 | |
| 1100 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1101 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1102 | line2 = I915_READ(reg) & line_mask; |
| 1103 | |
| 1104 | return line1 == line2; |
| 1105 | } |
| 1106 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1107 | /* |
| 1108 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1109 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1110 | * |
| 1111 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1112 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1113 | * see an interrupt when the pipe is disabled. |
| 1114 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1115 | * On Gen4 and above: |
| 1116 | * wait for the pipe register state bit to turn off |
| 1117 | * |
| 1118 | * Otherwise: |
| 1119 | * wait for the display line value to settle (it usually |
| 1120 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1121 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1122 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1123 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1124 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1125 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1126 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1127 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1128 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1129 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1130 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1131 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1132 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1133 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1134 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1135 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1136 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1137 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1138 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1139 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1140 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1141 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1144 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1145 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1146 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1147 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1148 | u32 val; |
| 1149 | bool cur_state; |
| 1150 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1151 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1152 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1153 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1154 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1155 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1156 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1157 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1158 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1159 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1160 | { |
| 1161 | u32 val; |
| 1162 | bool cur_state; |
| 1163 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1164 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1165 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1166 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1167 | |
| 1168 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1169 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1170 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1171 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1172 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1173 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1174 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1175 | enum pipe pipe, bool state) |
| 1176 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1177 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1178 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1179 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1180 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1181 | if (HAS_DDI(dev_priv->dev)) { |
| 1182 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1183 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1184 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1185 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1186 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1187 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1188 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1189 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1190 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1191 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1192 | } |
| 1193 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1194 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1195 | |
| 1196 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1197 | enum pipe pipe, bool state) |
| 1198 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1199 | u32 val; |
| 1200 | bool cur_state; |
| 1201 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1202 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1203 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1204 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1205 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1206 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1207 | } |
| 1208 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1209 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1210 | |
| 1211 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1212 | enum pipe pipe) |
| 1213 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1214 | u32 val; |
| 1215 | |
| 1216 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1217 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1218 | return; |
| 1219 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1220 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1221 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1222 | return; |
| 1223 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1224 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1225 | 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] | 1226 | } |
| 1227 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1228 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1229 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1230 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1231 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1232 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1233 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1234 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1235 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1236 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1237 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1238 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1241 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1242 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1243 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1244 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1245 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1246 | u32 val; |
| 1247 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1248 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1249 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1250 | if (WARN_ON(HAS_DDI(dev))) |
| 1251 | return; |
| 1252 | |
| 1253 | if (HAS_PCH_SPLIT(dev)) { |
| 1254 | u32 port_sel; |
| 1255 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1256 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1257 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1258 | |
| 1259 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1260 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1261 | panel_pipe = PIPE_B; |
| 1262 | /* XXX: else fix for eDP */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1263 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1264 | /* presumably write lock depends on pipe, not port select */ |
| 1265 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1266 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1267 | } else { |
| 1268 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1269 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1270 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | val = I915_READ(pp_reg); |
| 1274 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1275 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1276 | locked = false; |
| 1277 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1278 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1279 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1280 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1283 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1284 | enum pipe pipe, bool state) |
| 1285 | { |
| 1286 | struct drm_device *dev = dev_priv->dev; |
| 1287 | bool cur_state; |
| 1288 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1289 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 1290 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1291 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1292 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1293 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1294 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1295 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1296 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1297 | } |
| 1298 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1299 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1300 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1301 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1302 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1303 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1304 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1305 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1306 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1307 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1308 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1309 | /* if we need the pipe quirk it must be always on */ |
| 1310 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1311 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1312 | state = true; |
| 1313 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1314 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1315 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1316 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1317 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1318 | |
| 1319 | intel_display_power_put(dev_priv, power_domain); |
| 1320 | } else { |
| 1321 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1322 | } |
| 1323 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1324 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1325 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1326 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1329 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1330 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1331 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1332 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1333 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1334 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1335 | val = I915_READ(DSPCNTR(plane)); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1336 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1337 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1338 | "plane %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1339 | plane_name(plane), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1342 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1343 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1344 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1345 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1346 | enum pipe pipe) |
| 1347 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1348 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1349 | int i; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1350 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1351 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1352 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1353 | u32 val = I915_READ(DSPCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1354 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1355 | "plane %c assertion failure, should be disabled but not\n", |
| 1356 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1357 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1358 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1359 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1360 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1361 | for_each_pipe(dev_priv, i) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1362 | u32 val = I915_READ(DSPCNTR(i)); |
| 1363 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1364 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1365 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1366 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1367 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1371 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1372 | enum pipe pipe) |
| 1373 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1374 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1375 | int sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1376 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1377 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1378 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1379 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1380 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1381 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1382 | sprite, pipe_name(pipe)); |
| 1383 | } |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1384 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1385 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1386 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1387 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1388 | "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] | 1389 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1390 | } |
| 1391 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1392 | u32 val = I915_READ(SPRCTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1393 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1394 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1395 | plane_name(pipe), pipe_name(pipe)); |
| 1396 | } else if (INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1397 | u32 val = I915_READ(DVSCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1398 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1399 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1400 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1404 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1405 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1406 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1407 | drm_crtc_vblank_put(crtc); |
| 1408 | } |
| 1409 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1410 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1411 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1412 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1413 | u32 val; |
| 1414 | bool enabled; |
| 1415 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1416 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1417 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1418 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1419 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1420 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1421 | } |
| 1422 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1423 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1424 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1425 | { |
| 1426 | if ((val & DP_PORT_EN) == 0) |
| 1427 | return false; |
| 1428 | |
| 1429 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1430 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1431 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1432 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1433 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1434 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1435 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1436 | } else { |
| 1437 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1438 | return false; |
| 1439 | } |
| 1440 | return true; |
| 1441 | } |
| 1442 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1443 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1444 | enum pipe pipe, u32 val) |
| 1445 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1446 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1447 | return false; |
| 1448 | |
| 1449 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1450 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1451 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1452 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1453 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1454 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1455 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1456 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1457 | return false; |
| 1458 | } |
| 1459 | return true; |
| 1460 | } |
| 1461 | |
| 1462 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1463 | enum pipe pipe, u32 val) |
| 1464 | { |
| 1465 | if ((val & LVDS_PORT_EN) == 0) |
| 1466 | return false; |
| 1467 | |
| 1468 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1469 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1470 | return false; |
| 1471 | } else { |
| 1472 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1473 | return false; |
| 1474 | } |
| 1475 | return true; |
| 1476 | } |
| 1477 | |
| 1478 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1479 | enum pipe pipe, u32 val) |
| 1480 | { |
| 1481 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1482 | return false; |
| 1483 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1484 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1485 | return false; |
| 1486 | } else { |
| 1487 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1488 | return false; |
| 1489 | } |
| 1490 | return true; |
| 1491 | } |
| 1492 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1493 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1494 | enum pipe pipe, i915_reg_t reg, |
| 1495 | u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1496 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1497 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1498 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1499 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1500 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1501 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1502 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1503 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1504 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1508 | enum pipe pipe, i915_reg_t reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1509 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1510 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1511 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1512 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1513 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1514 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1515 | 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] | 1516 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1517 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1521 | enum pipe pipe) |
| 1522 | { |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1523 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1524 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1525 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1526 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1527 | 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] | 1528 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1529 | val = I915_READ(PCH_ADPA); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1530 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1531 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1532 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1533 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1534 | val = I915_READ(PCH_LVDS); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1535 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1536 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1537 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1538 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1539 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1540 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1541 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1544 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1545 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1546 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1547 | struct drm_device *dev = crtc->base.dev; |
| 1548 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1549 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1550 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1551 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1552 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1553 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1554 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1555 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1556 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1557 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1558 | I915_WRITE(reg, dpll); |
| 1559 | POSTING_READ(reg); |
| 1560 | udelay(150); |
| 1561 | |
| 1562 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1563 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1564 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1565 | 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] | 1566 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1567 | |
| 1568 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1569 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1570 | POSTING_READ(reg); |
| 1571 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1572 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1573 | POSTING_READ(reg); |
| 1574 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1575 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1576 | POSTING_READ(reg); |
| 1577 | udelay(150); /* wait for warmup */ |
| 1578 | } |
| 1579 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1580 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1581 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1582 | { |
| 1583 | struct drm_device *dev = crtc->base.dev; |
| 1584 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1585 | int pipe = crtc->pipe; |
| 1586 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1587 | u32 tmp; |
| 1588 | |
| 1589 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1590 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1591 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1592 | |
| 1593 | /* Enable back the 10bit clock to display controller */ |
| 1594 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1595 | tmp |= DPIO_DCLKP_EN; |
| 1596 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1597 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1598 | mutex_unlock(&dev_priv->sb_lock); |
| 1599 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1600 | /* |
| 1601 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1602 | */ |
| 1603 | udelay(1); |
| 1604 | |
| 1605 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1606 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1607 | |
| 1608 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1609 | 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] | 1610 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1611 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1612 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1613 | 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] | 1614 | POSTING_READ(DPLL_MD(pipe)); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1615 | } |
| 1616 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1617 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1618 | { |
| 1619 | struct intel_crtc *crtc; |
| 1620 | int count = 0; |
| 1621 | |
| 1622 | for_each_intel_crtc(dev, crtc) |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1623 | count += crtc->base.state->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1624 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1625 | |
| 1626 | return count; |
| 1627 | } |
| 1628 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1629 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1630 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1631 | struct drm_device *dev = crtc->base.dev; |
| 1632 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1633 | i915_reg_t reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1634 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1635 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1636 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1637 | |
| 1638 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1639 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1640 | |
| 1641 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1642 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1643 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1644 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1645 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1646 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1647 | /* |
| 1648 | * It appears to be important that we don't enable this |
| 1649 | * for the current pipe before otherwise configuring the |
| 1650 | * PLL. No idea how this should be handled if multiple |
| 1651 | * DVO outputs are enabled simultaneosly. |
| 1652 | */ |
| 1653 | dpll |= DPLL_DVO_2X_MODE; |
| 1654 | I915_WRITE(DPLL(!crtc->pipe), |
| 1655 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1656 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1657 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1658 | /* |
| 1659 | * Apparently we need to have VGA mode enabled prior to changing |
| 1660 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1661 | * dividers, even though the register value does change. |
| 1662 | */ |
| 1663 | I915_WRITE(reg, 0); |
| 1664 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1665 | I915_WRITE(reg, dpll); |
| 1666 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1667 | /* Wait for the clocks to stabilize. */ |
| 1668 | POSTING_READ(reg); |
| 1669 | udelay(150); |
| 1670 | |
| 1671 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1672 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1673 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1674 | } else { |
| 1675 | /* The pixel multiplier can only be updated once the |
| 1676 | * DPLL is enabled and the clocks are stable. |
| 1677 | * |
| 1678 | * So write it again. |
| 1679 | */ |
| 1680 | I915_WRITE(reg, dpll); |
| 1681 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1682 | |
| 1683 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1684 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1685 | POSTING_READ(reg); |
| 1686 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1687 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1688 | POSTING_READ(reg); |
| 1689 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1690 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1691 | POSTING_READ(reg); |
| 1692 | udelay(150); /* wait for warmup */ |
| 1693 | } |
| 1694 | |
| 1695 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1696 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1697 | * @dev_priv: i915 private structure |
| 1698 | * @pipe: pipe PLL to disable |
| 1699 | * |
| 1700 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1701 | * |
| 1702 | * Note! This is for pre-ILK only. |
| 1703 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1704 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1705 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1706 | struct drm_device *dev = crtc->base.dev; |
| 1707 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1708 | enum pipe pipe = crtc->pipe; |
| 1709 | |
| 1710 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1711 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1712 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1713 | !intel_num_dvo_pipes(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1714 | I915_WRITE(DPLL(PIPE_B), |
| 1715 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1716 | I915_WRITE(DPLL(PIPE_A), |
| 1717 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1718 | } |
| 1719 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1720 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1721 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1722 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1723 | return; |
| 1724 | |
| 1725 | /* Make sure the pipe isn't still relying on us */ |
| 1726 | assert_pipe_disabled(dev_priv, pipe); |
| 1727 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1728 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1729 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1732 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1733 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1734 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1735 | |
| 1736 | /* Make sure the pipe isn't still relying on us */ |
| 1737 | assert_pipe_disabled(dev_priv, pipe); |
| 1738 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1739 | /* |
| 1740 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1741 | * The latter is needed for VGA hotplug / manual detection. |
| 1742 | */ |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1743 | val = DPLL_VGA_MODE_DIS; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1744 | if (pipe == PIPE_B) |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1745 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1746 | I915_WRITE(DPLL(pipe), val); |
| 1747 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1748 | |
| 1749 | } |
| 1750 | |
| 1751 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1752 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1753 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1754 | u32 val; |
| 1755 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1756 | /* Make sure the pipe isn't still relying on us */ |
| 1757 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1758 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1759 | /* Set PLL en = 0 */ |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1760 | val = DPLL_SSC_REF_CLK_CHV | |
| 1761 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1762 | if (pipe != PIPE_A) |
| 1763 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1764 | I915_WRITE(DPLL(pipe), val); |
| 1765 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1766 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1767 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1768 | |
| 1769 | /* Disable 10bit clock to display controller */ |
| 1770 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1771 | val &= ~DPIO_DCLKP_EN; |
| 1772 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1773 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1774 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1777 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1778 | struct intel_digital_port *dport, |
| 1779 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1780 | { |
| 1781 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1782 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1783 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1784 | switch (dport->port) { |
| 1785 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1786 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1787 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1788 | break; |
| 1789 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1790 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1791 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1792 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1793 | break; |
| 1794 | case PORT_D: |
| 1795 | port_mask = DPLL_PORTD_READY_MASK; |
| 1796 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1797 | break; |
| 1798 | default: |
| 1799 | BUG(); |
| 1800 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1801 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1802 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
| 1803 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
| 1804 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1807 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1808 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1809 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1810 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1811 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1812 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1813 | i915_reg_t reg; |
| 1814 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1815 | |
| 1816 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1817 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1818 | |
| 1819 | /* Make sure PCH DPLL is enabled */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 1820 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1821 | |
| 1822 | /* FDI must be feeding us bits for PCH ports */ |
| 1823 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1824 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1825 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1826 | if (HAS_PCH_CPT(dev)) { |
| 1827 | /* Workaround: Set the timing override bit before enabling the |
| 1828 | * pch transcoder. */ |
| 1829 | reg = TRANS_CHICKEN2(pipe); |
| 1830 | val = I915_READ(reg); |
| 1831 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1832 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1833 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1834 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1835 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1836 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1837 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1838 | |
| 1839 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1840 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1841 | * Make the BPC in transcoder be consistent with |
| 1842 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1843 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1844 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1845 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1846 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
| 1847 | val |= PIPECONF_8BPC; |
| 1848 | else |
| 1849 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1850 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1851 | |
| 1852 | val &= ~TRANS_INTERLACE_MASK; |
| 1853 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1854 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1855 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1856 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1857 | else |
| 1858 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1859 | else |
| 1860 | val |= TRANS_PROGRESSIVE; |
| 1861 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1862 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1863 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1864 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1867 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1868 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1869 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1870 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1871 | |
| 1872 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1873 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1874 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1875 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1876 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1877 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1878 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1879 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1880 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1881 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1882 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1883 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1884 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1885 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1886 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1887 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1888 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1889 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1890 | else |
| 1891 | val |= TRANS_PROGRESSIVE; |
| 1892 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1893 | I915_WRITE(LPT_TRANSCONF, val); |
| 1894 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1895 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1896 | } |
| 1897 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1898 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1899 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1900 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1901 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1902 | i915_reg_t reg; |
| 1903 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1904 | |
| 1905 | /* FDI relies on the transcoder */ |
| 1906 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1907 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1908 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1909 | /* Ports must be off as well */ |
| 1910 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1911 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1912 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1913 | val = I915_READ(reg); |
| 1914 | val &= ~TRANS_ENABLE; |
| 1915 | I915_WRITE(reg, val); |
| 1916 | /* wait for PCH transcoder off, transcoder state */ |
| 1917 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1918 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1919 | |
Ville Syrjälä | c465613 | 2015-10-29 21:25:56 +0200 | [diff] [blame] | 1920 | if (HAS_PCH_CPT(dev)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1921 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1922 | reg = TRANS_CHICKEN2(pipe); |
| 1923 | val = I915_READ(reg); |
| 1924 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1925 | I915_WRITE(reg, val); |
| 1926 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1929 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1930 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1931 | u32 val; |
| 1932 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1933 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1934 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1935 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1936 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1937 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1938 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1939 | |
| 1940 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1941 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1942 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1943 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1947 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1948 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1949 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1950 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1951 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1952 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1953 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1954 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1955 | struct drm_device *dev = crtc->base.dev; |
| 1956 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1957 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 1a70a728 | 2015-10-29 21:25:50 +0200 | [diff] [blame] | 1958 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1959 | enum pipe pch_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1960 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1961 | u32 val; |
| 1962 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1963 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1964 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1965 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1966 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1967 | assert_sprites_disabled(dev_priv, pipe); |
| 1968 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 1969 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1970 | pch_transcoder = TRANSCODER_A; |
| 1971 | else |
| 1972 | pch_transcoder = pipe; |
| 1973 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1974 | /* |
| 1975 | * A pipe without a PLL won't actually be able to drive bits from |
| 1976 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1977 | * need the check. |
| 1978 | */ |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 1979 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 1980 | if (crtc->config->has_dsi_encoder) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1981 | assert_dsi_pll_enabled(dev_priv); |
| 1982 | else |
| 1983 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1984 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1985 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1986 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1987 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1988 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1989 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1990 | } |
| 1991 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1992 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1993 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1994 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1995 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1996 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1997 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1998 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1999 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2000 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2001 | |
| 2002 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2003 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 2004 | |
| 2005 | /* |
| 2006 | * Until the pipe starts DSL will read as 0, which would cause |
| 2007 | * an apparent vblank timestamp jump, which messes up also the |
| 2008 | * frame count when it's derived from the timestamps. So let's |
| 2009 | * wait for the pipe to start properly before we call |
| 2010 | * drm_crtc_vblank_on() |
| 2011 | */ |
| 2012 | if (dev->max_vblank_count == 0 && |
| 2013 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) |
| 2014 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2018 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2019 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2020 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2021 | * Disable the pipe of @crtc, making sure that various hardware |
| 2022 | * specific requirements are met, if applicable, e.g. plane |
| 2023 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2024 | * |
| 2025 | * Will wait until the pipe has shut down before returning. |
| 2026 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2027 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2028 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2029 | 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] | 2030 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2031 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2032 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2033 | u32 val; |
| 2034 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2035 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 2036 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2037 | /* |
| 2038 | * Make sure planes won't keep trying to pump pixels to us, |
| 2039 | * or we might hang the display. |
| 2040 | */ |
| 2041 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2042 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2043 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2044 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2045 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2046 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2047 | if ((val & PIPECONF_ENABLE) == 0) |
| 2048 | return; |
| 2049 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2050 | /* |
| 2051 | * Double wide has implications for planes |
| 2052 | * so best keep it disabled when not needed. |
| 2053 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2054 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2055 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2056 | |
| 2057 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2058 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2059 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2060 | val &= ~PIPECONF_ENABLE; |
| 2061 | |
| 2062 | I915_WRITE(reg, val); |
| 2063 | if ((val & PIPECONF_ENABLE) == 0) |
| 2064 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2065 | } |
| 2066 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2067 | static bool need_vtd_wa(struct drm_device *dev) |
| 2068 | { |
| 2069 | #ifdef CONFIG_INTEL_IOMMU |
| 2070 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2071 | return true; |
| 2072 | #endif |
| 2073 | return false; |
| 2074 | } |
| 2075 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2076 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 2077 | { |
| 2078 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 2079 | } |
| 2080 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2081 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
| 2082 | uint64_t fb_modifier, unsigned int cpp) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2083 | { |
| 2084 | switch (fb_modifier) { |
| 2085 | case DRM_FORMAT_MOD_NONE: |
| 2086 | return cpp; |
| 2087 | case I915_FORMAT_MOD_X_TILED: |
| 2088 | if (IS_GEN2(dev_priv)) |
| 2089 | return 128; |
| 2090 | else |
| 2091 | return 512; |
| 2092 | case I915_FORMAT_MOD_Y_TILED: |
| 2093 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 2094 | return 128; |
| 2095 | else |
| 2096 | return 512; |
| 2097 | case I915_FORMAT_MOD_Yf_TILED: |
| 2098 | switch (cpp) { |
| 2099 | case 1: |
| 2100 | return 64; |
| 2101 | case 2: |
| 2102 | case 4: |
| 2103 | return 128; |
| 2104 | case 8: |
| 2105 | case 16: |
| 2106 | return 256; |
| 2107 | default: |
| 2108 | MISSING_CASE(cpp); |
| 2109 | return cpp; |
| 2110 | } |
| 2111 | break; |
| 2112 | default: |
| 2113 | MISSING_CASE(fb_modifier); |
| 2114 | return cpp; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2118 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
| 2119 | uint64_t fb_modifier, unsigned int cpp) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2120 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2121 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
| 2122 | return 1; |
| 2123 | else |
| 2124 | return intel_tile_size(dev_priv) / |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2125 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2128 | /* Return the tile dimensions in pixel units */ |
| 2129 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, |
| 2130 | unsigned int *tile_width, |
| 2131 | unsigned int *tile_height, |
| 2132 | uint64_t fb_modifier, |
| 2133 | unsigned int cpp) |
| 2134 | { |
| 2135 | unsigned int tile_width_bytes = |
| 2136 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
| 2137 | |
| 2138 | *tile_width = tile_width_bytes / cpp; |
| 2139 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; |
| 2140 | } |
| 2141 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2142 | unsigned int |
| 2143 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2144 | uint32_t pixel_format, uint64_t fb_modifier) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2145 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2146 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 2147 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); |
| 2148 | |
| 2149 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2150 | } |
| 2151 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2152 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 2153 | { |
| 2154 | unsigned int size = 0; |
| 2155 | int i; |
| 2156 | |
| 2157 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 2158 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2159 | |
| 2160 | return size; |
| 2161 | } |
| 2162 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 2163 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2164 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 2165 | const struct drm_framebuffer *fb, |
| 2166 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2167 | { |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2168 | if (intel_rotation_90_or_270(rotation)) { |
| 2169 | *view = i915_ggtt_view_rotated; |
| 2170 | view->params.rotated = to_intel_framebuffer(fb)->rot_info; |
| 2171 | } else { |
| 2172 | *view = i915_ggtt_view_normal; |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | static void |
| 2177 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2178 | struct drm_framebuffer *fb) |
| 2179 | { |
| 2180 | struct intel_rotation_info *info = &to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2181 | unsigned int tile_size, tile_width, tile_height, cpp; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2182 | |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2183 | tile_size = intel_tile_size(dev_priv); |
| 2184 | |
| 2185 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2186 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2187 | fb->modifier[0], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2188 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2189 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); |
| 2190 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 2191 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2192 | if (info->pixel_format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2193 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2194 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2195 | fb->modifier[1], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2196 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2197 | info->uv_offset = fb->offsets[1]; |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2198 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); |
| 2199 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2200 | } |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2203 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2204 | { |
| 2205 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2206 | return 256 * 1024; |
Ville Syrjälä | 985b8bb | 2015-06-11 16:31:15 +0300 | [diff] [blame] | 2207 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2208 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2209 | return 128 * 1024; |
| 2210 | else if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2211 | return 4 * 1024; |
| 2212 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2213 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2214 | } |
| 2215 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2216 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
| 2217 | uint64_t fb_modifier) |
| 2218 | { |
| 2219 | switch (fb_modifier) { |
| 2220 | case DRM_FORMAT_MOD_NONE: |
| 2221 | return intel_linear_alignment(dev_priv); |
| 2222 | case I915_FORMAT_MOD_X_TILED: |
| 2223 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2224 | return 256 * 1024; |
| 2225 | return 0; |
| 2226 | case I915_FORMAT_MOD_Y_TILED: |
| 2227 | case I915_FORMAT_MOD_Yf_TILED: |
| 2228 | return 1 * 1024 * 1024; |
| 2229 | default: |
| 2230 | MISSING_CASE(fb_modifier); |
| 2231 | return 0; |
| 2232 | } |
| 2233 | } |
| 2234 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2235 | int |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2236 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
| 2237 | unsigned int rotation) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2238 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2239 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2240 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2241 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2242 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2243 | u32 alignment; |
| 2244 | int ret; |
| 2245 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2246 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2247 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2248 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2249 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2250 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2251 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2252 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2253 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2254 | * we should always have valid PTE following the scanout preventing |
| 2255 | * the VT-d warning. |
| 2256 | */ |
| 2257 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2258 | alignment = 256 * 1024; |
| 2259 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2260 | /* |
| 2261 | * Global gtt pte registers are special registers which actually forward |
| 2262 | * writes to a chunk of system memory. Which means that there is no risk |
| 2263 | * that the register values disappear as soon as we call |
| 2264 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2265 | * pin/unpin/fence and not more. |
| 2266 | */ |
| 2267 | intel_runtime_pm_get(dev_priv); |
| 2268 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 2269 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
| 2270 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2271 | if (ret) |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2272 | goto err_pm; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2273 | |
| 2274 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2275 | * fence, whereas 965+ only requires a fence if using |
| 2276 | * framebuffer compression. For simplicity, we always install |
| 2277 | * a fence as the cost is not that onerous. |
| 2278 | */ |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2279 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
| 2280 | ret = i915_gem_object_get_fence(obj); |
| 2281 | if (ret == -EDEADLK) { |
| 2282 | /* |
| 2283 | * -EDEADLK means there are no free fences |
| 2284 | * no pending flips. |
| 2285 | * |
| 2286 | * This is propagated to atomic, but it uses |
| 2287 | * -EDEADLK to force a locking recovery, so |
| 2288 | * change the returned error to -EBUSY. |
| 2289 | */ |
| 2290 | ret = -EBUSY; |
| 2291 | goto err_unpin; |
| 2292 | } else if (ret) |
| 2293 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2294 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2295 | i915_gem_object_pin_fence(obj); |
| 2296 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2297 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2298 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2299 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2300 | |
| 2301 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2302 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2303 | err_pm: |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2304 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2305 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2306 | } |
| 2307 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2308 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2309 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2310 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2311 | struct i915_ggtt_view view; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2312 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2313 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2314 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2315 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2316 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2317 | if (view.type == I915_GGTT_VIEW_NORMAL) |
| 2318 | i915_gem_object_unpin_fence(obj); |
| 2319 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2320 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2321 | } |
| 2322 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2323 | /* |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2324 | * Adjust the tile offset by moving the difference into |
| 2325 | * the x/y offsets. |
| 2326 | * |
| 2327 | * Input tile dimensions and pitch must already be |
| 2328 | * rotated to match x and y, and in pixel units. |
| 2329 | */ |
| 2330 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2331 | unsigned int tile_width, |
| 2332 | unsigned int tile_height, |
| 2333 | unsigned int tile_size, |
| 2334 | unsigned int pitch_tiles, |
| 2335 | u32 old_offset, |
| 2336 | u32 new_offset) |
| 2337 | { |
| 2338 | unsigned int tiles; |
| 2339 | |
| 2340 | WARN_ON(old_offset & (tile_size - 1)); |
| 2341 | WARN_ON(new_offset & (tile_size - 1)); |
| 2342 | WARN_ON(new_offset > old_offset); |
| 2343 | |
| 2344 | tiles = (old_offset - new_offset) / tile_size; |
| 2345 | |
| 2346 | *y += tiles / pitch_tiles * tile_height; |
| 2347 | *x += tiles % pitch_tiles * tile_width; |
| 2348 | |
| 2349 | return new_offset; |
| 2350 | } |
| 2351 | |
| 2352 | /* |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2353 | * Computes the linear offset to the base tile and adjusts |
| 2354 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2355 | * |
| 2356 | * In the 90/270 rotated case, x and y are assumed |
| 2357 | * to be already rotated to match the rotated GTT view, and |
| 2358 | * pitch is the tile_height aligned framebuffer height. |
| 2359 | */ |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2360 | u32 intel_compute_tile_offset(int *x, int *y, |
| 2361 | const struct drm_framebuffer *fb, int plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2362 | unsigned int pitch, |
| 2363 | unsigned int rotation) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2364 | { |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2365 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2366 | uint64_t fb_modifier = fb->modifier[plane]; |
| 2367 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2368 | u32 offset, offset_aligned, alignment; |
| 2369 | |
| 2370 | alignment = intel_surf_alignment(dev_priv, fb_modifier); |
| 2371 | if (alignment) |
| 2372 | alignment--; |
| 2373 | |
Ville Syrjälä | b5c6533 | 2016-01-12 21:08:31 +0200 | [diff] [blame] | 2374 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2375 | unsigned int tile_size, tile_width, tile_height; |
| 2376 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2377 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2378 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2379 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2380 | fb_modifier, cpp); |
| 2381 | |
| 2382 | if (intel_rotation_90_or_270(rotation)) { |
| 2383 | pitch_tiles = pitch / tile_height; |
| 2384 | swap(tile_width, tile_height); |
| 2385 | } else { |
| 2386 | pitch_tiles = pitch / (tile_width * cpp); |
| 2387 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2388 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2389 | tile_rows = *y / tile_height; |
| 2390 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2391 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2392 | tiles = *x / tile_width; |
| 2393 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2394 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2395 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2396 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2397 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2398 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2399 | tile_size, pitch_tiles, |
| 2400 | offset, offset_aligned); |
| 2401 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2402 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2403 | offset_aligned = offset & ~alignment; |
| 2404 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2405 | *y = (offset & alignment) / pitch; |
| 2406 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2407 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2408 | |
| 2409 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2410 | } |
| 2411 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2412 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2413 | { |
| 2414 | switch (format) { |
| 2415 | case DISPPLANE_8BPP: |
| 2416 | return DRM_FORMAT_C8; |
| 2417 | case DISPPLANE_BGRX555: |
| 2418 | return DRM_FORMAT_XRGB1555; |
| 2419 | case DISPPLANE_BGRX565: |
| 2420 | return DRM_FORMAT_RGB565; |
| 2421 | default: |
| 2422 | case DISPPLANE_BGRX888: |
| 2423 | return DRM_FORMAT_XRGB8888; |
| 2424 | case DISPPLANE_RGBX888: |
| 2425 | return DRM_FORMAT_XBGR8888; |
| 2426 | case DISPPLANE_BGRX101010: |
| 2427 | return DRM_FORMAT_XRGB2101010; |
| 2428 | case DISPPLANE_RGBX101010: |
| 2429 | return DRM_FORMAT_XBGR2101010; |
| 2430 | } |
| 2431 | } |
| 2432 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2433 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2434 | { |
| 2435 | switch (format) { |
| 2436 | case PLANE_CTL_FORMAT_RGB_565: |
| 2437 | return DRM_FORMAT_RGB565; |
| 2438 | default: |
| 2439 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2440 | if (rgb_order) { |
| 2441 | if (alpha) |
| 2442 | return DRM_FORMAT_ABGR8888; |
| 2443 | else |
| 2444 | return DRM_FORMAT_XBGR8888; |
| 2445 | } else { |
| 2446 | if (alpha) |
| 2447 | return DRM_FORMAT_ARGB8888; |
| 2448 | else |
| 2449 | return DRM_FORMAT_XRGB8888; |
| 2450 | } |
| 2451 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2452 | if (rgb_order) |
| 2453 | return DRM_FORMAT_XBGR2101010; |
| 2454 | else |
| 2455 | return DRM_FORMAT_XRGB2101010; |
| 2456 | } |
| 2457 | } |
| 2458 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2459 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2460 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2461 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2462 | { |
| 2463 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2464 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2465 | struct drm_i915_gem_object *obj = NULL; |
| 2466 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2467 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2468 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2469 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2470 | PAGE_SIZE); |
| 2471 | |
| 2472 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2473 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2474 | if (plane_config->size == 0) |
| 2475 | return false; |
| 2476 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2477 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2478 | * important and we should probably use that space with FBC or other |
| 2479 | * features. */ |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 2480 | if (size_aligned * 2 > dev_priv->ggtt.stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2481 | return false; |
| 2482 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2483 | mutex_lock(&dev->struct_mutex); |
| 2484 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2485 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2486 | base_aligned, |
| 2487 | base_aligned, |
| 2488 | size_aligned); |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2489 | if (!obj) { |
| 2490 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2491 | return false; |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2492 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2493 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2494 | obj->tiling_mode = plane_config->tiling; |
| 2495 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2496 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2497 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2498 | mode_cmd.pixel_format = fb->pixel_format; |
| 2499 | mode_cmd.width = fb->width; |
| 2500 | mode_cmd.height = fb->height; |
| 2501 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2502 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2503 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2504 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2505 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2506 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2507 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2508 | goto out_unref_obj; |
| 2509 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2510 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2511 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2512 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2513 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2514 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2515 | |
| 2516 | out_unref_obj: |
| 2517 | drm_gem_object_unreference(&obj->base); |
| 2518 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2519 | return false; |
| 2520 | } |
| 2521 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2522 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2523 | static void |
| 2524 | update_state_fb(struct drm_plane *plane) |
| 2525 | { |
| 2526 | if (plane->fb == plane->state->fb) |
| 2527 | return; |
| 2528 | |
| 2529 | if (plane->state->fb) |
| 2530 | drm_framebuffer_unreference(plane->state->fb); |
| 2531 | plane->state->fb = plane->fb; |
| 2532 | if (plane->state->fb) |
| 2533 | drm_framebuffer_reference(plane->state->fb); |
| 2534 | } |
| 2535 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2536 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2537 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2538 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2539 | { |
| 2540 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2541 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2542 | struct drm_crtc *c; |
| 2543 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2544 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2545 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2546 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2547 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
| 2548 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2549 | struct intel_plane_state *intel_state = |
| 2550 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2551 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2552 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2553 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2554 | return; |
| 2555 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2556 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2557 | fb = &plane_config->fb->base; |
| 2558 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2559 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2560 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2561 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2562 | |
| 2563 | /* |
| 2564 | * Failed to alloc the obj, check to see if we should share |
| 2565 | * an fb with another CRTC instead |
| 2566 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2567 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2568 | i = to_intel_crtc(c); |
| 2569 | |
| 2570 | if (c == &intel_crtc->base) |
| 2571 | continue; |
| 2572 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2573 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2574 | continue; |
| 2575 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2576 | fb = c->primary->fb; |
| 2577 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2578 | continue; |
| 2579 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2580 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2581 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2582 | drm_framebuffer_reference(fb); |
| 2583 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2584 | } |
| 2585 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2586 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2587 | /* |
| 2588 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2589 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2590 | * which will lead to problems later if we don't fix it up. The |
| 2591 | * simplest solution is to just disable the primary plane now and |
| 2592 | * pretend the BIOS never had it enabled. |
| 2593 | */ |
| 2594 | to_intel_plane_state(plane_state)->visible = false; |
| 2595 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 2596 | intel_pre_disable_primary_noatomic(&intel_crtc->base); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2597 | intel_plane->disable_plane(primary, &intel_crtc->base); |
| 2598 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2599 | return; |
| 2600 | |
| 2601 | valid_fb: |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2602 | plane_state->src_x = 0; |
| 2603 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2604 | plane_state->src_w = fb->width << 16; |
| 2605 | plane_state->src_h = fb->height << 16; |
| 2606 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2607 | plane_state->crtc_x = 0; |
| 2608 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2609 | plane_state->crtc_w = fb->width; |
| 2610 | plane_state->crtc_h = fb->height; |
| 2611 | |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2612 | intel_state->src.x1 = plane_state->src_x; |
| 2613 | intel_state->src.y1 = plane_state->src_y; |
| 2614 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; |
| 2615 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; |
| 2616 | intel_state->dst.x1 = plane_state->crtc_x; |
| 2617 | intel_state->dst.y1 = plane_state->crtc_y; |
| 2618 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; |
| 2619 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; |
| 2620 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2621 | obj = intel_fb_obj(fb); |
| 2622 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2623 | dev_priv->preserve_bios_swizzle = true; |
| 2624 | |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2625 | drm_framebuffer_reference(fb); |
| 2626 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2627 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2628 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 2629 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2630 | } |
| 2631 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2632 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
| 2633 | const struct intel_crtc_state *crtc_state, |
| 2634 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2635 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2636 | struct drm_device *dev = primary->dev; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2637 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2638 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2639 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2640 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2641 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2642 | u32 linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2643 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2644 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2645 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2646 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2647 | int x = plane_state->src.x1 >> 16; |
| 2648 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2649 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2650 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2651 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2652 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2653 | |
| 2654 | if (INTEL_INFO(dev)->gen < 4) { |
| 2655 | if (intel_crtc->pipe == PIPE_B) |
| 2656 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2657 | |
| 2658 | /* pipesrc and dspsize control the size that is scaled from, |
| 2659 | * which should always be the user's requested size. |
| 2660 | */ |
| 2661 | I915_WRITE(DSPSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2662 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2663 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2664 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2665 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2666 | I915_WRITE(PRIMSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2667 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2668 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2669 | I915_WRITE(PRIMPOS(plane), 0); |
| 2670 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2671 | } |
| 2672 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2673 | switch (fb->pixel_format) { |
| 2674 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2675 | dspcntr |= DISPPLANE_8BPP; |
| 2676 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2677 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2678 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2679 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2680 | case DRM_FORMAT_RGB565: |
| 2681 | dspcntr |= DISPPLANE_BGRX565; |
| 2682 | break; |
| 2683 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2684 | dspcntr |= DISPPLANE_BGRX888; |
| 2685 | break; |
| 2686 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2687 | dspcntr |= DISPPLANE_RGBX888; |
| 2688 | break; |
| 2689 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2690 | dspcntr |= DISPPLANE_BGRX101010; |
| 2691 | break; |
| 2692 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2693 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2694 | break; |
| 2695 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2696 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2697 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2698 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2699 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2700 | obj->tiling_mode != I915_TILING_NONE) |
| 2701 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2702 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2703 | if (IS_G4X(dev)) |
| 2704 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2705 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2706 | linear_offset = y * fb->pitches[0] + x * cpp; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2707 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2708 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2709 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2710 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2711 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2712 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2713 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2714 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2715 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2716 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2717 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2718 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2719 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2720 | x += (crtc_state->pipe_src_w - 1); |
| 2721 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2722 | |
| 2723 | /* Finding the last pixel of the last line of the display |
| 2724 | data and adding to linear_offset*/ |
| 2725 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2726 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2727 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2728 | } |
| 2729 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2730 | intel_crtc->adjusted_x = x; |
| 2731 | intel_crtc->adjusted_y = y; |
| 2732 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2733 | I915_WRITE(reg, dspcntr); |
| 2734 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2735 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2736 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2737 | I915_WRITE(DSPSURF(plane), |
| 2738 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2739 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2740 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2741 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2742 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2743 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2746 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
| 2747 | struct drm_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2748 | { |
| 2749 | struct drm_device *dev = crtc->dev; |
| 2750 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2751 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2752 | int plane = intel_crtc->plane; |
| 2753 | |
| 2754 | I915_WRITE(DSPCNTR(plane), 0); |
| 2755 | if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2756 | I915_WRITE(DSPSURF(plane), 0); |
| 2757 | else |
| 2758 | I915_WRITE(DSPADDR(plane), 0); |
| 2759 | POSTING_READ(DSPCNTR(plane)); |
| 2760 | } |
| 2761 | |
| 2762 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
| 2763 | const struct intel_crtc_state *crtc_state, |
| 2764 | const struct intel_plane_state *plane_state) |
| 2765 | { |
| 2766 | struct drm_device *dev = primary->dev; |
| 2767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2768 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2769 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2770 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2771 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2772 | u32 linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2773 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2774 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2775 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2776 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2777 | int x = plane_state->src.x1 >> 16; |
| 2778 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2779 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2780 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2781 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2782 | |
| 2783 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2784 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2785 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2786 | switch (fb->pixel_format) { |
| 2787 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2788 | dspcntr |= DISPPLANE_8BPP; |
| 2789 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2790 | case DRM_FORMAT_RGB565: |
| 2791 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2792 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2793 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2794 | dspcntr |= DISPPLANE_BGRX888; |
| 2795 | break; |
| 2796 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2797 | dspcntr |= DISPPLANE_RGBX888; |
| 2798 | break; |
| 2799 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2800 | dspcntr |= DISPPLANE_BGRX101010; |
| 2801 | break; |
| 2802 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2803 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2804 | break; |
| 2805 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2806 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2810 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2811 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2812 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2813 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2814 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2815 | linear_offset = y * fb->pitches[0] + x * cpp; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2816 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2817 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2818 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2819 | linear_offset -= intel_crtc->dspaddr_offset; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2820 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2821 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2822 | |
| 2823 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2824 | x += (crtc_state->pipe_src_w - 1); |
| 2825 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2826 | |
| 2827 | /* Finding the last pixel of the last line of the display |
| 2828 | data and adding to linear_offset*/ |
| 2829 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2830 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2831 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2832 | } |
| 2833 | } |
| 2834 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2835 | intel_crtc->adjusted_x = x; |
| 2836 | intel_crtc->adjusted_y = y; |
| 2837 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2838 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2839 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2840 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2841 | I915_WRITE(DSPSURF(plane), |
| 2842 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2843 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2844 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2845 | } else { |
| 2846 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2847 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2848 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2849 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2852 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
| 2853 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2854 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2855 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
| 2856 | return 64; |
| 2857 | } else { |
| 2858 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2859 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2860 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2864 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2865 | struct drm_i915_gem_object *obj, |
| 2866 | unsigned int plane) |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2867 | { |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2868 | struct i915_ggtt_view view; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2869 | struct i915_vma *vma; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2870 | u64 offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2871 | |
Ville Syrjälä | e794129 | 2016-01-19 18:23:17 +0200 | [diff] [blame] | 2872 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2873 | intel_plane->base.state->rotation); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2874 | |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2875 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2876 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2877 | view.type)) |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2878 | return -1; |
| 2879 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2880 | offset = vma->node.start; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2881 | |
| 2882 | if (plane == 1) { |
Ville Syrjälä | 7723f47d | 2016-01-20 21:05:22 +0200 | [diff] [blame] | 2883 | offset += vma->ggtt_view.params.rotated.uv_start_page * |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2884 | PAGE_SIZE; |
| 2885 | } |
| 2886 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2887 | WARN_ON(upper_32_bits(offset)); |
| 2888 | |
| 2889 | return lower_32_bits(offset); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2892 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 2893 | { |
| 2894 | struct drm_device *dev = intel_crtc->base.dev; |
| 2895 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2896 | |
| 2897 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 2898 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 2899 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2900 | } |
| 2901 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2902 | /* |
| 2903 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 2904 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 2905 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2906 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2907 | struct intel_crtc_scaler_state *scaler_state; |
| 2908 | int i; |
| 2909 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2910 | scaler_state = &intel_crtc->config->scaler_state; |
| 2911 | |
| 2912 | /* loop through and disable scalers that aren't in use */ |
| 2913 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2914 | if (!scaler_state->scalers[i].in_use) |
| 2915 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2919 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 2920 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2921 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 2922 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2923 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2924 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2925 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2926 | case DRM_FORMAT_XBGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2927 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2928 | case DRM_FORMAT_XRGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2929 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2930 | /* |
| 2931 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 2932 | * to be already pre-multiplied. We need to add a knob (or a different |
| 2933 | * DRM_FORMAT) for user-space to configure that. |
| 2934 | */ |
| 2935 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2936 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2937 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2938 | case DRM_FORMAT_ARGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2939 | return PLANE_CTL_FORMAT_XRGB_8888 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2940 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2941 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2942 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2943 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2944 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2945 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2946 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2947 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2948 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2949 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2950 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2951 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2952 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2953 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 2954 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2955 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 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 | |
| 2960 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 2961 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2962 | switch (fb_modifier) { |
| 2963 | case DRM_FORMAT_MOD_NONE: |
| 2964 | break; |
| 2965 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2966 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2967 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2968 | return PLANE_CTL_TILED_Y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2969 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2970 | return PLANE_CTL_TILED_YF; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2971 | default: |
| 2972 | MISSING_CASE(fb_modifier); |
| 2973 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2974 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2975 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 2979 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2980 | switch (rotation) { |
| 2981 | case BIT(DRM_ROTATE_0): |
| 2982 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2983 | /* |
| 2984 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 2985 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 2986 | */ |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2987 | case BIT(DRM_ROTATE_90): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2988 | return PLANE_CTL_ROTATE_270; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2989 | case BIT(DRM_ROTATE_180): |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2990 | return PLANE_CTL_ROTATE_180; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2991 | case BIT(DRM_ROTATE_270): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2992 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2993 | default: |
| 2994 | MISSING_CASE(rotation); |
| 2995 | } |
| 2996 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2997 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3000 | static void skylake_update_primary_plane(struct drm_plane *plane, |
| 3001 | const struct intel_crtc_state *crtc_state, |
| 3002 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3003 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3004 | struct drm_device *dev = plane->dev; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3005 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3006 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3007 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 3008 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3009 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3010 | u32 plane_ctl, stride_div, stride; |
| 3011 | u32 tile_height, plane_offset, plane_size; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3012 | unsigned int rotation = plane_state->base.rotation; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3013 | int x_offset, y_offset; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 3014 | u32 surf_addr; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3015 | int scaler_id = plane_state->scaler_id; |
| 3016 | int src_x = plane_state->src.x1 >> 16; |
| 3017 | int src_y = plane_state->src.y1 >> 16; |
| 3018 | int src_w = drm_rect_width(&plane_state->src) >> 16; |
| 3019 | int src_h = drm_rect_height(&plane_state->src) >> 16; |
| 3020 | int dst_x = plane_state->dst.x1; |
| 3021 | int dst_y = plane_state->dst.y1; |
| 3022 | int dst_w = drm_rect_width(&plane_state->dst); |
| 3023 | int dst_h = drm_rect_height(&plane_state->dst); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3024 | |
| 3025 | plane_ctl = PLANE_CTL_ENABLE | |
| 3026 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3027 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 3028 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3029 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
| 3030 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3031 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3032 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3033 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3034 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3035 | fb->pixel_format); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 3036 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3037 | |
Paulo Zanoni | a42e5a2 | 2015-09-30 17:05:43 -0300 | [diff] [blame] | 3038 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3039 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3040 | if (intel_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3041 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
| 3042 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3043 | /* stride = Surface height in tiles */ |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3044 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3045 | stride = DIV_ROUND_UP(fb->height, tile_height); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3046 | x_offset = stride * tile_height - src_y - src_h; |
| 3047 | y_offset = src_x; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3048 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3049 | } else { |
| 3050 | stride = fb->pitches[0] / stride_div; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3051 | x_offset = src_x; |
| 3052 | y_offset = src_y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3053 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3054 | } |
| 3055 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3056 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3057 | intel_crtc->adjusted_x = x_offset; |
| 3058 | intel_crtc->adjusted_y = y_offset; |
| 3059 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3060 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3061 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3062 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3063 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3064 | |
| 3065 | if (scaler_id >= 0) { |
| 3066 | uint32_t ps_ctrl = 0; |
| 3067 | |
| 3068 | WARN_ON(!dst_w || !dst_h); |
| 3069 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | |
| 3070 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3071 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3072 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3073 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3074 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
| 3075 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3076 | } else { |
| 3077 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); |
| 3078 | } |
| 3079 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3080 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3081 | |
| 3082 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3083 | } |
| 3084 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3085 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
| 3086 | struct drm_crtc *crtc) |
| 3087 | { |
| 3088 | struct drm_device *dev = crtc->dev; |
| 3089 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3090 | int pipe = to_intel_crtc(crtc)->pipe; |
| 3091 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3092 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 3093 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 3094 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3095 | } |
| 3096 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3097 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3098 | static int |
| 3099 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3100 | int x, int y, enum mode_set_atomic state) |
| 3101 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3102 | /* Support for kgdboc is disabled, this needs a major rework. */ |
| 3103 | DRM_ERROR("legacy panic handler not supported any more.\n"); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3104 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3105 | return -ENODEV; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3108 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3109 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3110 | struct drm_crtc *crtc; |
| 3111 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3112 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3113 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3114 | enum plane plane = intel_crtc->plane; |
| 3115 | |
| 3116 | intel_prepare_page_flip(dev, plane); |
| 3117 | intel_finish_page_flip_plane(dev, plane); |
| 3118 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3122 | { |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3123 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3124 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3125 | for_each_crtc(dev, crtc) { |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3126 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
| 3127 | struct intel_plane_state *plane_state; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3128 | |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3129 | drm_modeset_lock_crtc(crtc, &plane->base); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3130 | plane_state = to_intel_plane_state(plane->base.state); |
| 3131 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3132 | if (plane_state->visible) |
| 3133 | plane->update_plane(&plane->base, |
| 3134 | to_intel_crtc_state(crtc->state), |
| 3135 | plane_state); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3136 | |
| 3137 | drm_modeset_unlock_crtc(crtc); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3141 | void intel_prepare_reset(struct drm_device *dev) |
| 3142 | { |
| 3143 | /* no reset support for gen2 */ |
| 3144 | if (IS_GEN2(dev)) |
| 3145 | return; |
| 3146 | |
| 3147 | /* reset doesn't touch the display */ |
| 3148 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3149 | return; |
| 3150 | |
| 3151 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3152 | /* |
| 3153 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3154 | * g33 docs say we should at least disable all the planes. |
| 3155 | */ |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 3156 | intel_display_suspend(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | void intel_finish_reset(struct drm_device *dev) |
| 3160 | { |
| 3161 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3162 | |
| 3163 | /* |
| 3164 | * Flips in the rings will be nuked by the reset, |
| 3165 | * so complete all pending flips so that user space |
| 3166 | * will get its events and not get stuck. |
| 3167 | */ |
| 3168 | intel_complete_page_flips(dev); |
| 3169 | |
| 3170 | /* no reset support for gen2 */ |
| 3171 | if (IS_GEN2(dev)) |
| 3172 | return; |
| 3173 | |
| 3174 | /* reset doesn't touch the display */ |
| 3175 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3176 | /* |
| 3177 | * Flips in the rings have been nuked by the reset, |
| 3178 | * so update the base address of all primary |
| 3179 | * planes to the the last fb to make sure we're |
| 3180 | * showing the correct fb after a reset. |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3181 | * |
| 3182 | * FIXME: Atomic will make this obsolete since we won't schedule |
| 3183 | * CS-based flips (which might get lost in gpu resets) any more. |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3184 | */ |
| 3185 | intel_update_primary_planes(dev); |
| 3186 | return; |
| 3187 | } |
| 3188 | |
| 3189 | /* |
| 3190 | * The display has been reset as well, |
| 3191 | * so need a full re-initialization. |
| 3192 | */ |
| 3193 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3194 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3195 | |
| 3196 | intel_modeset_init_hw(dev); |
| 3197 | |
| 3198 | spin_lock_irq(&dev_priv->irq_lock); |
| 3199 | if (dev_priv->display.hpd_irq_setup) |
| 3200 | dev_priv->display.hpd_irq_setup(dev); |
| 3201 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3202 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 3203 | intel_display_resume(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3204 | |
| 3205 | intel_hpd_init(dev_priv); |
| 3206 | |
| 3207 | drm_modeset_unlock_all(dev); |
| 3208 | } |
| 3209 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3210 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3211 | { |
| 3212 | struct drm_device *dev = crtc->dev; |
| 3213 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3214 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3215 | bool pending; |
| 3216 | |
| 3217 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3218 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3219 | return false; |
| 3220 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3221 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3222 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3223 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3224 | |
| 3225 | return pending; |
| 3226 | } |
| 3227 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3228 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
| 3229 | struct intel_crtc_state *old_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3230 | { |
| 3231 | struct drm_device *dev = crtc->base.dev; |
| 3232 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3233 | struct intel_crtc_state *pipe_config = |
| 3234 | to_intel_crtc_state(crtc->base.state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3235 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3236 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
| 3237 | crtc->base.mode = crtc->base.state->mode; |
| 3238 | |
| 3239 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", |
| 3240 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, |
| 3241 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3242 | |
Maarten Lankhorst | 44522d8 | 2015-08-27 15:44:02 +0200 | [diff] [blame] | 3243 | if (HAS_DDI(dev)) |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 3244 | intel_color_set_csc(&crtc->base); |
Maarten Lankhorst | 44522d8 | 2015-08-27 15:44:02 +0200 | [diff] [blame] | 3245 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3246 | /* |
| 3247 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3248 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3249 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3250 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3251 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3252 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3253 | */ |
| 3254 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3255 | I915_WRITE(PIPESRC(crtc->pipe), |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3256 | ((pipe_config->pipe_src_w - 1) << 16) | |
| 3257 | (pipe_config->pipe_src_h - 1)); |
| 3258 | |
| 3259 | /* on skylake this is done by detaching scalers */ |
| 3260 | if (INTEL_INFO(dev)->gen >= 9) { |
| 3261 | skl_detach_scalers(crtc); |
| 3262 | |
| 3263 | if (pipe_config->pch_pfit.enabled) |
| 3264 | skylake_pfit_enable(crtc); |
| 3265 | } else if (HAS_PCH_SPLIT(dev)) { |
| 3266 | if (pipe_config->pch_pfit.enabled) |
| 3267 | ironlake_pfit_enable(crtc); |
| 3268 | else if (old_crtc_state->pch_pfit.enabled) |
| 3269 | ironlake_pfit_disable(crtc, true); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3270 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3271 | } |
| 3272 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3273 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3274 | { |
| 3275 | struct drm_device *dev = crtc->dev; |
| 3276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3277 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3278 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3279 | i915_reg_t reg; |
| 3280 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3281 | |
| 3282 | /* enable normal train */ |
| 3283 | reg = FDI_TX_CTL(pipe); |
| 3284 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3285 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3286 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3287 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3288 | } else { |
| 3289 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3290 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3291 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3292 | I915_WRITE(reg, temp); |
| 3293 | |
| 3294 | reg = FDI_RX_CTL(pipe); |
| 3295 | temp = I915_READ(reg); |
| 3296 | if (HAS_PCH_CPT(dev)) { |
| 3297 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3298 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3299 | } else { |
| 3300 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3301 | temp |= FDI_LINK_TRAIN_NONE; |
| 3302 | } |
| 3303 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3304 | |
| 3305 | /* wait one idle pattern time */ |
| 3306 | POSTING_READ(reg); |
| 3307 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3308 | |
| 3309 | /* IVB wants error correction enabled */ |
| 3310 | if (IS_IVYBRIDGE(dev)) |
| 3311 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3312 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3313 | } |
| 3314 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3315 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3316 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3317 | { |
| 3318 | struct drm_device *dev = crtc->dev; |
| 3319 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3320 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3321 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3322 | i915_reg_t reg; |
| 3323 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3324 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3325 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3326 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3327 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3328 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3329 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3330 | reg = FDI_RX_IMR(pipe); |
| 3331 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3332 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3333 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3334 | I915_WRITE(reg, temp); |
| 3335 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3336 | udelay(150); |
| 3337 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3338 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3339 | reg = FDI_TX_CTL(pipe); |
| 3340 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3341 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3342 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3343 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3344 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3345 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3346 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3347 | reg = FDI_RX_CTL(pipe); |
| 3348 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3349 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3350 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3351 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3352 | |
| 3353 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3354 | udelay(150); |
| 3355 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3356 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3357 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3358 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3359 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3360 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3361 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3362 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3363 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3364 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3365 | |
| 3366 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3367 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3368 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3369 | break; |
| 3370 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3371 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3372 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3373 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3374 | |
| 3375 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3376 | reg = FDI_TX_CTL(pipe); |
| 3377 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3378 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3379 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3380 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3381 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3382 | reg = FDI_RX_CTL(pipe); |
| 3383 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3384 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3385 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3386 | I915_WRITE(reg, temp); |
| 3387 | |
| 3388 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3389 | udelay(150); |
| 3390 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3391 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3392 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3393 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3394 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3395 | |
| 3396 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3397 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3398 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3399 | break; |
| 3400 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3401 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3402 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3403 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3404 | |
| 3405 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3406 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3407 | } |
| 3408 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3409 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3410 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3411 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3412 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3413 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3414 | }; |
| 3415 | |
| 3416 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3417 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3418 | { |
| 3419 | struct drm_device *dev = crtc->dev; |
| 3420 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3422 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3423 | i915_reg_t reg; |
| 3424 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3425 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3426 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3427 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3428 | reg = FDI_RX_IMR(pipe); |
| 3429 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3430 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3431 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3432 | I915_WRITE(reg, temp); |
| 3433 | |
| 3434 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3435 | udelay(150); |
| 3436 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3437 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3438 | reg = FDI_TX_CTL(pipe); |
| 3439 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3440 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3441 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3442 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3443 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3444 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3445 | /* SNB-B */ |
| 3446 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3447 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3448 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3449 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3450 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3451 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3452 | reg = FDI_RX_CTL(pipe); |
| 3453 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3454 | if (HAS_PCH_CPT(dev)) { |
| 3455 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3456 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3457 | } else { |
| 3458 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3459 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3460 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3461 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3462 | |
| 3463 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3464 | udelay(150); |
| 3465 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3466 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3467 | reg = FDI_TX_CTL(pipe); |
| 3468 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3469 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3470 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3471 | I915_WRITE(reg, temp); |
| 3472 | |
| 3473 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3474 | udelay(500); |
| 3475 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3476 | for (retry = 0; retry < 5; retry++) { |
| 3477 | reg = FDI_RX_IIR(pipe); |
| 3478 | temp = I915_READ(reg); |
| 3479 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3480 | if (temp & FDI_RX_BIT_LOCK) { |
| 3481 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3482 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3483 | break; |
| 3484 | } |
| 3485 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3486 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3487 | if (retry < 5) |
| 3488 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3489 | } |
| 3490 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3491 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3492 | |
| 3493 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3494 | reg = FDI_TX_CTL(pipe); |
| 3495 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3496 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3497 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3498 | if (IS_GEN6(dev)) { |
| 3499 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3500 | /* SNB-B */ |
| 3501 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3502 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3503 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3504 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3505 | reg = FDI_RX_CTL(pipe); |
| 3506 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3507 | if (HAS_PCH_CPT(dev)) { |
| 3508 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3509 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3510 | } else { |
| 3511 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3512 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3513 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3514 | I915_WRITE(reg, temp); |
| 3515 | |
| 3516 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3517 | udelay(150); |
| 3518 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3519 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3520 | reg = FDI_TX_CTL(pipe); |
| 3521 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3522 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3523 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3524 | I915_WRITE(reg, temp); |
| 3525 | |
| 3526 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3527 | udelay(500); |
| 3528 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3529 | for (retry = 0; retry < 5; retry++) { |
| 3530 | reg = FDI_RX_IIR(pipe); |
| 3531 | temp = I915_READ(reg); |
| 3532 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3533 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3534 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3535 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3536 | break; |
| 3537 | } |
| 3538 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3539 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3540 | if (retry < 5) |
| 3541 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3542 | } |
| 3543 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3544 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3545 | |
| 3546 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3547 | } |
| 3548 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3549 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3550 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3551 | { |
| 3552 | struct drm_device *dev = crtc->dev; |
| 3553 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3554 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3555 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3556 | i915_reg_t reg; |
| 3557 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3558 | |
| 3559 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3560 | for train result */ |
| 3561 | reg = FDI_RX_IMR(pipe); |
| 3562 | temp = I915_READ(reg); |
| 3563 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3564 | temp &= ~FDI_RX_BIT_LOCK; |
| 3565 | I915_WRITE(reg, temp); |
| 3566 | |
| 3567 | POSTING_READ(reg); |
| 3568 | udelay(150); |
| 3569 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3570 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3571 | I915_READ(FDI_RX_IIR(pipe))); |
| 3572 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3573 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3574 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3575 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3576 | reg = FDI_TX_CTL(pipe); |
| 3577 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3578 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3579 | temp &= ~FDI_TX_ENABLE; |
| 3580 | I915_WRITE(reg, temp); |
| 3581 | |
| 3582 | reg = FDI_RX_CTL(pipe); |
| 3583 | temp = I915_READ(reg); |
| 3584 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3585 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3586 | temp &= ~FDI_RX_ENABLE; |
| 3587 | I915_WRITE(reg, temp); |
| 3588 | |
| 3589 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3590 | reg = FDI_TX_CTL(pipe); |
| 3591 | temp = I915_READ(reg); |
| 3592 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3593 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3594 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3595 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3596 | temp |= snb_b_fdi_train_param[j/2]; |
| 3597 | temp |= FDI_COMPOSITE_SYNC; |
| 3598 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3599 | |
| 3600 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3601 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3602 | |
| 3603 | reg = FDI_RX_CTL(pipe); |
| 3604 | temp = I915_READ(reg); |
| 3605 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3606 | temp |= FDI_COMPOSITE_SYNC; |
| 3607 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3608 | |
| 3609 | POSTING_READ(reg); |
| 3610 | udelay(1); /* should be 0.5us */ |
| 3611 | |
| 3612 | for (i = 0; i < 4; i++) { |
| 3613 | reg = FDI_RX_IIR(pipe); |
| 3614 | temp = I915_READ(reg); |
| 3615 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3616 | |
| 3617 | if (temp & FDI_RX_BIT_LOCK || |
| 3618 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3619 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3620 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3621 | i); |
| 3622 | break; |
| 3623 | } |
| 3624 | udelay(1); /* should be 0.5us */ |
| 3625 | } |
| 3626 | if (i == 4) { |
| 3627 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3628 | continue; |
| 3629 | } |
| 3630 | |
| 3631 | /* Train 2 */ |
| 3632 | reg = FDI_TX_CTL(pipe); |
| 3633 | temp = I915_READ(reg); |
| 3634 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3635 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3636 | I915_WRITE(reg, temp); |
| 3637 | |
| 3638 | reg = FDI_RX_CTL(pipe); |
| 3639 | temp = I915_READ(reg); |
| 3640 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3641 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3642 | I915_WRITE(reg, temp); |
| 3643 | |
| 3644 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3645 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3646 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3647 | for (i = 0; i < 4; i++) { |
| 3648 | reg = FDI_RX_IIR(pipe); |
| 3649 | temp = I915_READ(reg); |
| 3650 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3651 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3652 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3653 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3654 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3655 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3656 | i); |
| 3657 | goto train_done; |
| 3658 | } |
| 3659 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3660 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3661 | if (i == 4) |
| 3662 | 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] | 3663 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3664 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3665 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3666 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3667 | } |
| 3668 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3669 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3670 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3671 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3672 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3673 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3674 | i915_reg_t reg; |
| 3675 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3676 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3677 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3678 | reg = FDI_RX_CTL(pipe); |
| 3679 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3680 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3681 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3682 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3683 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3684 | |
| 3685 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3686 | udelay(200); |
| 3687 | |
| 3688 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3689 | temp = I915_READ(reg); |
| 3690 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3691 | |
| 3692 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3693 | udelay(200); |
| 3694 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3695 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3696 | reg = FDI_TX_CTL(pipe); |
| 3697 | temp = I915_READ(reg); |
| 3698 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3699 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3700 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3701 | POSTING_READ(reg); |
| 3702 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3706 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3707 | { |
| 3708 | struct drm_device *dev = intel_crtc->base.dev; |
| 3709 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3710 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3711 | i915_reg_t reg; |
| 3712 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3713 | |
| 3714 | /* Switch from PCDclk to Rawclk */ |
| 3715 | reg = FDI_RX_CTL(pipe); |
| 3716 | temp = I915_READ(reg); |
| 3717 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3718 | |
| 3719 | /* Disable CPU FDI TX PLL */ |
| 3720 | reg = FDI_TX_CTL(pipe); |
| 3721 | temp = I915_READ(reg); |
| 3722 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3723 | |
| 3724 | POSTING_READ(reg); |
| 3725 | udelay(100); |
| 3726 | |
| 3727 | reg = FDI_RX_CTL(pipe); |
| 3728 | temp = I915_READ(reg); |
| 3729 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3730 | |
| 3731 | /* Wait for the clocks to turn off. */ |
| 3732 | POSTING_READ(reg); |
| 3733 | udelay(100); |
| 3734 | } |
| 3735 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3736 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3737 | { |
| 3738 | struct drm_device *dev = crtc->dev; |
| 3739 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3740 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3741 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3742 | i915_reg_t reg; |
| 3743 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3744 | |
| 3745 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3746 | reg = FDI_TX_CTL(pipe); |
| 3747 | temp = I915_READ(reg); |
| 3748 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3749 | POSTING_READ(reg); |
| 3750 | |
| 3751 | reg = FDI_RX_CTL(pipe); |
| 3752 | temp = I915_READ(reg); |
| 3753 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3754 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3755 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3756 | |
| 3757 | POSTING_READ(reg); |
| 3758 | udelay(100); |
| 3759 | |
| 3760 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3761 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3762 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3763 | |
| 3764 | /* still set train pattern 1 */ |
| 3765 | reg = FDI_TX_CTL(pipe); |
| 3766 | temp = I915_READ(reg); |
| 3767 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3768 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3769 | I915_WRITE(reg, temp); |
| 3770 | |
| 3771 | reg = FDI_RX_CTL(pipe); |
| 3772 | temp = I915_READ(reg); |
| 3773 | if (HAS_PCH_CPT(dev)) { |
| 3774 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3775 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3776 | } else { |
| 3777 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3778 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3779 | } |
| 3780 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3781 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3782 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3783 | I915_WRITE(reg, temp); |
| 3784 | |
| 3785 | POSTING_READ(reg); |
| 3786 | udelay(100); |
| 3787 | } |
| 3788 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3789 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3790 | { |
| 3791 | struct intel_crtc *crtc; |
| 3792 | |
| 3793 | /* Note that we don't need to be called with mode_config.lock here |
| 3794 | * as our list of CRTC objects is static for the lifetime of the |
| 3795 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3796 | * happily treat the predicates as racy, atomic checks as userspace |
| 3797 | * cannot claim and pin a new fb without at least acquring the |
| 3798 | * struct_mutex and so serialising with us. |
| 3799 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3800 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3801 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3802 | continue; |
| 3803 | |
| 3804 | if (crtc->unpin_work) |
| 3805 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3806 | |
| 3807 | return true; |
| 3808 | } |
| 3809 | |
| 3810 | return false; |
| 3811 | } |
| 3812 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3813 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3814 | { |
| 3815 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3816 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3817 | |
| 3818 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3819 | smp_rmb(); |
| 3820 | intel_crtc->unpin_work = NULL; |
| 3821 | |
| 3822 | if (work->event) |
| 3823 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3824 | intel_crtc->pipe, |
| 3825 | work->event); |
| 3826 | |
| 3827 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3828 | |
| 3829 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3830 | queue_work(dev_priv->wq, &work->work); |
| 3831 | |
| 3832 | trace_i915_flip_complete(intel_crtc->plane, |
| 3833 | work->pending_flip_obj); |
| 3834 | } |
| 3835 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3836 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3837 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3838 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3839 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3840 | long ret; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3841 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3842 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3843 | |
| 3844 | ret = wait_event_interruptible_timeout( |
| 3845 | dev_priv->pending_flip_queue, |
| 3846 | !intel_crtc_has_pending_flip(crtc), |
| 3847 | 60*HZ); |
| 3848 | |
| 3849 | if (ret < 0) |
| 3850 | return ret; |
| 3851 | |
| 3852 | if (ret == 0) { |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3853 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3854 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3855 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3856 | if (intel_crtc->unpin_work) { |
| 3857 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3858 | page_flip_completed(intel_crtc); |
| 3859 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3860 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3861 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3862 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3863 | return 0; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3864 | } |
| 3865 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3866 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
| 3867 | { |
| 3868 | u32 temp; |
| 3869 | |
| 3870 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3871 | |
| 3872 | mutex_lock(&dev_priv->sb_lock); |
| 3873 | |
| 3874 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3875 | temp |= SBI_SSCCTL_DISABLE; |
| 3876 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 3877 | |
| 3878 | mutex_unlock(&dev_priv->sb_lock); |
| 3879 | } |
| 3880 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3881 | /* Program iCLKIP clock to the desired frequency */ |
| 3882 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3883 | { |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3884 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3885 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3886 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3887 | u32 temp; |
| 3888 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3889 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3890 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3891 | /* The iCLK virtual clock root frequency is in MHz, |
| 3892 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3893 | * divisors, it is necessary to divide one by another, so we |
| 3894 | * convert the virtual clock precision to KHz here for higher |
| 3895 | * precision. |
| 3896 | */ |
| 3897 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3898 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3899 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3900 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3901 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3902 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3903 | clock << auxdiv); |
| 3904 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 3905 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3906 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3907 | /* |
| 3908 | * Near 20MHz is a corner case which is |
| 3909 | * out of range for the 7-bit divisor |
| 3910 | */ |
| 3911 | if (divsel <= 0x7f) |
| 3912 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | /* This should not happen with any sane values */ |
| 3916 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3917 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3918 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3919 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3920 | |
| 3921 | 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] | 3922 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3923 | auxdiv, |
| 3924 | divsel, |
| 3925 | phasedir, |
| 3926 | phaseinc); |
| 3927 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3928 | mutex_lock(&dev_priv->sb_lock); |
| 3929 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3930 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3931 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3932 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3933 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3934 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3935 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3936 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3937 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3938 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3939 | |
| 3940 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3941 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3942 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3943 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3944 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3945 | |
| 3946 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3947 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3948 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3949 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3950 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3951 | mutex_unlock(&dev_priv->sb_lock); |
| 3952 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3953 | /* Wait for initialization time */ |
| 3954 | udelay(24); |
| 3955 | |
| 3956 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 3957 | } |
| 3958 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 3959 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 3960 | { |
| 3961 | u32 divsel, phaseinc, auxdiv; |
| 3962 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3963 | u32 iclk_pi_range = 64; |
| 3964 | u32 desired_divisor; |
| 3965 | u32 temp; |
| 3966 | |
| 3967 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 3968 | return 0; |
| 3969 | |
| 3970 | mutex_lock(&dev_priv->sb_lock); |
| 3971 | |
| 3972 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3973 | if (temp & SBI_SSCCTL_DISABLE) { |
| 3974 | mutex_unlock(&dev_priv->sb_lock); |
| 3975 | return 0; |
| 3976 | } |
| 3977 | |
| 3978 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 3979 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 3980 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 3981 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 3982 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 3983 | |
| 3984 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 3985 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 3986 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 3987 | |
| 3988 | mutex_unlock(&dev_priv->sb_lock); |
| 3989 | |
| 3990 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 3991 | |
| 3992 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3993 | desired_divisor << auxdiv); |
| 3994 | } |
| 3995 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3996 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3997 | enum pipe pch_transcoder) |
| 3998 | { |
| 3999 | struct drm_device *dev = crtc->base.dev; |
| 4000 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4001 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4002 | |
| 4003 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4004 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4005 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4006 | I915_READ(HBLANK(cpu_transcoder))); |
| 4007 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4008 | I915_READ(HSYNC(cpu_transcoder))); |
| 4009 | |
| 4010 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4011 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4012 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4013 | I915_READ(VBLANK(cpu_transcoder))); |
| 4014 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4015 | I915_READ(VSYNC(cpu_transcoder))); |
| 4016 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4017 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4018 | } |
| 4019 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4020 | 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] | 4021 | { |
| 4022 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4023 | uint32_t temp; |
| 4024 | |
| 4025 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4026 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4027 | return; |
| 4028 | |
| 4029 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4030 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4031 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4032 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4033 | if (enable) |
| 4034 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4035 | |
| 4036 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4037 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4038 | POSTING_READ(SOUTH_CHICKEN1); |
| 4039 | } |
| 4040 | |
| 4041 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4042 | { |
| 4043 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4044 | |
| 4045 | switch (intel_crtc->pipe) { |
| 4046 | case PIPE_A: |
| 4047 | break; |
| 4048 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4049 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4050 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4051 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4052 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4053 | |
| 4054 | break; |
| 4055 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4056 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4057 | |
| 4058 | break; |
| 4059 | default: |
| 4060 | BUG(); |
| 4061 | } |
| 4062 | } |
| 4063 | |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4064 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 4065 | static enum port |
| 4066 | intel_trans_dp_port_sel(struct drm_crtc *crtc) |
| 4067 | { |
| 4068 | struct drm_device *dev = crtc->dev; |
| 4069 | struct intel_encoder *encoder; |
| 4070 | |
| 4071 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4072 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || |
| 4073 | encoder->type == INTEL_OUTPUT_EDP) |
| 4074 | return enc_to_dig_port(&encoder->base)->port; |
| 4075 | } |
| 4076 | |
| 4077 | return -1; |
| 4078 | } |
| 4079 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4080 | /* |
| 4081 | * Enable PCH resources required for PCH ports: |
| 4082 | * - PCH PLLs |
| 4083 | * - FDI training & RX/TX |
| 4084 | * - update transcoder timings |
| 4085 | * - DP transcoding bits |
| 4086 | * - transcoder |
| 4087 | */ |
| 4088 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4089 | { |
| 4090 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4091 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4092 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4093 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4094 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4095 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4096 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4097 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4098 | if (IS_IVYBRIDGE(dev)) |
| 4099 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4100 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4101 | /* Write the TU size bits before fdi link training, so that error |
| 4102 | * detection works. */ |
| 4103 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4104 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4105 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4106 | /* |
| 4107 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 4108 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 4109 | */ |
| 4110 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4111 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4112 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4113 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4114 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4115 | /* We need to program the right clock selection before writing the pixel |
| 4116 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4117 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4118 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4119 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4120 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4121 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4122 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4123 | if (intel_crtc->config->shared_dpll == |
| 4124 | intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4125 | temp |= sel; |
| 4126 | else |
| 4127 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4128 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4129 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4130 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4131 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4132 | * transcoder, and we actually should do this to not upset any PCH |
| 4133 | * transcoder that already use the clock when we share it. |
| 4134 | * |
| 4135 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4136 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4137 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4138 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4139 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4140 | /* set transcoder timing, panel must allow it */ |
| 4141 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4142 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4143 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4144 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4145 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4146 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4147 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4148 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4149 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4150 | const struct drm_display_mode *adjusted_mode = |
| 4151 | &intel_crtc->config->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4152 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4153 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4154 | temp = I915_READ(reg); |
| 4155 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4156 | TRANS_DP_SYNC_MASK | |
| 4157 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4158 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4159 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4160 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4161 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4162 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4163 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4164 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4165 | |
| 4166 | switch (intel_trans_dp_port_sel(crtc)) { |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4167 | case PORT_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4168 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4169 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4170 | case PORT_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4171 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4172 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4173 | case PORT_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4174 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4175 | break; |
| 4176 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4177 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4180 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4183 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4186 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4187 | { |
| 4188 | struct drm_device *dev = crtc->dev; |
| 4189 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4190 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4191 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4192 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4193 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4194 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4195 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4196 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4197 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4198 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4199 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4200 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4201 | } |
| 4202 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4203 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4204 | { |
| 4205 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4206 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4207 | u32 temp; |
| 4208 | |
| 4209 | temp = I915_READ(dslreg); |
| 4210 | udelay(500); |
| 4211 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4212 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4213 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4217 | static int |
| 4218 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
| 4219 | unsigned scaler_user, int *scaler_id, unsigned int rotation, |
| 4220 | int src_w, int src_h, int dst_w, int dst_h) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4221 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4222 | struct intel_crtc_scaler_state *scaler_state = |
| 4223 | &crtc_state->scaler_state; |
| 4224 | struct intel_crtc *intel_crtc = |
| 4225 | to_intel_crtc(crtc_state->base.crtc); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4226 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4227 | |
| 4228 | need_scaling = intel_rotation_90_or_270(rotation) ? |
| 4229 | (src_h != dst_w || src_w != dst_h): |
| 4230 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4231 | |
| 4232 | /* |
| 4233 | * if plane is being disabled or scaler is no more required or force detach |
| 4234 | * - free scaler binded to this plane/crtc |
| 4235 | * - in order to do this, update crtc->scaler_usage |
| 4236 | * |
| 4237 | * Here scaler state in crtc_state is set free so that |
| 4238 | * scaler can be assigned to other user. Actual register |
| 4239 | * update to free the scaler is done in plane/panel-fit programming. |
| 4240 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4241 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4242 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4243 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4244 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4245 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4246 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4247 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4248 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4249 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4250 | scaler_state->scaler_users); |
| 4251 | *scaler_id = -1; |
| 4252 | } |
| 4253 | return 0; |
| 4254 | } |
| 4255 | |
| 4256 | /* range checks */ |
| 4257 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4258 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4259 | |
| 4260 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4261 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4262 | 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] | 4263 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4264 | 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] | 4265 | return -EINVAL; |
| 4266 | } |
| 4267 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4268 | /* mark this plane as a scaler user in crtc_state */ |
| 4269 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4270 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4271 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4272 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4273 | scaler_state->scaler_users); |
| 4274 | |
| 4275 | return 0; |
| 4276 | } |
| 4277 | |
| 4278 | /** |
| 4279 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4280 | * |
| 4281 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4282 | * |
| 4283 | * Return |
| 4284 | * 0 - scaler_usage updated successfully |
| 4285 | * error - requested scaling cannot be supported or other error condition |
| 4286 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4287 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4288 | { |
| 4289 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4290 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4291 | |
| 4292 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", |
| 4293 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); |
| 4294 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4295 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Ville Syrjälä | fa5a797 | 2015-10-15 17:01:58 +0300 | [diff] [blame] | 4296 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4297 | state->pipe_src_w, state->pipe_src_h, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 4298 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | /** |
| 4302 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
| 4303 | * |
| 4304 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4305 | * @plane_state: atomic plane state to update |
| 4306 | * |
| 4307 | * Return |
| 4308 | * 0 - scaler_usage updated successfully |
| 4309 | * error - requested scaling cannot be supported or other error condition |
| 4310 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4311 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4312 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4313 | { |
| 4314 | |
| 4315 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4316 | struct intel_plane *intel_plane = |
| 4317 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4318 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4319 | int ret; |
| 4320 | |
| 4321 | bool force_detach = !fb || !plane_state->visible; |
| 4322 | |
| 4323 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", |
| 4324 | intel_plane->base.base.id, intel_crtc->pipe, |
| 4325 | drm_plane_index(&intel_plane->base)); |
| 4326 | |
| 4327 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4328 | drm_plane_index(&intel_plane->base), |
| 4329 | &plane_state->scaler_id, |
| 4330 | plane_state->base.rotation, |
| 4331 | drm_rect_width(&plane_state->src) >> 16, |
| 4332 | drm_rect_height(&plane_state->src) >> 16, |
| 4333 | drm_rect_width(&plane_state->dst), |
| 4334 | drm_rect_height(&plane_state->dst)); |
| 4335 | |
| 4336 | if (ret || plane_state->scaler_id < 0) |
| 4337 | return ret; |
| 4338 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4339 | /* check colorkey */ |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4340 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4341 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4342 | intel_plane->base.base.id); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4343 | return -EINVAL; |
| 4344 | } |
| 4345 | |
| 4346 | /* Check src format */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4347 | switch (fb->pixel_format) { |
| 4348 | case DRM_FORMAT_RGB565: |
| 4349 | case DRM_FORMAT_XBGR8888: |
| 4350 | case DRM_FORMAT_XRGB8888: |
| 4351 | case DRM_FORMAT_ABGR8888: |
| 4352 | case DRM_FORMAT_ARGB8888: |
| 4353 | case DRM_FORMAT_XRGB2101010: |
| 4354 | case DRM_FORMAT_XBGR2101010: |
| 4355 | case DRM_FORMAT_YUYV: |
| 4356 | case DRM_FORMAT_YVYU: |
| 4357 | case DRM_FORMAT_UYVY: |
| 4358 | case DRM_FORMAT_VYUY: |
| 4359 | break; |
| 4360 | default: |
| 4361 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", |
| 4362 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); |
| 4363 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4364 | } |
| 4365 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4366 | return 0; |
| 4367 | } |
| 4368 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4369 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4370 | { |
| 4371 | int i; |
| 4372 | |
| 4373 | for (i = 0; i < crtc->num_scalers; i++) |
| 4374 | skl_detach_scaler(crtc, i); |
| 4375 | } |
| 4376 | |
| 4377 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4378 | { |
| 4379 | struct drm_device *dev = crtc->base.dev; |
| 4380 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4381 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4382 | struct intel_crtc_scaler_state *scaler_state = |
| 4383 | &crtc->config->scaler_state; |
| 4384 | |
| 4385 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4386 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4387 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4388 | int id; |
| 4389 | |
| 4390 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4391 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4392 | return; |
| 4393 | } |
| 4394 | |
| 4395 | id = scaler_state->scaler_id; |
| 4396 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4397 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4398 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4399 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4400 | |
| 4401 | 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] | 4402 | } |
| 4403 | } |
| 4404 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4405 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4406 | { |
| 4407 | struct drm_device *dev = crtc->base.dev; |
| 4408 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4409 | int pipe = crtc->pipe; |
| 4410 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4411 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4412 | /* Force use of hard-coded filter coefficients |
| 4413 | * as some pre-programmed values are broken, |
| 4414 | * e.g. x201. |
| 4415 | */ |
| 4416 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4417 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4418 | PF_PIPE_SEL_IVB(pipe)); |
| 4419 | else |
| 4420 | 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] | 4421 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4422 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4423 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4426 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4427 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4428 | struct drm_device *dev = crtc->base.dev; |
| 4429 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4430 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4431 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4432 | return; |
| 4433 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4434 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4435 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4436 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4437 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4438 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4439 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4440 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4441 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4442 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4443 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4444 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4445 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4446 | */ |
| 4447 | } else { |
| 4448 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4449 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4450 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4451 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4452 | * the HW state readout code will complain that the expected |
| 4453 | * IPS_CTL value is not the one we read. */ |
| 4454 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4455 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4456 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4457 | } |
| 4458 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4459 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4460 | { |
| 4461 | struct drm_device *dev = crtc->base.dev; |
| 4462 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4463 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4464 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4465 | return; |
| 4466 | |
| 4467 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4468 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4469 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4470 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4471 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4472 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4473 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4474 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4475 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4476 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4477 | POSTING_READ(IPS_CTL); |
| 4478 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4479 | |
| 4480 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4481 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4482 | } |
| 4483 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4484 | 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] | 4485 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4486 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4487 | struct drm_device *dev = intel_crtc->base.dev; |
| 4488 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4489 | |
| 4490 | mutex_lock(&dev->struct_mutex); |
| 4491 | dev_priv->mm.interruptible = false; |
| 4492 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4493 | dev_priv->mm.interruptible = true; |
| 4494 | mutex_unlock(&dev->struct_mutex); |
| 4495 | } |
| 4496 | |
| 4497 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4498 | * has to recompute where to put it anyway. |
| 4499 | */ |
| 4500 | } |
| 4501 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4502 | /** |
| 4503 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4504 | * @crtc: the CRTC whose primary plane was just enabled |
| 4505 | * |
| 4506 | * Performs potentially sleeping operations that must be done after the primary |
| 4507 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4508 | * called due to an explicit primary plane update, or due to an implicit |
| 4509 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4510 | * completely hide the primary plane. |
| 4511 | */ |
| 4512 | static void |
| 4513 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4514 | { |
| 4515 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4516 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4517 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4518 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4519 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4520 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4521 | * FIXME IPS should be fine as long as one plane is |
| 4522 | * enabled, but in practice it seems to have problems |
| 4523 | * when going from primary only to sprite only and vice |
| 4524 | * versa. |
| 4525 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4526 | hsw_enable_ips(intel_crtc); |
| 4527 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4528 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4529 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4530 | * So don't enable underrun reporting before at least some planes |
| 4531 | * are enabled. |
| 4532 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4533 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4534 | */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4535 | if (IS_GEN2(dev)) |
| 4536 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4537 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 4538 | /* Underruns don't always raise interrupts, so check manually. */ |
| 4539 | intel_check_cpu_fifo_underruns(dev_priv); |
| 4540 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4541 | } |
| 4542 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4543 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4544 | static void |
| 4545 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4546 | { |
| 4547 | struct drm_device *dev = crtc->dev; |
| 4548 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4549 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4550 | int pipe = intel_crtc->pipe; |
| 4551 | |
| 4552 | /* |
| 4553 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4554 | * So diasble underrun reporting before all the planes get disabled. |
| 4555 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4556 | * but leave the pipe running. |
| 4557 | */ |
| 4558 | if (IS_GEN2(dev)) |
| 4559 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4560 | |
| 4561 | /* |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4562 | * FIXME IPS should be fine as long as one plane is |
| 4563 | * enabled, but in practice it seems to have problems |
| 4564 | * when going from primary only to sprite only and vice |
| 4565 | * versa. |
| 4566 | */ |
| 4567 | hsw_disable_ips(intel_crtc); |
| 4568 | } |
| 4569 | |
| 4570 | /* FIXME get rid of this and use pre_plane_update */ |
| 4571 | static void |
| 4572 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 4573 | { |
| 4574 | struct drm_device *dev = crtc->dev; |
| 4575 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4576 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4577 | int pipe = intel_crtc->pipe; |
| 4578 | |
| 4579 | intel_pre_disable_primary(crtc); |
| 4580 | |
| 4581 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4582 | * Vblank time updates from the shadow to live plane control register |
| 4583 | * are blocked if the memory self-refresh mode is active at that |
| 4584 | * moment. So to make sure the plane gets truly disabled, disable |
| 4585 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4586 | * will be checked/applied by the HW only at the next frame start |
| 4587 | * event which is after the vblank start event, so we need to have a |
| 4588 | * wait-for-vblank between disabling the plane and the pipe. |
| 4589 | */ |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4590 | if (HAS_GMCH_DISPLAY(dev)) { |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4591 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4592 | dev_priv->wm.vlv.cxsr = false; |
| 4593 | intel_wait_for_vblank(dev, pipe); |
| 4594 | } |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4595 | } |
| 4596 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4597 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4598 | { |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4599 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 4600 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4601 | struct intel_crtc_state *pipe_config = |
| 4602 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4603 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4604 | struct drm_plane *primary = crtc->base.primary; |
| 4605 | struct drm_plane_state *old_pri_state = |
| 4606 | drm_atomic_get_existing_plane_state(old_state, primary); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4607 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4608 | intel_frontbuffer_flip(dev, pipe_config->fb_bits); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4609 | |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4610 | crtc->wm.cxsr_allowed = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4611 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 4612 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 4613 | intel_update_watermarks(&crtc->base); |
| 4614 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4615 | if (old_pri_state) { |
| 4616 | struct intel_plane_state *primary_state = |
| 4617 | to_intel_plane_state(primary->state); |
| 4618 | struct intel_plane_state *old_primary_state = |
| 4619 | to_intel_plane_state(old_pri_state); |
| 4620 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 4621 | intel_fbc_post_update(crtc); |
| 4622 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4623 | if (primary_state->visible && |
| 4624 | (needs_modeset(&pipe_config->base) || |
| 4625 | !old_primary_state->visible)) |
| 4626 | intel_post_enable_primary(&crtc->base); |
| 4627 | } |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4628 | } |
| 4629 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4630 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4631 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4632 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4633 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 4634 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4635 | struct intel_crtc_state *pipe_config = |
| 4636 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4637 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 4638 | struct drm_plane *primary = crtc->base.primary; |
| 4639 | struct drm_plane_state *old_pri_state = |
| 4640 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 4641 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4642 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4643 | if (old_pri_state) { |
| 4644 | struct intel_plane_state *primary_state = |
| 4645 | to_intel_plane_state(primary->state); |
| 4646 | struct intel_plane_state *old_primary_state = |
| 4647 | to_intel_plane_state(old_pri_state); |
| 4648 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 4649 | intel_fbc_pre_update(crtc); |
| 4650 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4651 | if (old_primary_state->visible && |
| 4652 | (modeset || !primary_state->visible)) |
| 4653 | intel_pre_disable_primary(&crtc->base); |
| 4654 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4655 | |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4656 | if (pipe_config->disable_cxsr) { |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4657 | crtc->wm.cxsr_allowed = false; |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4658 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4659 | /* |
| 4660 | * Vblank time updates from the shadow to live plane control register |
| 4661 | * are blocked if the memory self-refresh mode is active at that |
| 4662 | * moment. So to make sure the plane gets truly disabled, disable |
| 4663 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4664 | * will be checked/applied by the HW only at the next frame start |
| 4665 | * event which is after the vblank start event, so we need to have a |
| 4666 | * wait-for-vblank between disabling the plane and the pipe. |
| 4667 | */ |
| 4668 | if (old_crtc_state->base.active) { |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4669 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4670 | dev_priv->wm.vlv.cxsr = false; |
| 4671 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4672 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4673 | } |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4674 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4675 | /* |
| 4676 | * IVB workaround: must disable low power watermarks for at least |
| 4677 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 4678 | * when scaling is disabled. |
| 4679 | * |
| 4680 | * WaCxSRDisabledForSpriteScaling:ivb |
| 4681 | */ |
| 4682 | if (pipe_config->disable_lp_wm) { |
| 4683 | ilk_disable_lp_wm(dev); |
| 4684 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4685 | } |
| 4686 | |
| 4687 | /* |
| 4688 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 4689 | * watermark programming here. |
| 4690 | */ |
| 4691 | if (needs_modeset(&pipe_config->base)) |
| 4692 | return; |
| 4693 | |
| 4694 | /* |
| 4695 | * For platforms that support atomic watermarks, program the |
| 4696 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 4697 | * will be the intermediate values that are safe for both pre- and |
| 4698 | * post- vblank; when vblank happens, the 'active' values will be set |
| 4699 | * to the final 'target' values and we'll do this again to get the |
| 4700 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 4701 | * will be the final target values which will get automatically latched |
| 4702 | * at vblank time; no further programming will be necessary. |
| 4703 | * |
| 4704 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 4705 | * we'll continue to update watermarks the old way, if flags tell |
| 4706 | * us to. |
| 4707 | */ |
| 4708 | if (dev_priv->display.initial_watermarks != NULL) |
| 4709 | dev_priv->display.initial_watermarks(pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 4710 | else if (pipe_config->update_wm_pre) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4711 | intel_update_watermarks(&crtc->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4712 | } |
| 4713 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4714 | 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] | 4715 | { |
| 4716 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4717 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4718 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4719 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4720 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4721 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4722 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4723 | drm_for_each_plane_mask(p, dev, plane_mask) |
| 4724 | to_intel_plane(p)->disable_plane(p, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4725 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4726 | /* |
| 4727 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4728 | * to compute the mask of flip planes precisely. For the time being |
| 4729 | * consider this a flip to a NULL plane. |
| 4730 | */ |
| 4731 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4732 | } |
| 4733 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4734 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4735 | { |
| 4736 | struct drm_device *dev = crtc->dev; |
| 4737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4738 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4739 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4740 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4741 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4742 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4743 | return; |
| 4744 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4745 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4746 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4747 | |
| 4748 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4749 | intel_prepare_shared_dpll(intel_crtc); |
| 4750 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4751 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4752 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4753 | |
| 4754 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4755 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4756 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4757 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4758 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4759 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | ironlake_set_pipeconf(crtc); |
| 4763 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4764 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4765 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4766 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4767 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4768 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4769 | if (encoder->pre_enable) |
| 4770 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4771 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4772 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4773 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4774 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4775 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4776 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4777 | } else { |
| 4778 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4779 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4780 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4781 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4782 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4783 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4784 | /* |
| 4785 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4786 | * clocks enabled |
| 4787 | */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 4788 | intel_color_load_luts(crtc); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4789 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4790 | if (dev_priv->display.initial_watermarks != NULL) |
| 4791 | dev_priv->display.initial_watermarks(intel_crtc->config); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4792 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4793 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4794 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4795 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4796 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4797 | assert_vblank_disabled(crtc); |
| 4798 | drm_crtc_vblank_on(crtc); |
| 4799 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4800 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4801 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4802 | |
| 4803 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4804 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4805 | |
| 4806 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ |
| 4807 | if (intel_crtc->config->has_pch_encoder) |
| 4808 | intel_wait_for_vblank(dev, pipe); |
| 4809 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4812 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4813 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4814 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4815 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4816 | } |
| 4817 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4818 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4819 | { |
| 4820 | struct drm_device *dev = crtc->dev; |
| 4821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4823 | struct intel_encoder *encoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4824 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4825 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4826 | struct intel_crtc_state *pipe_config = |
| 4827 | to_intel_crtc_state(crtc->state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4828 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4829 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4830 | return; |
| 4831 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4832 | if (intel_crtc->config->has_pch_encoder) |
| 4833 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4834 | false); |
| 4835 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4836 | if (intel_crtc->config->shared_dpll) |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4837 | intel_enable_shared_dpll(intel_crtc); |
| 4838 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4839 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4840 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4841 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4842 | if (!intel_crtc->config->has_dsi_encoder) |
| 4843 | intel_set_pipe_timings(intel_crtc); |
| 4844 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4845 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4846 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4847 | if (cpu_transcoder != TRANSCODER_EDP && |
| 4848 | !transcoder_is_dsi(cpu_transcoder)) { |
| 4849 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4850 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4853 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4854 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4855 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4856 | } |
| 4857 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4858 | if (!intel_crtc->config->has_dsi_encoder) |
| 4859 | haswell_set_pipeconf(crtc); |
| 4860 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 4861 | haswell_set_pipemisc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4862 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 4863 | intel_color_set_csc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4864 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4865 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4866 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4867 | if (intel_crtc->config->has_pch_encoder) |
| 4868 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4869 | else |
| 4870 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4871 | |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4872 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4873 | if (encoder->pre_enable) |
| 4874 | encoder->pre_enable(encoder); |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4875 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4876 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4877 | if (intel_crtc->config->has_pch_encoder) |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4878 | dev_priv->display.fdi_link_train(crtc); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4879 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4880 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4881 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4882 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4883 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4884 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4885 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4886 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4887 | |
| 4888 | /* |
| 4889 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4890 | * clocks enabled |
| 4891 | */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 4892 | intel_color_load_luts(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4893 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4894 | intel_ddi_set_pipe_settings(crtc); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4895 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4896 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4897 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4898 | if (dev_priv->display.initial_watermarks != NULL) |
| 4899 | dev_priv->display.initial_watermarks(pipe_config); |
| 4900 | else |
| 4901 | intel_update_watermarks(crtc); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4902 | |
| 4903 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 4904 | if (!intel_crtc->config->has_dsi_encoder) |
| 4905 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4906 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4907 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4908 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4909 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4910 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4911 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4912 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4913 | assert_vblank_disabled(crtc); |
| 4914 | drm_crtc_vblank_on(crtc); |
| 4915 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4916 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4917 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4918 | intel_opregion_notify_encoder(encoder, true); |
| 4919 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4920 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4921 | if (intel_crtc->config->has_pch_encoder) { |
| 4922 | intel_wait_for_vblank(dev, pipe); |
| 4923 | intel_wait_for_vblank(dev, pipe); |
| 4924 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4925 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4926 | true); |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4927 | } |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4928 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4929 | /* If we change the relative order between pipe/planes enabling, we need |
| 4930 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4931 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
| 4932 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { |
| 4933 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4934 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4935 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4936 | } |
| 4937 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4938 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4939 | { |
| 4940 | struct drm_device *dev = crtc->base.dev; |
| 4941 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4942 | int pipe = crtc->pipe; |
| 4943 | |
| 4944 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4945 | * it's in use. The hw state code will make sure we get this right. */ |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4946 | if (force || crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4947 | I915_WRITE(PF_CTL(pipe), 0); |
| 4948 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4949 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4950 | } |
| 4951 | } |
| 4952 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4953 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4954 | { |
| 4955 | struct drm_device *dev = crtc->dev; |
| 4956 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4957 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4958 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4959 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4960 | |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4961 | if (intel_crtc->config->has_pch_encoder) |
| 4962 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4963 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4964 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4965 | encoder->disable(encoder); |
| 4966 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4967 | drm_crtc_vblank_off(crtc); |
| 4968 | assert_vblank_disabled(crtc); |
| 4969 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4970 | /* |
| 4971 | * Sometimes spurious CPU pipe underruns happen when the |
| 4972 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 4973 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 4974 | */ |
| 4975 | if (intel_crtc->config->has_pch_encoder) |
| 4976 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4977 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4978 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4979 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4980 | ironlake_pfit_disable(intel_crtc, false); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4981 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4982 | if (intel_crtc->config->has_pch_encoder) { |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4983 | ironlake_fdi_disable(crtc); |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4984 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4985 | } |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4986 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4987 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4988 | if (encoder->post_disable) |
| 4989 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4990 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4991 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4992 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4993 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4994 | if (HAS_PCH_CPT(dev)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4995 | i915_reg_t reg; |
| 4996 | u32 temp; |
| 4997 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4998 | /* disable TRANS_DP_CTL */ |
| 4999 | reg = TRANS_DP_CTL(pipe); |
| 5000 | temp = I915_READ(reg); |
| 5001 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5002 | TRANS_DP_PORT_SEL_MASK); |
| 5003 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5004 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5005 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5006 | /* disable DPLL_SEL */ |
| 5007 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5008 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5009 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5010 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5011 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5012 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5013 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5014 | |
| 5015 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5016 | } |
| 5017 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5018 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 5019 | { |
| 5020 | struct drm_device *dev = crtc->dev; |
| 5021 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5022 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5023 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5024 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5025 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5026 | if (intel_crtc->config->has_pch_encoder) |
| 5027 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5028 | false); |
| 5029 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5030 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5031 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5032 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5033 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5034 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5035 | drm_crtc_vblank_off(crtc); |
| 5036 | assert_vblank_disabled(crtc); |
| 5037 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5038 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 5039 | if (!intel_crtc->config->has_dsi_encoder) |
| 5040 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5041 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5042 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5043 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5044 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5045 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5046 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5047 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 5048 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5049 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5050 | else |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5051 | ironlake_pfit_disable(intel_crtc, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5052 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5053 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5054 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5055 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 5056 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5057 | if (encoder->post_disable) |
| 5058 | encoder->post_disable(encoder); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5059 | |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5060 | if (intel_crtc->config->has_pch_encoder) { |
| 5061 | lpt_disable_pch_transcoder(dev_priv); |
Ville Syrjälä | 503a74e | 2015-12-04 22:22:14 +0200 | [diff] [blame] | 5062 | lpt_disable_iclkip(dev_priv); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5063 | intel_ddi_fdi_disable(crtc); |
| 5064 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5065 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5066 | true); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5067 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5068 | } |
| 5069 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5070 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5071 | { |
| 5072 | struct drm_device *dev = crtc->base.dev; |
| 5073 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5074 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5075 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5076 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5077 | return; |
| 5078 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5079 | /* |
| 5080 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5081 | * according to register description and PRM. |
| 5082 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5083 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5084 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5085 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5086 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5087 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5088 | |
| 5089 | /* Border color in case we don't scale up to the full screen. Black by |
| 5090 | * default, change to something else for debugging. */ |
| 5091 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5094 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5095 | { |
| 5096 | switch (port) { |
| 5097 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5098 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5099 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5100 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5101 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5102 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5103 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5104 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5105 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5106 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5107 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5108 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5109 | return POWER_DOMAIN_PORT_OTHER; |
| 5110 | } |
| 5111 | } |
| 5112 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5113 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
| 5114 | { |
| 5115 | switch (port) { |
| 5116 | case PORT_A: |
| 5117 | return POWER_DOMAIN_AUX_A; |
| 5118 | case PORT_B: |
| 5119 | return POWER_DOMAIN_AUX_B; |
| 5120 | case PORT_C: |
| 5121 | return POWER_DOMAIN_AUX_C; |
| 5122 | case PORT_D: |
| 5123 | return POWER_DOMAIN_AUX_D; |
| 5124 | case PORT_E: |
| 5125 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5126 | return POWER_DOMAIN_AUX_D; |
| 5127 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5128 | MISSING_CASE(port); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5129 | return POWER_DOMAIN_AUX_A; |
| 5130 | } |
| 5131 | } |
| 5132 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5133 | enum intel_display_power_domain |
| 5134 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5135 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5136 | struct drm_device *dev = intel_encoder->base.dev; |
| 5137 | struct intel_digital_port *intel_dig_port; |
| 5138 | |
| 5139 | switch (intel_encoder->type) { |
| 5140 | case INTEL_OUTPUT_UNKNOWN: |
| 5141 | /* Only DDI platforms should ever use this output type */ |
| 5142 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5143 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5144 | case INTEL_OUTPUT_HDMI: |
| 5145 | case INTEL_OUTPUT_EDP: |
| 5146 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5147 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5148 | case INTEL_OUTPUT_DP_MST: |
| 5149 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5150 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5151 | case INTEL_OUTPUT_ANALOG: |
| 5152 | return POWER_DOMAIN_PORT_CRT; |
| 5153 | case INTEL_OUTPUT_DSI: |
| 5154 | return POWER_DOMAIN_PORT_DSI; |
| 5155 | default: |
| 5156 | return POWER_DOMAIN_PORT_OTHER; |
| 5157 | } |
| 5158 | } |
| 5159 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5160 | enum intel_display_power_domain |
| 5161 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) |
| 5162 | { |
| 5163 | struct drm_device *dev = intel_encoder->base.dev; |
| 5164 | struct intel_digital_port *intel_dig_port; |
| 5165 | |
| 5166 | switch (intel_encoder->type) { |
| 5167 | case INTEL_OUTPUT_UNKNOWN: |
Imre Deak | 651174a | 2015-11-18 15:57:24 +0200 | [diff] [blame] | 5168 | case INTEL_OUTPUT_HDMI: |
| 5169 | /* |
| 5170 | * Only DDI platforms should ever use these output types. |
| 5171 | * We can get here after the HDMI detect code has already set |
| 5172 | * the type of the shared encoder. Since we can't be sure |
| 5173 | * what's the status of the given connectors, play safe and |
| 5174 | * run the DP detection too. |
| 5175 | */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5176 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5177 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5178 | case INTEL_OUTPUT_EDP: |
| 5179 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 5180 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5181 | case INTEL_OUTPUT_DP_MST: |
| 5182 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5183 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5184 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5185 | MISSING_CASE(intel_encoder->type); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5186 | return POWER_DOMAIN_AUX_A; |
| 5187 | } |
| 5188 | } |
| 5189 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5190 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
| 5191 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5192 | { |
| 5193 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5194 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5195 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5196 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5197 | unsigned long mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5198 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5199 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5200 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5201 | return 0; |
| 5202 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5203 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5204 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5205 | if (crtc_state->pch_pfit.enabled || |
| 5206 | crtc_state->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5207 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5208 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5209 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5210 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5211 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5212 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5213 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5214 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5215 | if (crtc_state->shared_dpll) |
| 5216 | mask |= BIT(POWER_DOMAIN_PLLS); |
| 5217 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5218 | return mask; |
| 5219 | } |
| 5220 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5221 | static unsigned long |
| 5222 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5223 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5224 | { |
| 5225 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5226 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5227 | enum intel_display_power_domain domain; |
| 5228 | unsigned long domains, new_domains, old_domains; |
| 5229 | |
| 5230 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5231 | intel_crtc->enabled_power_domains = new_domains = |
| 5232 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5233 | |
| 5234 | domains = new_domains & ~old_domains; |
| 5235 | |
| 5236 | for_each_power_domain(domain, domains) |
| 5237 | intel_display_power_get(dev_priv, domain); |
| 5238 | |
| 5239 | return old_domains & ~new_domains; |
| 5240 | } |
| 5241 | |
| 5242 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
| 5243 | unsigned long domains) |
| 5244 | { |
| 5245 | enum intel_display_power_domain domain; |
| 5246 | |
| 5247 | for_each_power_domain(domain, domains) |
| 5248 | intel_display_power_put(dev_priv, domain); |
| 5249 | } |
| 5250 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5251 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
| 5252 | { |
| 5253 | int max_cdclk_freq = dev_priv->max_cdclk_freq; |
| 5254 | |
| 5255 | if (INTEL_INFO(dev_priv)->gen >= 9 || |
| 5256 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 5257 | return max_cdclk_freq; |
| 5258 | else if (IS_CHERRYVIEW(dev_priv)) |
| 5259 | return max_cdclk_freq*95/100; |
| 5260 | else if (INTEL_INFO(dev_priv)->gen < 4) |
| 5261 | return 2*max_cdclk_freq*90/100; |
| 5262 | else |
| 5263 | return max_cdclk_freq*90/100; |
| 5264 | } |
| 5265 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5266 | static void intel_update_max_cdclk(struct drm_device *dev) |
| 5267 | { |
| 5268 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5269 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 5270 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5271 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
| 5272 | |
| 5273 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
| 5274 | dev_priv->max_cdclk_freq = 675000; |
| 5275 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
| 5276 | dev_priv->max_cdclk_freq = 540000; |
| 5277 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
| 5278 | dev_priv->max_cdclk_freq = 450000; |
| 5279 | else |
| 5280 | dev_priv->max_cdclk_freq = 337500; |
| 5281 | } else if (IS_BROADWELL(dev)) { |
| 5282 | /* |
| 5283 | * FIXME with extra cooling we can allow |
| 5284 | * 540 MHz for ULX and 675 Mhz for ULT. |
| 5285 | * How can we know if extra cooling is |
| 5286 | * available? PCI ID, VTB, something else? |
| 5287 | */ |
| 5288 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 5289 | dev_priv->max_cdclk_freq = 450000; |
| 5290 | else if (IS_BDW_ULX(dev)) |
| 5291 | dev_priv->max_cdclk_freq = 450000; |
| 5292 | else if (IS_BDW_ULT(dev)) |
| 5293 | dev_priv->max_cdclk_freq = 540000; |
| 5294 | else |
| 5295 | dev_priv->max_cdclk_freq = 675000; |
Mika Kahola | 0904dea | 2015-06-12 10:11:32 +0300 | [diff] [blame] | 5296 | } else if (IS_CHERRYVIEW(dev)) { |
| 5297 | dev_priv->max_cdclk_freq = 320000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5298 | } else if (IS_VALLEYVIEW(dev)) { |
| 5299 | dev_priv->max_cdclk_freq = 400000; |
| 5300 | } else { |
| 5301 | /* otherwise assume cdclk is fixed */ |
| 5302 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; |
| 5303 | } |
| 5304 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5305 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
| 5306 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5307 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
| 5308 | dev_priv->max_cdclk_freq); |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5309 | |
| 5310 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", |
| 5311 | dev_priv->max_dotclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | static void intel_update_cdclk(struct drm_device *dev) |
| 5315 | { |
| 5316 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5317 | |
| 5318 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
| 5319 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
| 5320 | dev_priv->cdclk_freq); |
| 5321 | |
| 5322 | /* |
| 5323 | * Program the gmbus_freq based on the cdclk frequency. |
| 5324 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5325 | * in fact 1MHz is the correct frequency. |
| 5326 | */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 5327 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5328 | /* |
| 5329 | * Program the gmbus_freq based on the cdclk frequency. |
| 5330 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5331 | * in fact 1MHz is the correct frequency. |
| 5332 | */ |
| 5333 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
| 5334 | } |
| 5335 | |
| 5336 | if (dev_priv->max_cdclk_freq == 0) |
| 5337 | intel_update_max_cdclk(dev); |
| 5338 | } |
| 5339 | |
Damien Lespiau | 70d0c57 | 2015-06-04 18:21:29 +0100 | [diff] [blame] | 5340 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5341 | { |
| 5342 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5343 | uint32_t divider; |
| 5344 | uint32_t ratio; |
| 5345 | uint32_t current_freq; |
| 5346 | int ret; |
| 5347 | |
| 5348 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ |
| 5349 | switch (frequency) { |
| 5350 | case 144000: |
| 5351 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
| 5352 | ratio = BXT_DE_PLL_RATIO(60); |
| 5353 | break; |
| 5354 | case 288000: |
| 5355 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
| 5356 | ratio = BXT_DE_PLL_RATIO(60); |
| 5357 | break; |
| 5358 | case 384000: |
| 5359 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
| 5360 | ratio = BXT_DE_PLL_RATIO(60); |
| 5361 | break; |
| 5362 | case 576000: |
| 5363 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5364 | ratio = BXT_DE_PLL_RATIO(60); |
| 5365 | break; |
| 5366 | case 624000: |
| 5367 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5368 | ratio = BXT_DE_PLL_RATIO(65); |
| 5369 | break; |
| 5370 | case 19200: |
| 5371 | /* |
| 5372 | * Bypass frequency with DE PLL disabled. Init ratio, divider |
| 5373 | * to suppress GCC warning. |
| 5374 | */ |
| 5375 | ratio = 0; |
| 5376 | divider = 0; |
| 5377 | break; |
| 5378 | default: |
| 5379 | DRM_ERROR("unsupported CDCLK freq %d", frequency); |
| 5380 | |
| 5381 | return; |
| 5382 | } |
| 5383 | |
| 5384 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5385 | /* Inform power controller of upcoming frequency change */ |
| 5386 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5387 | 0x80000000); |
| 5388 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5389 | |
| 5390 | if (ret) { |
| 5391 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
| 5392 | ret, frequency); |
| 5393 | return; |
| 5394 | } |
| 5395 | |
| 5396 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; |
| 5397 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ |
| 5398 | current_freq = current_freq * 500 + 1000; |
| 5399 | |
| 5400 | /* |
| 5401 | * DE PLL has to be disabled when |
| 5402 | * - setting to 19.2MHz (bypass, PLL isn't used) |
| 5403 | * - before setting to 624MHz (PLL needs toggling) |
| 5404 | * - before setting to any frequency from 624MHz (PLL needs toggling) |
| 5405 | */ |
| 5406 | if (frequency == 19200 || frequency == 624000 || |
| 5407 | current_freq == 624000) { |
| 5408 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); |
| 5409 | /* Timeout 200us */ |
| 5410 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), |
| 5411 | 1)) |
| 5412 | DRM_ERROR("timout waiting for DE PLL unlock\n"); |
| 5413 | } |
| 5414 | |
| 5415 | if (frequency != 19200) { |
| 5416 | uint32_t val; |
| 5417 | |
| 5418 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5419 | val &= ~BXT_DE_PLL_RATIO_MASK; |
| 5420 | val |= ratio; |
| 5421 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5422 | |
| 5423 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5424 | /* Timeout 200us */ |
| 5425 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) |
| 5426 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
| 5427 | |
| 5428 | val = I915_READ(CDCLK_CTL); |
| 5429 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; |
| 5430 | val |= divider; |
| 5431 | /* |
| 5432 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5433 | * enable otherwise. |
| 5434 | */ |
| 5435 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5436 | if (frequency >= 500000) |
| 5437 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5438 | |
| 5439 | val &= ~CDCLK_FREQ_DECIMAL_MASK; |
| 5440 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5441 | val |= (frequency - 1000) / 500; |
| 5442 | I915_WRITE(CDCLK_CTL, val); |
| 5443 | } |
| 5444 | |
| 5445 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5446 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5447 | DIV_ROUND_UP(frequency, 25000)); |
| 5448 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5449 | |
| 5450 | if (ret) { |
| 5451 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
| 5452 | ret, frequency); |
| 5453 | return; |
| 5454 | } |
| 5455 | |
Damien Lespiau | a47871b | 2015-06-04 18:21:34 +0100 | [diff] [blame] | 5456 | intel_update_cdclk(dev); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | void broxton_init_cdclk(struct drm_device *dev) |
| 5460 | { |
| 5461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5462 | uint32_t val; |
| 5463 | |
| 5464 | /* |
| 5465 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT |
| 5466 | * or else the reset will hang because there is no PCH to respond. |
| 5467 | * Move the handshake programming to initialization sequence. |
| 5468 | * Previously was left up to BIOS. |
| 5469 | */ |
| 5470 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 5471 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; |
| 5472 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); |
| 5473 | |
| 5474 | /* Enable PG1 for cdclk */ |
| 5475 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 5476 | |
| 5477 | /* check if cd clock is enabled */ |
| 5478 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { |
| 5479 | DRM_DEBUG_KMS("Display already initialized\n"); |
| 5480 | return; |
| 5481 | } |
| 5482 | |
| 5483 | /* |
| 5484 | * FIXME: |
| 5485 | * - The initial CDCLK needs to be read from VBT. |
| 5486 | * Need to make this change after VBT has changes for BXT. |
| 5487 | * - check if setting the max (or any) cdclk freq is really necessary |
| 5488 | * here, it belongs to modeset time |
| 5489 | */ |
| 5490 | broxton_set_cdclk(dev, 624000); |
| 5491 | |
| 5492 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5493 | POSTING_READ(DBUF_CTL); |
| 5494 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5495 | udelay(10); |
| 5496 | |
| 5497 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5498 | DRM_ERROR("DBuf power enable timeout!\n"); |
| 5499 | } |
| 5500 | |
| 5501 | void broxton_uninit_cdclk(struct drm_device *dev) |
| 5502 | { |
| 5503 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5504 | |
| 5505 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5506 | POSTING_READ(DBUF_CTL); |
| 5507 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5508 | udelay(10); |
| 5509 | |
| 5510 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5511 | DRM_ERROR("DBuf power disable timeout!\n"); |
| 5512 | |
| 5513 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ |
| 5514 | broxton_set_cdclk(dev, 19200); |
| 5515 | |
| 5516 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
| 5517 | } |
| 5518 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5519 | static const struct skl_cdclk_entry { |
| 5520 | unsigned int freq; |
| 5521 | unsigned int vco; |
| 5522 | } skl_cdclk_frequencies[] = { |
| 5523 | { .freq = 308570, .vco = 8640 }, |
| 5524 | { .freq = 337500, .vco = 8100 }, |
| 5525 | { .freq = 432000, .vco = 8640 }, |
| 5526 | { .freq = 450000, .vco = 8100 }, |
| 5527 | { .freq = 540000, .vco = 8100 }, |
| 5528 | { .freq = 617140, .vco = 8640 }, |
| 5529 | { .freq = 675000, .vco = 8100 }, |
| 5530 | }; |
| 5531 | |
| 5532 | static unsigned int skl_cdclk_decimal(unsigned int freq) |
| 5533 | { |
| 5534 | return (freq - 1000) / 500; |
| 5535 | } |
| 5536 | |
| 5537 | static unsigned int skl_cdclk_get_vco(unsigned int freq) |
| 5538 | { |
| 5539 | unsigned int i; |
| 5540 | |
| 5541 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { |
| 5542 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; |
| 5543 | |
| 5544 | if (e->freq == freq) |
| 5545 | return e->vco; |
| 5546 | } |
| 5547 | |
| 5548 | return 8100; |
| 5549 | } |
| 5550 | |
| 5551 | static void |
| 5552 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) |
| 5553 | { |
| 5554 | unsigned int min_freq; |
| 5555 | u32 val; |
| 5556 | |
| 5557 | /* select the minimum CDCLK before enabling DPLL 0 */ |
| 5558 | val = I915_READ(CDCLK_CTL); |
| 5559 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; |
| 5560 | val |= CDCLK_FREQ_337_308; |
| 5561 | |
| 5562 | if (required_vco == 8640) |
| 5563 | min_freq = 308570; |
| 5564 | else |
| 5565 | min_freq = 337500; |
| 5566 | |
| 5567 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); |
| 5568 | |
| 5569 | I915_WRITE(CDCLK_CTL, val); |
| 5570 | POSTING_READ(CDCLK_CTL); |
| 5571 | |
| 5572 | /* |
| 5573 | * We always enable DPLL0 with the lowest link rate possible, but still |
| 5574 | * taking into account the VCO required to operate the eDP panel at the |
| 5575 | * desired frequency. The usual DP link rates operate with a VCO of |
| 5576 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. |
| 5577 | * The modeset code is responsible for the selection of the exact link |
| 5578 | * rate later on, with the constraint of choosing a frequency that |
| 5579 | * works with required_vco. |
| 5580 | */ |
| 5581 | val = I915_READ(DPLL_CTRL1); |
| 5582 | |
| 5583 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 5584 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
| 5585 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); |
| 5586 | if (required_vco == 8640) |
| 5587 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
| 5588 | SKL_DPLL0); |
| 5589 | else |
| 5590 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
| 5591 | SKL_DPLL0); |
| 5592 | |
| 5593 | I915_WRITE(DPLL_CTRL1, val); |
| 5594 | POSTING_READ(DPLL_CTRL1); |
| 5595 | |
| 5596 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); |
| 5597 | |
| 5598 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) |
| 5599 | DRM_ERROR("DPLL0 not locked\n"); |
| 5600 | } |
| 5601 | |
| 5602 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) |
| 5603 | { |
| 5604 | int ret; |
| 5605 | u32 val; |
| 5606 | |
| 5607 | /* inform PCU we want to change CDCLK */ |
| 5608 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; |
| 5609 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5610 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); |
| 5611 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5612 | |
| 5613 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); |
| 5614 | } |
| 5615 | |
| 5616 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) |
| 5617 | { |
| 5618 | unsigned int i; |
| 5619 | |
| 5620 | for (i = 0; i < 15; i++) { |
| 5621 | if (skl_cdclk_pcu_ready(dev_priv)) |
| 5622 | return true; |
| 5623 | udelay(10); |
| 5624 | } |
| 5625 | |
| 5626 | return false; |
| 5627 | } |
| 5628 | |
| 5629 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) |
| 5630 | { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5631 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5632 | u32 freq_select, pcu_ack; |
| 5633 | |
| 5634 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); |
| 5635 | |
| 5636 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { |
| 5637 | DRM_ERROR("failed to inform PCU about cdclk change\n"); |
| 5638 | return; |
| 5639 | } |
| 5640 | |
| 5641 | /* set CDCLK_CTL */ |
| 5642 | switch(freq) { |
| 5643 | case 450000: |
| 5644 | case 432000: |
| 5645 | freq_select = CDCLK_FREQ_450_432; |
| 5646 | pcu_ack = 1; |
| 5647 | break; |
| 5648 | case 540000: |
| 5649 | freq_select = CDCLK_FREQ_540; |
| 5650 | pcu_ack = 2; |
| 5651 | break; |
| 5652 | case 308570: |
| 5653 | case 337500: |
| 5654 | default: |
| 5655 | freq_select = CDCLK_FREQ_337_308; |
| 5656 | pcu_ack = 0; |
| 5657 | break; |
| 5658 | case 617140: |
| 5659 | case 675000: |
| 5660 | freq_select = CDCLK_FREQ_675_617; |
| 5661 | pcu_ack = 3; |
| 5662 | break; |
| 5663 | } |
| 5664 | |
| 5665 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); |
| 5666 | POSTING_READ(CDCLK_CTL); |
| 5667 | |
| 5668 | /* inform PCU of the change */ |
| 5669 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5670 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); |
| 5671 | mutex_unlock(&dev_priv->rps.hw_lock); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5672 | |
| 5673 | intel_update_cdclk(dev); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
| 5677 | { |
| 5678 | /* disable DBUF power */ |
| 5679 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
| 5680 | POSTING_READ(DBUF_CTL); |
| 5681 | |
| 5682 | udelay(10); |
| 5683 | |
| 5684 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5685 | DRM_ERROR("DBuf power disable timeout\n"); |
| 5686 | |
Imre Deak | ab96c1ee | 2015-11-04 19:24:18 +0200 | [diff] [blame] | 5687 | /* disable DPLL0 */ |
| 5688 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); |
| 5689 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) |
| 5690 | DRM_ERROR("Couldn't disable DPLL0\n"); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | void skl_init_cdclk(struct drm_i915_private *dev_priv) |
| 5694 | { |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5695 | unsigned int required_vco; |
| 5696 | |
Gary Wang | 39d9b85 | 2015-08-28 16:40:34 +0800 | [diff] [blame] | 5697 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
| 5698 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { |
| 5699 | /* enable DPLL0 */ |
| 5700 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); |
| 5701 | skl_dpll0_enable(dev_priv, required_vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5704 | /* set CDCLK to the frequency the BIOS chose */ |
| 5705 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); |
| 5706 | |
| 5707 | /* enable DBUF power */ |
| 5708 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
| 5709 | POSTING_READ(DBUF_CTL); |
| 5710 | |
| 5711 | udelay(10); |
| 5712 | |
| 5713 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5714 | DRM_ERROR("DBuf power enable timeout\n"); |
| 5715 | } |
| 5716 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5717 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
| 5718 | { |
| 5719 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 5720 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 5721 | int freq = dev_priv->skl_boot_cdclk; |
| 5722 | |
Shobhit Kumar | f1b391a | 2015-11-05 18:05:32 +0530 | [diff] [blame] | 5723 | /* |
| 5724 | * check if the pre-os intialized the display |
| 5725 | * There is SWF18 scratchpad register defined which is set by the |
| 5726 | * pre-os which can be used by the OS drivers to check the status |
| 5727 | */ |
| 5728 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) |
| 5729 | goto sanitize; |
| 5730 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5731 | /* Is PLL enabled and locked ? */ |
| 5732 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) |
| 5733 | goto sanitize; |
| 5734 | |
| 5735 | /* DPLL okay; verify the cdclock |
| 5736 | * |
| 5737 | * Noticed in some instances that the freq selection is correct but |
| 5738 | * decimal part is programmed wrong from BIOS where pre-os does not |
| 5739 | * enable display. Verify the same as well. |
| 5740 | */ |
| 5741 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) |
| 5742 | /* All well; nothing to sanitize */ |
| 5743 | return false; |
| 5744 | sanitize: |
| 5745 | /* |
| 5746 | * As of now initialize with max cdclk till |
| 5747 | * we get dynamic cdclk support |
| 5748 | * */ |
| 5749 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; |
| 5750 | skl_init_cdclk(dev_priv); |
| 5751 | |
| 5752 | /* we did have to sanitize */ |
| 5753 | return true; |
| 5754 | } |
| 5755 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5756 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5757 | static void valleyview_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); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5764 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5765 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5766 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5767 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5768 | cmd = 1; |
| 5769 | else |
| 5770 | cmd = 0; |
| 5771 | |
| 5772 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5773 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5774 | val &= ~DSPFREQGUAR_MASK; |
| 5775 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5776 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5777 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5778 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5779 | 50)) { |
| 5780 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5781 | } |
| 5782 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5783 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5784 | mutex_lock(&dev_priv->sb_lock); |
| 5785 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5786 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5787 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5788 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5789 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5790 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5791 | /* adjust cdclk divider */ |
| 5792 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5793 | val &= ~CCK_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5794 | val |= divider; |
| 5795 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5796 | |
| 5797 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5798 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5799 | 50)) |
| 5800 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5801 | } |
| 5802 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5803 | /* adjust self-refresh exit latency value */ |
| 5804 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5805 | val &= ~0x7f; |
| 5806 | |
| 5807 | /* |
| 5808 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5809 | * so that the core display fetch happens in time to avoid underruns. |
| 5810 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5811 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5812 | val |= 4500 / 250; /* 4.5 usec */ |
| 5813 | else |
| 5814 | val |= 3000 / 250; /* 3.0 usec */ |
| 5815 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5816 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5817 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5818 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5819 | intel_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5820 | } |
| 5821 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5822 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5823 | { |
| 5824 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5825 | u32 val, cmd; |
| 5826 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5827 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5828 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5829 | |
| 5830 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5831 | case 333333: |
| 5832 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5833 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5834 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5835 | break; |
| 5836 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5837 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5838 | return; |
| 5839 | } |
| 5840 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5841 | /* |
| 5842 | * Specs are full of misinformation, but testing on actual |
| 5843 | * hardware has shown that we just need to write the desired |
| 5844 | * CCK divider into the Punit register. |
| 5845 | */ |
| 5846 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5847 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5848 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5849 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5850 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5851 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5852 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5853 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5854 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5855 | 50)) { |
| 5856 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5857 | } |
| 5858 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5859 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5860 | intel_update_cdclk(dev); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5861 | } |
| 5862 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5863 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5864 | int max_pixclk) |
| 5865 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5866 | 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] | 5867 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5868 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5869 | /* |
| 5870 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5871 | * 200MHz |
| 5872 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5873 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5874 | * 400MHz (VLV only) |
| 5875 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5876 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5877 | * |
| 5878 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5879 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5880 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5881 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5882 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5883 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5884 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5885 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5886 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5887 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5888 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5889 | else |
| 5890 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5891 | } |
| 5892 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5893 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5894 | int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5895 | { |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5896 | /* |
| 5897 | * FIXME: |
| 5898 | * - remove the guardband, it's not needed on BXT |
| 5899 | * - set 19.2MHz bypass frequency if there are no active pipes |
| 5900 | */ |
| 5901 | if (max_pixclk > 576000*9/10) |
| 5902 | return 624000; |
| 5903 | else if (max_pixclk > 384000*9/10) |
| 5904 | return 576000; |
| 5905 | else if (max_pixclk > 288000*9/10) |
| 5906 | return 384000; |
| 5907 | else if (max_pixclk > 144000*9/10) |
| 5908 | return 288000; |
| 5909 | else |
| 5910 | return 144000; |
| 5911 | } |
| 5912 | |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 5913 | /* Compute the max pixel clock for new configuration. */ |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5914 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 5915 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5916 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5917 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 5918 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5919 | struct drm_crtc *crtc; |
| 5920 | struct drm_crtc_state *crtc_state; |
| 5921 | unsigned max_pixclk = 0, i; |
| 5922 | enum pipe pipe; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5923 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5924 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 5925 | sizeof(intel_state->min_pixclk)); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5926 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5927 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 5928 | int pixclk = 0; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5929 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5930 | if (crtc_state->enable) |
| 5931 | pixclk = crtc_state->adjusted_mode.crtc_clock; |
| 5932 | |
| 5933 | intel_state->min_pixclk[i] = pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5936 | for_each_pipe(dev_priv, pipe) |
| 5937 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); |
| 5938 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5939 | return max_pixclk; |
| 5940 | } |
| 5941 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5942 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
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 | struct drm_device *dev = state->dev; |
| 5945 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5946 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5947 | struct intel_atomic_state *intel_state = |
| 5948 | to_intel_atomic_state(state); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5949 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5950 | if (max_pixclk < 0) |
| 5951 | return max_pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5952 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5953 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5954 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5955 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5956 | if (!intel_state->active_crtcs) |
| 5957 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); |
| 5958 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5959 | return 0; |
| 5960 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5961 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5962 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 5963 | { |
| 5964 | struct drm_device *dev = state->dev; |
| 5965 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5966 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5967 | struct intel_atomic_state *intel_state = |
| 5968 | to_intel_atomic_state(state); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5969 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5970 | if (max_pixclk < 0) |
| 5971 | return max_pixclk; |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5972 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5973 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5974 | broxton_calc_cdclk(dev_priv, max_pixclk); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5975 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5976 | if (!intel_state->active_crtcs) |
| 5977 | intel_state->dev_cdclk = broxton_calc_cdclk(dev_priv, 0); |
| 5978 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5979 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5980 | } |
| 5981 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5982 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5983 | { |
| 5984 | unsigned int credits, default_credits; |
| 5985 | |
| 5986 | if (IS_CHERRYVIEW(dev_priv)) |
| 5987 | default_credits = PFI_CREDIT(12); |
| 5988 | else |
| 5989 | default_credits = PFI_CREDIT(8); |
| 5990 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 5991 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5992 | /* CHV suggested value is 31 or 63 */ |
| 5993 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | fcc0008 | 2015-05-26 20:22:40 +0300 | [diff] [blame] | 5994 | credits = PFI_CREDIT_63; |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5995 | else |
| 5996 | credits = PFI_CREDIT(15); |
| 5997 | } else { |
| 5998 | credits = default_credits; |
| 5999 | } |
| 6000 | |
| 6001 | /* |
| 6002 | * WA - write default credits before re-programming |
| 6003 | * FIXME: should we also set the resend bit here? |
| 6004 | */ |
| 6005 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6006 | default_credits); |
| 6007 | |
| 6008 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6009 | credits | PFI_CREDIT_RESEND); |
| 6010 | |
| 6011 | /* |
| 6012 | * FIXME is this guaranteed to clear |
| 6013 | * immediately or should we poll for it? |
| 6014 | */ |
| 6015 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 6016 | } |
| 6017 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6018 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6019 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 6020 | struct drm_device *dev = old_state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6021 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6022 | struct intel_atomic_state *old_intel_state = |
| 6023 | to_intel_atomic_state(old_state); |
| 6024 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6025 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6026 | /* |
| 6027 | * FIXME: We can end up here with all power domains off, yet |
| 6028 | * with a CDCLK frequency other than the minimum. To account |
| 6029 | * for this take the PIPE-A power domain, which covers the HW |
| 6030 | * blocks needed for the following programming. This can be |
| 6031 | * removed once it's guaranteed that we get here either with |
| 6032 | * the minimum CDCLK set, or the required power domains |
| 6033 | * enabled. |
| 6034 | */ |
| 6035 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6036 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6037 | if (IS_CHERRYVIEW(dev)) |
| 6038 | cherryview_set_cdclk(dev, req_cdclk); |
| 6039 | else |
| 6040 | valleyview_set_cdclk(dev, req_cdclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6041 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6042 | vlv_program_pfi_credits(dev_priv); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 6043 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6044 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6045 | } |
| 6046 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6047 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 6048 | { |
| 6049 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6050 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6051 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6052 | struct intel_encoder *encoder; |
| 6053 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6054 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6055 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6056 | return; |
| 6057 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6058 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6059 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6060 | |
| 6061 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6062 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6063 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6064 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 6065 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6066 | |
| 6067 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6068 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6069 | } |
| 6070 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6071 | i9xx_set_pipeconf(intel_crtc); |
| 6072 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6073 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6074 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6075 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6076 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6077 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6078 | if (encoder->pre_pll_enable) |
| 6079 | encoder->pre_pll_enable(encoder); |
| 6080 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 6081 | if (!intel_crtc->config->has_dsi_encoder) { |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6082 | if (IS_CHERRYVIEW(dev)) { |
| 6083 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6084 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6085 | } else { |
| 6086 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6087 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6088 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6089 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6090 | |
| 6091 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6092 | if (encoder->pre_enable) |
| 6093 | encoder->pre_enable(encoder); |
| 6094 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6095 | i9xx_pfit_enable(intel_crtc); |
| 6096 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 6097 | intel_color_load_luts(crtc); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6098 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 6099 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6100 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6101 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6102 | assert_vblank_disabled(crtc); |
| 6103 | drm_crtc_vblank_on(crtc); |
| 6104 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6105 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6106 | encoder->enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6107 | } |
| 6108 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6109 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 6110 | { |
| 6111 | struct drm_device *dev = crtc->base.dev; |
| 6112 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6113 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6114 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 6115 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6116 | } |
| 6117 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6118 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6119 | { |
| 6120 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6121 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6122 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6123 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6124 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6125 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6126 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6127 | return; |
| 6128 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6129 | i9xx_set_pll_dividers(intel_crtc); |
| 6130 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6131 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6132 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6133 | |
| 6134 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6135 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6136 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6137 | i9xx_set_pipeconf(intel_crtc); |
| 6138 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6139 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6140 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6141 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6142 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6143 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 6144 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6145 | if (encoder->pre_enable) |
| 6146 | encoder->pre_enable(encoder); |
| 6147 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6148 | i9xx_enable_pll(intel_crtc); |
| 6149 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6150 | i9xx_pfit_enable(intel_crtc); |
| 6151 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 6152 | intel_color_load_luts(crtc); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6153 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 6154 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6155 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6156 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6157 | assert_vblank_disabled(crtc); |
| 6158 | drm_crtc_vblank_on(crtc); |
| 6159 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6160 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6161 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6162 | } |
| 6163 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6164 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6165 | { |
| 6166 | struct drm_device *dev = crtc->base.dev; |
| 6167 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6168 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6169 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6170 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6171 | |
| 6172 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6173 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6174 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6175 | I915_READ(PFIT_CONTROL)); |
| 6176 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6177 | } |
| 6178 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6179 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 6180 | { |
| 6181 | struct drm_device *dev = crtc->dev; |
| 6182 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6183 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6184 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6185 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6186 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6187 | /* |
| 6188 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6189 | * wait for planes to fully turn off before disabling the pipe. |
| 6190 | */ |
Ander Conselvan de Oliveira | 90e83e5 | 2016-03-22 10:11:24 +0200 | [diff] [blame] | 6191 | if (IS_GEN2(dev)) |
| 6192 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6193 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6194 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6195 | encoder->disable(encoder); |
| 6196 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6197 | drm_crtc_vblank_off(crtc); |
| 6198 | assert_vblank_disabled(crtc); |
| 6199 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6200 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6201 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6202 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6203 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6204 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6205 | if (encoder->post_disable) |
| 6206 | encoder->post_disable(encoder); |
| 6207 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 6208 | if (!intel_crtc->config->has_dsi_encoder) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6209 | if (IS_CHERRYVIEW(dev)) |
| 6210 | chv_disable_pll(dev_priv, pipe); |
| 6211 | else if (IS_VALLEYVIEW(dev)) |
| 6212 | vlv_disable_pll(dev_priv, pipe); |
| 6213 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6214 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6215 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6216 | |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6217 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6218 | if (encoder->post_pll_disable) |
| 6219 | encoder->post_pll_disable(encoder); |
| 6220 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6221 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6222 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6225 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6226 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6227 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6228 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6229 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6230 | enum intel_display_power_domain domain; |
| 6231 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6232 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6233 | if (!intel_crtc->active) |
| 6234 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6235 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6236 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
Maarten Lankhorst | fc32b1f | 2015-10-19 17:09:23 +0200 | [diff] [blame] | 6237 | WARN_ON(intel_crtc->unpin_work); |
| 6238 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 6239 | intel_pre_disable_primary_noatomic(crtc); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6240 | |
| 6241 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); |
| 6242 | to_intel_plane_state(crtc->primary->state)->visible = false; |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6243 | } |
| 6244 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6245 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6246 | |
| 6247 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was enabled, now disabled\n", |
| 6248 | crtc->base.id); |
| 6249 | |
| 6250 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6251 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6252 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6253 | crtc->enabled = false; |
| 6254 | crtc->state->connector_mask = 0; |
| 6255 | crtc->state->encoder_mask = 0; |
| 6256 | |
| 6257 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6258 | encoder->base.crtc = NULL; |
| 6259 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6260 | intel_fbc_disable(intel_crtc); |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6261 | intel_update_watermarks(crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6262 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6263 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6264 | domains = intel_crtc->enabled_power_domains; |
| 6265 | for_each_power_domain(domain, domains) |
| 6266 | intel_display_power_put(dev_priv, domain); |
| 6267 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6268 | |
| 6269 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
| 6270 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6271 | } |
| 6272 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6273 | /* |
| 6274 | * turn all crtc's off, but do not adjust state |
| 6275 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6276 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6277 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6278 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6279 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6280 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6281 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6282 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6283 | state = drm_atomic_helper_suspend(dev); |
| 6284 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6285 | if (ret) |
| 6286 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6287 | else |
| 6288 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6289 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6290 | } |
| 6291 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6292 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6293 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6294 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6295 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6296 | drm_encoder_cleanup(encoder); |
| 6297 | kfree(intel_encoder); |
| 6298 | } |
| 6299 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6300 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6301 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 6302 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6303 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6304 | struct drm_crtc *crtc = connector->base.state->crtc; |
| 6305 | |
| 6306 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6307 | connector->base.base.id, |
| 6308 | connector->base.name); |
| 6309 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6310 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6311 | struct intel_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6312 | struct drm_connector_state *conn_state = connector->base.state; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6313 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6314 | I915_STATE_WARN(!crtc, |
| 6315 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6316 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6317 | if (!crtc) |
| 6318 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6319 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6320 | I915_STATE_WARN(!crtc->state->active, |
| 6321 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6322 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6323 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6324 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6325 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6326 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6327 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6328 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6329 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6330 | "attached encoder crtc differs from connector crtc\n"); |
| 6331 | } else { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6332 | I915_STATE_WARN(crtc && crtc->state->active, |
| 6333 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6334 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
| 6335 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6339 | int intel_connector_init(struct intel_connector *connector) |
| 6340 | { |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6341 | drm_atomic_helper_connector_reset(&connector->base); |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6342 | |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6343 | if (!connector->base.state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6344 | return -ENOMEM; |
| 6345 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6346 | return 0; |
| 6347 | } |
| 6348 | |
| 6349 | struct intel_connector *intel_connector_alloc(void) |
| 6350 | { |
| 6351 | struct intel_connector *connector; |
| 6352 | |
| 6353 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6354 | if (!connector) |
| 6355 | return NULL; |
| 6356 | |
| 6357 | if (intel_connector_init(connector) < 0) { |
| 6358 | kfree(connector); |
| 6359 | return NULL; |
| 6360 | } |
| 6361 | |
| 6362 | return connector; |
| 6363 | } |
| 6364 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6365 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6366 | * one connector and no cloning and hence the encoder state determines the state |
| 6367 | * of the connector. */ |
| 6368 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6369 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6370 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6371 | struct intel_encoder *encoder = connector->encoder; |
| 6372 | |
| 6373 | return encoder->get_hw_state(encoder, &pipe); |
| 6374 | } |
| 6375 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6376 | 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] | 6377 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6378 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6379 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6380 | |
| 6381 | return 0; |
| 6382 | } |
| 6383 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6384 | 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] | 6385 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6386 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6387 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6388 | struct intel_crtc *other_crtc; |
| 6389 | struct intel_crtc_state *other_crtc_state; |
| 6390 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6391 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6392 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6393 | if (pipe_config->fdi_lanes > 4) { |
| 6394 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6395 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6396 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6397 | } |
| 6398 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 6399 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6400 | if (pipe_config->fdi_lanes > 2) { |
| 6401 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6402 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6403 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6404 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6405 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6410 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6411 | |
| 6412 | /* Ivybridge 3 pipe is really complicated */ |
| 6413 | switch (pipe) { |
| 6414 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6415 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6416 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6417 | if (pipe_config->fdi_lanes <= 2) |
| 6418 | return 0; |
| 6419 | |
| 6420 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 6421 | other_crtc_state = |
| 6422 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6423 | if (IS_ERR(other_crtc_state)) |
| 6424 | return PTR_ERR(other_crtc_state); |
| 6425 | |
| 6426 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6427 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6428 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6429 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6430 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6431 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6432 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6433 | if (pipe_config->fdi_lanes > 2) { |
| 6434 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6435 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6436 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6437 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6438 | |
| 6439 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 6440 | other_crtc_state = |
| 6441 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6442 | if (IS_ERR(other_crtc_state)) |
| 6443 | return PTR_ERR(other_crtc_state); |
| 6444 | |
| 6445 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6446 | 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] | 6447 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6448 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6449 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6450 | default: |
| 6451 | BUG(); |
| 6452 | } |
| 6453 | } |
| 6454 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6455 | #define RETRY 1 |
| 6456 | 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] | 6457 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6458 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6459 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6460 | const 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] | 6461 | int lane, link_bw, fdi_dotclock, ret; |
| 6462 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6463 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6464 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6465 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6466 | * each output octet as 10 bits. The actual frequency |
| 6467 | * is stored as a divider into a 100MHz clock, and the |
| 6468 | * mode pixel clock is stored in units of 1KHz. |
| 6469 | * Hence the bw of each lane in terms of the mode signal |
| 6470 | * is: |
| 6471 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6472 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6473 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6474 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6475 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6476 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6477 | pipe_config->pipe_bpp); |
| 6478 | |
| 6479 | pipe_config->fdi_lanes = lane; |
| 6480 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6481 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6482 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6483 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6484 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6485 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6486 | pipe_config->pipe_bpp -= 2*3; |
| 6487 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6488 | pipe_config->pipe_bpp); |
| 6489 | needs_recompute = true; |
| 6490 | pipe_config->bw_constrained = true; |
| 6491 | |
| 6492 | goto retry; |
| 6493 | } |
| 6494 | |
| 6495 | if (needs_recompute) |
| 6496 | return RETRY; |
| 6497 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6498 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6499 | } |
| 6500 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6501 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
| 6502 | struct intel_crtc_state *pipe_config) |
| 6503 | { |
| 6504 | if (pipe_config->pipe_bpp > 24) |
| 6505 | return false; |
| 6506 | |
| 6507 | /* HSW can handle pixel rate up to cdclk? */ |
| 6508 | if (IS_HASWELL(dev_priv->dev)) |
| 6509 | return true; |
| 6510 | |
| 6511 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6512 | * We compare against max which means we must take |
| 6513 | * the increased cdclk requirement into account when |
| 6514 | * calculating the new cdclk. |
| 6515 | * |
| 6516 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6517 | */ |
| 6518 | return ilk_pipe_pixel_rate(pipe_config) <= |
| 6519 | dev_priv->max_cdclk_freq * 95 / 100; |
| 6520 | } |
| 6521 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6522 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6523 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6524 | { |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6525 | struct drm_device *dev = crtc->base.dev; |
| 6526 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6527 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6528 | pipe_config->ips_enabled = i915.enable_ips && |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6529 | hsw_crtc_supports_ips(crtc) && |
| 6530 | pipe_config_supports_ips(dev_priv, pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6531 | } |
| 6532 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6533 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6534 | { |
| 6535 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6536 | |
| 6537 | /* GDG double wide on either pipe, otherwise pipe A only */ |
| 6538 | return INTEL_INFO(dev_priv)->gen < 4 && |
| 6539 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6540 | } |
| 6541 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6542 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6543 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6544 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6545 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 6546 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6547 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6548 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6549 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6550 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6551 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6552 | |
| 6553 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6554 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6555 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6556 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6557 | if (intel_crtc_supports_double_wide(crtc) && |
| 6558 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6559 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6560 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6561 | } |
| 6562 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6563 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6564 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6565 | adjusted_mode->crtc_clock, clock_limit, |
| 6566 | yesno(pipe_config->double_wide)); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6567 | return -EINVAL; |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6568 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6569 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6570 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6571 | /* |
| 6572 | * Pipe horizontal size must be even in: |
| 6573 | * - DVO ganged mode |
| 6574 | * - LVDS dual channel mode |
| 6575 | * - Double wide pipe |
| 6576 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6577 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6578 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 6579 | pipe_config->pipe_src_w &= ~1; |
| 6580 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6581 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6582 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6583 | */ |
| 6584 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6585 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6586 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6587 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 6588 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6589 | hsw_compute_ips_config(crtc, pipe_config); |
| 6590 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6591 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6592 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6593 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6594 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6595 | } |
| 6596 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6597 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 6598 | { |
| 6599 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6600 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 6601 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6602 | uint32_t linkrate; |
| 6603 | |
Damien Lespiau | 414355a | 2015-06-04 18:21:31 +0100 | [diff] [blame] | 6604 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6605 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6606 | |
| 6607 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 6608 | return 540000; |
| 6609 | |
| 6610 | linkrate = (I915_READ(DPLL_CTRL1) & |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6611 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6612 | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6613 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
| 6614 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6615 | /* vco 8640 */ |
| 6616 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6617 | case CDCLK_FREQ_450_432: |
| 6618 | return 432000; |
| 6619 | case CDCLK_FREQ_337_308: |
| 6620 | return 308570; |
| 6621 | case CDCLK_FREQ_675_617: |
| 6622 | return 617140; |
| 6623 | default: |
| 6624 | WARN(1, "Unknown cd freq selection\n"); |
| 6625 | } |
| 6626 | } else { |
| 6627 | /* vco 8100 */ |
| 6628 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6629 | case CDCLK_FREQ_450_432: |
| 6630 | return 450000; |
| 6631 | case CDCLK_FREQ_337_308: |
| 6632 | return 337500; |
| 6633 | case CDCLK_FREQ_675_617: |
| 6634 | return 675000; |
| 6635 | default: |
| 6636 | WARN(1, "Unknown cd freq selection\n"); |
| 6637 | } |
| 6638 | } |
| 6639 | |
| 6640 | /* error case, do as if DPLL0 isn't enabled */ |
| 6641 | return 24000; |
| 6642 | } |
| 6643 | |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6644 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
| 6645 | { |
| 6646 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6647 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6648 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; |
| 6649 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); |
| 6650 | int cdclk; |
| 6651 | |
| 6652 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) |
| 6653 | return 19200; |
| 6654 | |
| 6655 | cdclk = 19200 * pll_ratio / 2; |
| 6656 | |
| 6657 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { |
| 6658 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
| 6659 | return cdclk; /* 576MHz or 624MHz */ |
| 6660 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
| 6661 | return cdclk * 2 / 3; /* 384MHz */ |
| 6662 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
| 6663 | return cdclk / 2; /* 288MHz */ |
| 6664 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
| 6665 | return cdclk / 4; /* 144MHz */ |
| 6666 | } |
| 6667 | |
| 6668 | /* error case, do as if DE PLL isn't enabled */ |
| 6669 | return 19200; |
| 6670 | } |
| 6671 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6672 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 6673 | { |
| 6674 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6675 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6676 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6677 | |
| 6678 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6679 | return 800000; |
| 6680 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6681 | return 450000; |
| 6682 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6683 | return 450000; |
| 6684 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6685 | return 540000; |
| 6686 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6687 | return 337500; |
| 6688 | else |
| 6689 | return 675000; |
| 6690 | } |
| 6691 | |
| 6692 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6693 | { |
| 6694 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6695 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6696 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6697 | |
| 6698 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6699 | return 800000; |
| 6700 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6701 | return 450000; |
| 6702 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6703 | return 450000; |
| 6704 | else if (IS_HSW_ULT(dev)) |
| 6705 | return 337500; |
| 6706 | else |
| 6707 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6708 | } |
| 6709 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6710 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6711 | { |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6712 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
| 6713 | CCK_DISPLAY_CLOCK_CONTROL); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6716 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6717 | { |
| 6718 | return 450000; |
| 6719 | } |
| 6720 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6721 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6722 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6723 | return 400000; |
| 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 i915_get_display_clock_speed(struct drm_device *dev) |
| 6727 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6728 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6729 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6730 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6731 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6732 | { |
| 6733 | return 200000; |
| 6734 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6735 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6736 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6737 | { |
| 6738 | u16 gcfgc = 0; |
| 6739 | |
| 6740 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6741 | |
| 6742 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6743 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6744 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6745 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6746 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6747 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6748 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6749 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6750 | return 200000; |
| 6751 | default: |
| 6752 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6753 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6754 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6755 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6756 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6757 | } |
| 6758 | } |
| 6759 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6760 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6761 | { |
| 6762 | u16 gcfgc = 0; |
| 6763 | |
| 6764 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6765 | |
| 6766 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6767 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6768 | else { |
| 6769 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6770 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6771 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6772 | default: |
| 6773 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6774 | return 190000; |
| 6775 | } |
| 6776 | } |
| 6777 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6778 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6779 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6780 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6781 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6784 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6785 | { |
| 6786 | u16 hpllcc = 0; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6787 | |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 6788 | /* |
| 6789 | * 852GM/852GMV only supports 133 MHz and the HPLLCC |
| 6790 | * encoding is different :( |
| 6791 | * FIXME is this the right way to detect 852GM/852GMV? |
| 6792 | */ |
| 6793 | if (dev->pdev->revision == 0x1) |
| 6794 | return 133333; |
| 6795 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6796 | pci_bus_read_config_word(dev->pdev->bus, |
| 6797 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); |
| 6798 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6799 | /* Assume that the hardware is in the high speed state. This |
| 6800 | * should be the default. |
| 6801 | */ |
| 6802 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6803 | case GC_CLOCK_133_200: |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6804 | case GC_CLOCK_133_200_2: |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6805 | case GC_CLOCK_100_200: |
| 6806 | return 200000; |
| 6807 | case GC_CLOCK_166_250: |
| 6808 | return 250000; |
| 6809 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6810 | return 133333; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6811 | case GC_CLOCK_133_266: |
| 6812 | case GC_CLOCK_133_266_2: |
| 6813 | case GC_CLOCK_166_266: |
| 6814 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
| 6817 | /* Shouldn't happen */ |
| 6818 | return 0; |
| 6819 | } |
| 6820 | |
| 6821 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6822 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6823 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6824 | } |
| 6825 | |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6826 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
| 6827 | { |
| 6828 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6829 | static const unsigned int blb_vco[8] = { |
| 6830 | [0] = 3200000, |
| 6831 | [1] = 4000000, |
| 6832 | [2] = 5333333, |
| 6833 | [3] = 4800000, |
| 6834 | [4] = 6400000, |
| 6835 | }; |
| 6836 | static const unsigned int pnv_vco[8] = { |
| 6837 | [0] = 3200000, |
| 6838 | [1] = 4000000, |
| 6839 | [2] = 5333333, |
| 6840 | [3] = 4800000, |
| 6841 | [4] = 2666667, |
| 6842 | }; |
| 6843 | static const unsigned int cl_vco[8] = { |
| 6844 | [0] = 3200000, |
| 6845 | [1] = 4000000, |
| 6846 | [2] = 5333333, |
| 6847 | [3] = 6400000, |
| 6848 | [4] = 3333333, |
| 6849 | [5] = 3566667, |
| 6850 | [6] = 4266667, |
| 6851 | }; |
| 6852 | static const unsigned int elk_vco[8] = { |
| 6853 | [0] = 3200000, |
| 6854 | [1] = 4000000, |
| 6855 | [2] = 5333333, |
| 6856 | [3] = 4800000, |
| 6857 | }; |
| 6858 | static const unsigned int ctg_vco[8] = { |
| 6859 | [0] = 3200000, |
| 6860 | [1] = 4000000, |
| 6861 | [2] = 5333333, |
| 6862 | [3] = 6400000, |
| 6863 | [4] = 2666667, |
| 6864 | [5] = 4266667, |
| 6865 | }; |
| 6866 | const unsigned int *vco_table; |
| 6867 | unsigned int vco; |
| 6868 | uint8_t tmp = 0; |
| 6869 | |
| 6870 | /* FIXME other chipsets? */ |
| 6871 | if (IS_GM45(dev)) |
| 6872 | vco_table = ctg_vco; |
| 6873 | else if (IS_G4X(dev)) |
| 6874 | vco_table = elk_vco; |
| 6875 | else if (IS_CRESTLINE(dev)) |
| 6876 | vco_table = cl_vco; |
| 6877 | else if (IS_PINEVIEW(dev)) |
| 6878 | vco_table = pnv_vco; |
| 6879 | else if (IS_G33(dev)) |
| 6880 | vco_table = blb_vco; |
| 6881 | else |
| 6882 | return 0; |
| 6883 | |
| 6884 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); |
| 6885 | |
| 6886 | vco = vco_table[tmp & 0x7]; |
| 6887 | if (vco == 0) |
| 6888 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); |
| 6889 | else |
| 6890 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); |
| 6891 | |
| 6892 | return vco; |
| 6893 | } |
| 6894 | |
| 6895 | static int gm45_get_display_clock_speed(struct drm_device *dev) |
| 6896 | { |
| 6897 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6898 | uint16_t tmp = 0; |
| 6899 | |
| 6900 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6901 | |
| 6902 | cdclk_sel = (tmp >> 12) & 0x1; |
| 6903 | |
| 6904 | switch (vco) { |
| 6905 | case 2666667: |
| 6906 | case 4000000: |
| 6907 | case 5333333: |
| 6908 | return cdclk_sel ? 333333 : 222222; |
| 6909 | case 3200000: |
| 6910 | return cdclk_sel ? 320000 : 228571; |
| 6911 | default: |
| 6912 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); |
| 6913 | return 222222; |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | static int i965gm_get_display_clock_speed(struct drm_device *dev) |
| 6918 | { |
| 6919 | static const uint8_t div_3200[] = { 16, 10, 8 }; |
| 6920 | static const uint8_t div_4000[] = { 20, 12, 10 }; |
| 6921 | static const uint8_t div_5333[] = { 24, 16, 14 }; |
| 6922 | const uint8_t *div_table; |
| 6923 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6924 | uint16_t tmp = 0; |
| 6925 | |
| 6926 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6927 | |
| 6928 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; |
| 6929 | |
| 6930 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6931 | goto fail; |
| 6932 | |
| 6933 | switch (vco) { |
| 6934 | case 3200000: |
| 6935 | div_table = div_3200; |
| 6936 | break; |
| 6937 | case 4000000: |
| 6938 | div_table = div_4000; |
| 6939 | break; |
| 6940 | case 5333333: |
| 6941 | div_table = div_5333; |
| 6942 | break; |
| 6943 | default: |
| 6944 | goto fail; |
| 6945 | } |
| 6946 | |
| 6947 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6948 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6949 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6950 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
| 6951 | return 200000; |
| 6952 | } |
| 6953 | |
| 6954 | static int g33_get_display_clock_speed(struct drm_device *dev) |
| 6955 | { |
| 6956 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; |
| 6957 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; |
| 6958 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; |
| 6959 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; |
| 6960 | const uint8_t *div_table; |
| 6961 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6962 | uint16_t tmp = 0; |
| 6963 | |
| 6964 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6965 | |
| 6966 | cdclk_sel = (tmp >> 4) & 0x7; |
| 6967 | |
| 6968 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6969 | goto fail; |
| 6970 | |
| 6971 | switch (vco) { |
| 6972 | case 3200000: |
| 6973 | div_table = div_3200; |
| 6974 | break; |
| 6975 | case 4000000: |
| 6976 | div_table = div_4000; |
| 6977 | break; |
| 6978 | case 4800000: |
| 6979 | div_table = div_4800; |
| 6980 | break; |
| 6981 | case 5333333: |
| 6982 | div_table = div_5333; |
| 6983 | break; |
| 6984 | default: |
| 6985 | goto fail; |
| 6986 | } |
| 6987 | |
| 6988 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6989 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6990 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6991 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
| 6992 | return 190476; |
| 6993 | } |
| 6994 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6995 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6996 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6997 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6998 | while (*num > DATA_LINK_M_N_MASK || |
| 6999 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7000 | *num >>= 1; |
| 7001 | *den >>= 1; |
| 7002 | } |
| 7003 | } |
| 7004 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7005 | static void compute_m_n(unsigned int m, unsigned int n, |
| 7006 | uint32_t *ret_m, uint32_t *ret_n) |
| 7007 | { |
| 7008 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 7009 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 7010 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 7011 | } |
| 7012 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7013 | void |
| 7014 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 7015 | int pixel_clock, int link_clock, |
| 7016 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7017 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7018 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7019 | |
| 7020 | compute_m_n(bits_per_pixel * pixel_clock, |
| 7021 | link_clock * nlanes * 8, |
| 7022 | &m_n->gmch_m, &m_n->gmch_n); |
| 7023 | |
| 7024 | compute_m_n(pixel_clock, link_clock, |
| 7025 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7026 | } |
| 7027 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7028 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 7029 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7030 | if (i915.panel_use_ssc >= 0) |
| 7031 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7032 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 7033 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7034 | } |
| 7035 | |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7036 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7037 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7038 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7039 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7040 | int refclk; |
| 7041 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7042 | WARN_ON(!crtc_state->base.state); |
| 7043 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7044 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 7045 | refclk = 100000; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7046 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7047 | intel_panel_use_ssc(dev_priv)) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7048 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7049 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7050 | } else if (!IS_GEN2(dev)) { |
| 7051 | refclk = 96000; |
| 7052 | } else { |
| 7053 | refclk = 48000; |
| 7054 | } |
| 7055 | |
| 7056 | return refclk; |
| 7057 | } |
| 7058 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7059 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7060 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 7061 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7062 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7063 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7064 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 7065 | { |
| 7066 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7067 | } |
| 7068 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7069 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7070 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7071 | intel_clock_t *reduced_clock) |
| 7072 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7073 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7074 | u32 fp, fp2 = 0; |
| 7075 | |
| 7076 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7077 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7078 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7079 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7080 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7081 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7082 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7083 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7084 | } |
| 7085 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7086 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7087 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7088 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7089 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7090 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7091 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7092 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7093 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7094 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7095 | } |
| 7096 | } |
| 7097 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7098 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 7099 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7100 | { |
| 7101 | u32 reg_val; |
| 7102 | |
| 7103 | /* |
| 7104 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 7105 | * and set it to a reasonable value instead. |
| 7106 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7107 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7108 | reg_val &= 0xffffff00; |
| 7109 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7110 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7111 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7112 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7113 | reg_val &= 0x8cffffff; |
| 7114 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7115 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7116 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7117 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7118 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7119 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7120 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7121 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7122 | reg_val &= 0x00ffffff; |
| 7123 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7124 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7125 | } |
| 7126 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7127 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 7128 | struct intel_link_m_n *m_n) |
| 7129 | { |
| 7130 | struct drm_device *dev = crtc->base.dev; |
| 7131 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7132 | int pipe = crtc->pipe; |
| 7133 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7134 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7135 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7136 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7137 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7141 | struct intel_link_m_n *m_n, |
| 7142 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7143 | { |
| 7144 | struct drm_device *dev = crtc->base.dev; |
| 7145 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7146 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7147 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7148 | |
| 7149 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7150 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7151 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7152 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7153 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7154 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 7155 | * for gen < 8) and if DRRS is supported (to make sure the |
| 7156 | * registers are not unnecessarily accessed). |
| 7157 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 7158 | 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] | 7159 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7160 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7161 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7162 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7163 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7164 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7165 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7166 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7167 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7168 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7169 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7170 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7171 | } |
| 7172 | } |
| 7173 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7174 | 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] | 7175 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7176 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 7177 | |
| 7178 | if (m_n == M1_N1) { |
| 7179 | dp_m_n = &crtc->config->dp_m_n; |
| 7180 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 7181 | } else if (m_n == M2_N2) { |
| 7182 | |
| 7183 | /* |
| 7184 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7185 | * needs to be programmed into M1_N1. |
| 7186 | */ |
| 7187 | dp_m_n = &crtc->config->dp_m2_n2; |
| 7188 | } else { |
| 7189 | DRM_ERROR("Unsupported divider value\n"); |
| 7190 | return; |
| 7191 | } |
| 7192 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7193 | if (crtc->config->has_pch_encoder) |
| 7194 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7195 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7196 | 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] | 7197 | } |
| 7198 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7199 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7200 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7201 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7202 | u32 dpll, dpll_md; |
| 7203 | |
| 7204 | /* |
| 7205 | * Enable DPIO clock input. We should never disable the reference |
| 7206 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 7207 | * on it. |
| 7208 | */ |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 7209 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
| 7210 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7211 | /* We should never disable this, set it here for state tracking */ |
| 7212 | if (crtc->pipe == PIPE_B) |
| 7213 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7214 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7215 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7216 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7217 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7218 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7219 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7220 | } |
| 7221 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7222 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7223 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7224 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7225 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7226 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7227 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7228 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7229 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7230 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7231 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7232 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7233 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7234 | bestn = pipe_config->dpll.n; |
| 7235 | bestm1 = pipe_config->dpll.m1; |
| 7236 | bestm2 = pipe_config->dpll.m2; |
| 7237 | bestp1 = pipe_config->dpll.p1; |
| 7238 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7239 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7240 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7241 | |
| 7242 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7243 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7244 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7245 | |
| 7246 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7247 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7248 | |
| 7249 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7250 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7251 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7252 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7253 | |
| 7254 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7255 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7256 | |
| 7257 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7258 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7259 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7260 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7261 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7262 | |
| 7263 | /* |
| 7264 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7265 | * but we don't support that). |
| 7266 | * Note: don't use the DAC post divider as it seems unstable. |
| 7267 | */ |
| 7268 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7269 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7270 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7271 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7272 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7273 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7274 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7275 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7276 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 7277 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7278 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7279 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7280 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7281 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7282 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7283 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7284 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7285 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7286 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7287 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7288 | 0x0df40000); |
| 7289 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7290 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7291 | 0x0df70000); |
| 7292 | } else { /* HDMI or VGA */ |
| 7293 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7294 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7295 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7296 | 0x0df70000); |
| 7297 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7298 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7299 | 0x0df40000); |
| 7300 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7301 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7302 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7303 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7304 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 7305 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7306 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7307 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7308 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7309 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7310 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7311 | } |
| 7312 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7313 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7314 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7315 | { |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 7316 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
| 7317 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7318 | DPLL_VCO_ENABLE; |
| 7319 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7320 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7321 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7322 | pipe_config->dpll_hw_state.dpll_md = |
| 7323 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7324 | } |
| 7325 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7326 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7327 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7328 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7329 | struct drm_device *dev = crtc->base.dev; |
| 7330 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7331 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 7332 | i915_reg_t dpll_reg = DPLL(crtc->pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7333 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7334 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7335 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7336 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7337 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7338 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7339 | bestn = pipe_config->dpll.n; |
| 7340 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7341 | bestm1 = pipe_config->dpll.m1; |
| 7342 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7343 | bestp1 = pipe_config->dpll.p1; |
| 7344 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7345 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7346 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7347 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7348 | |
| 7349 | /* |
| 7350 | * Enable Refclk and SSC |
| 7351 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7352 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7353 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7354 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7355 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7356 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7357 | /* p1 and p2 divider */ |
| 7358 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7359 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7360 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7361 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7362 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7363 | |
| 7364 | /* Feedback post-divider - m2 */ |
| 7365 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7366 | |
| 7367 | /* Feedback refclk divider - n and m1 */ |
| 7368 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7369 | DPIO_CHV_M1_DIV_BY_2 | |
| 7370 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7371 | |
| 7372 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7373 | 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] | 7374 | |
| 7375 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7376 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7377 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7378 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7379 | if (bestm2_frac) |
| 7380 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7381 | 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] | 7382 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7383 | /* Program digital lock detect threshold */ |
| 7384 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7385 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7386 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7387 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7388 | if (!bestm2_frac) |
| 7389 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7390 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7391 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7392 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7393 | if (vco == 5400000) { |
| 7394 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7395 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7396 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7397 | tribuf_calcntr = 0x9; |
| 7398 | } else if (vco <= 6200000) { |
| 7399 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7400 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7401 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7402 | tribuf_calcntr = 0x9; |
| 7403 | } else if (vco <= 6480000) { |
| 7404 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7405 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7406 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7407 | tribuf_calcntr = 0x8; |
| 7408 | } else { |
| 7409 | /* Not supported. Apply the same limits as in the max case */ |
| 7410 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7411 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7412 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7413 | tribuf_calcntr = 0; |
| 7414 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7415 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7416 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7417 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7418 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7419 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7420 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7421 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7422 | /* AFC Recal */ |
| 7423 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7424 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7425 | DPIO_AFC_RECAL); |
| 7426 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7427 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7428 | } |
| 7429 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7430 | /** |
| 7431 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7432 | * @dev_priv: i915 private structure |
| 7433 | * @pipe: pipe PLL to enable |
| 7434 | * @dpll: PLL configuration |
| 7435 | * |
| 7436 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7437 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7438 | * be enabled. |
| 7439 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7440 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 7441 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7442 | { |
| 7443 | struct intel_crtc *crtc = |
| 7444 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7445 | struct intel_crtc_state *pipe_config; |
| 7446 | |
| 7447 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7448 | if (!pipe_config) |
| 7449 | return -ENOMEM; |
| 7450 | |
| 7451 | pipe_config->base.crtc = &crtc->base; |
| 7452 | pipe_config->pixel_multiplier = 1; |
| 7453 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7454 | |
| 7455 | if (IS_CHERRYVIEW(dev)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7456 | chv_compute_dpll(crtc, pipe_config); |
| 7457 | chv_prepare_pll(crtc, pipe_config); |
| 7458 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7459 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7460 | vlv_compute_dpll(crtc, pipe_config); |
| 7461 | vlv_prepare_pll(crtc, pipe_config); |
| 7462 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7463 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7464 | |
| 7465 | kfree(pipe_config); |
| 7466 | |
| 7467 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7468 | } |
| 7469 | |
| 7470 | /** |
| 7471 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7472 | * @dev_priv: i915 private structure |
| 7473 | * @pipe: pipe PLL to disable |
| 7474 | * |
| 7475 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7476 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7477 | */ |
| 7478 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 7479 | { |
| 7480 | if (IS_CHERRYVIEW(dev)) |
| 7481 | chv_disable_pll(to_i915(dev), pipe); |
| 7482 | else |
| 7483 | vlv_disable_pll(to_i915(dev), pipe); |
| 7484 | } |
| 7485 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7486 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7487 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7488 | intel_clock_t *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7489 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7490 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7491 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7492 | u32 dpll; |
| 7493 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7494 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7495 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7496 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7497 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7498 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7499 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7500 | |
| 7501 | dpll = DPLL_VGA_MODE_DIS; |
| 7502 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7503 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7504 | dpll |= DPLLB_MODE_LVDS; |
| 7505 | else |
| 7506 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7507 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7508 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7509 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7510 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7511 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7512 | |
| 7513 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7514 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7515 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7516 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7517 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7518 | |
| 7519 | /* compute bitmask from p1 value */ |
| 7520 | if (IS_PINEVIEW(dev)) |
| 7521 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7522 | else { |
| 7523 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7524 | if (IS_G4X(dev) && reduced_clock) |
| 7525 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7526 | } |
| 7527 | switch (clock->p2) { |
| 7528 | case 5: |
| 7529 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7530 | break; |
| 7531 | case 7: |
| 7532 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7533 | break; |
| 7534 | case 10: |
| 7535 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7536 | break; |
| 7537 | case 14: |
| 7538 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7539 | break; |
| 7540 | } |
| 7541 | if (INTEL_INFO(dev)->gen >= 4) |
| 7542 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7543 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7544 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7545 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7546 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7547 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7548 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7549 | else |
| 7550 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7551 | |
| 7552 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7553 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7554 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7555 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7556 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7557 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7558 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7559 | } |
| 7560 | } |
| 7561 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7562 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7563 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7564 | intel_clock_t *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7565 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7566 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7567 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7568 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7569 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7570 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7571 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7572 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7573 | dpll = DPLL_VGA_MODE_DIS; |
| 7574 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7575 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7576 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7577 | } else { |
| 7578 | if (clock->p1 == 2) |
| 7579 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7580 | else |
| 7581 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7582 | if (clock->p2 == 4) |
| 7583 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7584 | } |
| 7585 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7586 | 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] | 7587 | dpll |= DPLL_DVO_2X_MODE; |
| 7588 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7589 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7590 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7591 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7592 | else |
| 7593 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7594 | |
| 7595 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7596 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7597 | } |
| 7598 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7599 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7600 | { |
| 7601 | struct drm_device *dev = intel_crtc->base.dev; |
| 7602 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7603 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7604 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7605 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7606 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7607 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7608 | |
| 7609 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7610 | * the hw state checker will get angry at the mismatch. */ |
| 7611 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7612 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7613 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7614 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7615 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7616 | crtc_vtotal -= 1; |
| 7617 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7618 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7619 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7620 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7621 | else |
| 7622 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7623 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7624 | if (vsyncshift < 0) |
| 7625 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7626 | } |
| 7627 | |
| 7628 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7629 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7630 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7631 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7632 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7633 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7634 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7635 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7636 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7637 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7638 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7639 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7640 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7641 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7642 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7643 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7644 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7645 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7646 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7647 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7648 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7649 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7650 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7651 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7652 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7653 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7654 | * bits. */ |
| 7655 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 7656 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7657 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7658 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7659 | } |
| 7660 | |
| 7661 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) |
| 7662 | { |
| 7663 | struct drm_device *dev = intel_crtc->base.dev; |
| 7664 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7665 | enum pipe pipe = intel_crtc->pipe; |
| 7666 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7667 | /* pipesrc controls the size that is scaled from, which should |
| 7668 | * always be the user's requested size. |
| 7669 | */ |
| 7670 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7671 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7672 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7673 | } |
| 7674 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7675 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7676 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7677 | { |
| 7678 | struct drm_device *dev = crtc->base.dev; |
| 7679 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7680 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7681 | uint32_t tmp; |
| 7682 | |
| 7683 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7684 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7685 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7686 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7687 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7688 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7689 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7690 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7691 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7692 | |
| 7693 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7694 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7695 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7696 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7697 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7698 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7699 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7700 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7701 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7702 | |
| 7703 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7704 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7705 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7706 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7707 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7708 | } |
| 7709 | |
| 7710 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7711 | struct intel_crtc_state *pipe_config) |
| 7712 | { |
| 7713 | struct drm_device *dev = crtc->base.dev; |
| 7714 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7715 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7716 | |
| 7717 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7718 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7719 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7720 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7721 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7722 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7723 | } |
| 7724 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7725 | 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] | 7726 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7727 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7728 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7729 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7730 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7731 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7732 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7733 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7734 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7735 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7736 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7737 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7738 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7739 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7740 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7741 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 7742 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7743 | |
| 7744 | mode->hsync = drm_mode_hsync(mode); |
| 7745 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7746 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7747 | } |
| 7748 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7749 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7750 | { |
| 7751 | struct drm_device *dev = intel_crtc->base.dev; |
| 7752 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7753 | uint32_t pipeconf; |
| 7754 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7755 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7756 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7757 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 7758 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 7759 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7760 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7761 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7762 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7763 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7764 | /* only g4x and later have fancy bpc/dither controls */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7765 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7766 | /* 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] | 7767 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7768 | pipeconf |= PIPECONF_DITHER_EN | |
| 7769 | PIPECONF_DITHER_TYPE_SP; |
| 7770 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7771 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7772 | case 18: |
| 7773 | pipeconf |= PIPECONF_6BPC; |
| 7774 | break; |
| 7775 | case 24: |
| 7776 | pipeconf |= PIPECONF_8BPC; |
| 7777 | break; |
| 7778 | case 30: |
| 7779 | pipeconf |= PIPECONF_10BPC; |
| 7780 | break; |
| 7781 | default: |
| 7782 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7783 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7784 | } |
| 7785 | } |
| 7786 | |
| 7787 | if (HAS_PIPE_CXSR(dev)) { |
| 7788 | if (intel_crtc->lowfreq_avail) { |
| 7789 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 7790 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 7791 | } else { |
| 7792 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7793 | } |
| 7794 | } |
| 7795 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7796 | 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] | 7797 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7798 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7799 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7800 | else |
| 7801 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7802 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7803 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7804 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7805 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 7806 | intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7807 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7808 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7809 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7810 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7811 | } |
| 7812 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7813 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7814 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7815 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7816 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7817 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7818 | int refclk; |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 7819 | intel_clock_t clock; |
| 7820 | bool ok; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 7821 | const intel_limit_t *limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7822 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7823 | memset(&crtc_state->dpll_hw_state, 0, |
| 7824 | sizeof(crtc_state->dpll_hw_state)); |
| 7825 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 7826 | if (crtc_state->has_dsi_encoder) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 7827 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7828 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7829 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7830 | refclk = i9xx_get_refclk(crtc_state); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7831 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7832 | /* |
| 7833 | * Returns a set of divisors for the desired target clock with |
| 7834 | * the given refclk, or FALSE. The returned values represent |
| 7835 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 7836 | * 2) / p1 / p2. |
| 7837 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7838 | limit = intel_limit(crtc_state, refclk); |
| 7839 | ok = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7840 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7841 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7842 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7843 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7844 | return -EINVAL; |
| 7845 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7846 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7847 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7848 | crtc_state->dpll.n = clock.n; |
| 7849 | crtc_state->dpll.m1 = clock.m1; |
| 7850 | crtc_state->dpll.m2 = clock.m2; |
| 7851 | crtc_state->dpll.p1 = clock.p1; |
| 7852 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7853 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7854 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7855 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7856 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7857 | } else if (IS_CHERRYVIEW(dev)) { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7858 | chv_compute_dpll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7859 | } else if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7860 | vlv_compute_dpll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7861 | } else { |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7862 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7863 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7864 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7865 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7866 | } |
| 7867 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7868 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7869 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7870 | { |
| 7871 | struct drm_device *dev = crtc->base.dev; |
| 7872 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7873 | uint32_t tmp; |
| 7874 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7875 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 7876 | return; |
| 7877 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7878 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7879 | if (!(tmp & PFIT_ENABLE)) |
| 7880 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7881 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7882 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7883 | if (INTEL_INFO(dev)->gen < 4) { |
| 7884 | if (crtc->pipe != PIPE_B) |
| 7885 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7886 | } else { |
| 7887 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7888 | return; |
| 7889 | } |
| 7890 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7891 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7892 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 7893 | if (INTEL_INFO(dev)->gen < 5) |
| 7894 | pipe_config->gmch_pfit.lvds_border_bits = |
| 7895 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 7896 | } |
| 7897 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7898 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7899 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7900 | { |
| 7901 | struct drm_device *dev = crtc->base.dev; |
| 7902 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7903 | int pipe = pipe_config->cpu_transcoder; |
| 7904 | intel_clock_t clock; |
| 7905 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7906 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7907 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7908 | /* In case of MIPI DPLL will not even be used */ |
| 7909 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 7910 | return; |
| 7911 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7912 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7913 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7914 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7915 | |
| 7916 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7917 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7918 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7919 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7920 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7921 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7922 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7923 | } |
| 7924 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7925 | static void |
| 7926 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7927 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7928 | { |
| 7929 | struct drm_device *dev = crtc->base.dev; |
| 7930 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7931 | u32 val, base, offset; |
| 7932 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7933 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7934 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7935 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7936 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7937 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7938 | val = I915_READ(DSPCNTR(plane)); |
| 7939 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 7940 | return; |
| 7941 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7942 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7943 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7944 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7945 | return; |
| 7946 | } |
| 7947 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7948 | fb = &intel_fb->base; |
| 7949 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7950 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7951 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7952 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7953 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7954 | } |
| 7955 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7956 | |
| 7957 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7958 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7959 | fb->pixel_format = fourcc; |
| 7960 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7961 | |
| 7962 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7963 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7964 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7965 | else |
| 7966 | offset = I915_READ(DSPLINOFF(plane)); |
| 7967 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7968 | } else { |
| 7969 | base = I915_READ(DSPADDR(plane)); |
| 7970 | } |
| 7971 | plane_config->base = base; |
| 7972 | |
| 7973 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7974 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7975 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7976 | |
| 7977 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7978 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7979 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7980 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 7981 | fb->pixel_format, |
| 7982 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7983 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7984 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7985 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7986 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7987 | pipe_name(pipe), plane, fb->width, fb->height, |
| 7988 | fb->bits_per_pixel, base, fb->pitches[0], |
| 7989 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7990 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7991 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7994 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7995 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7996 | { |
| 7997 | struct drm_device *dev = crtc->base.dev; |
| 7998 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7999 | int pipe = pipe_config->cpu_transcoder; |
| 8000 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 8001 | intel_clock_t clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8002 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8003 | int refclk = 100000; |
| 8004 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8005 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8006 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8007 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8008 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8009 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8010 | 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] | 8011 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8012 | |
| 8013 | 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] | 8014 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8015 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8016 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8017 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8018 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8019 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8020 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8021 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8022 | } |
| 8023 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8024 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8025 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8026 | { |
| 8027 | struct drm_device *dev = crtc->base.dev; |
| 8028 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8029 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8030 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8031 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8032 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8033 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8034 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8035 | return false; |
| 8036 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8037 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8038 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8039 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8040 | ret = false; |
| 8041 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8042 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8043 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8044 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8045 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8046 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8047 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8048 | case PIPECONF_6BPC: |
| 8049 | pipe_config->pipe_bpp = 18; |
| 8050 | break; |
| 8051 | case PIPECONF_8BPC: |
| 8052 | pipe_config->pipe_bpp = 24; |
| 8053 | break; |
| 8054 | case PIPECONF_10BPC: |
| 8055 | pipe_config->pipe_bpp = 30; |
| 8056 | break; |
| 8057 | default: |
| 8058 | break; |
| 8059 | } |
| 8060 | } |
| 8061 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8062 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 8063 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8064 | pipe_config->limited_color_range = true; |
| 8065 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8066 | if (INTEL_INFO(dev)->gen < 4) |
| 8067 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8068 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8069 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8070 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8071 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8072 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8073 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8074 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8075 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 8076 | pipe_config->pixel_multiplier = |
| 8077 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8078 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8079 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8080 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 8081 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8082 | pipe_config->pixel_multiplier = |
| 8083 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8084 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8085 | } else { |
| 8086 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8087 | * port and will be fixed up in the encoder->get_config |
| 8088 | * function. */ |
| 8089 | pipe_config->pixel_multiplier = 1; |
| 8090 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8091 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8092 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8093 | /* |
| 8094 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8095 | * on 830. Filter it out here so that we don't |
| 8096 | * report errors due to that. |
| 8097 | */ |
| 8098 | if (IS_I830(dev)) |
| 8099 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8100 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8101 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8102 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8103 | } else { |
| 8104 | /* Mask out read-only status bits. */ |
| 8105 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8106 | DPLL_PORTC_READY_MASK | |
| 8107 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8108 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8109 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8110 | if (IS_CHERRYVIEW(dev)) |
| 8111 | chv_crtc_clock_get(crtc, pipe_config); |
| 8112 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8113 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8114 | else |
| 8115 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8116 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8117 | /* |
| 8118 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8119 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8120 | * default. |
| 8121 | */ |
| 8122 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8123 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8124 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8125 | ret = true; |
| 8126 | |
| 8127 | out: |
| 8128 | intel_display_power_put(dev_priv, power_domain); |
| 8129 | |
| 8130 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8131 | } |
| 8132 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8133 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8134 | { |
| 8135 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8136 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8137 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8138 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8139 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8140 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8141 | bool has_ck505 = false; |
| 8142 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8143 | |
| 8144 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8145 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8146 | switch (encoder->type) { |
| 8147 | case INTEL_OUTPUT_LVDS: |
| 8148 | has_panel = true; |
| 8149 | has_lvds = true; |
| 8150 | break; |
| 8151 | case INTEL_OUTPUT_EDP: |
| 8152 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8153 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8154 | has_cpu_edp = true; |
| 8155 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8156 | default: |
| 8157 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8158 | } |
| 8159 | } |
| 8160 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8161 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8162 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8163 | can_ssc = has_ck505; |
| 8164 | } else { |
| 8165 | has_ck505 = false; |
| 8166 | can_ssc = true; |
| 8167 | } |
| 8168 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8169 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 8170 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8171 | |
| 8172 | /* Ironlake: try to setup display ref clock before DPLL |
| 8173 | * enabling. This is only under driver's control after |
| 8174 | * PCH B stepping, previous chipset stepping should be |
| 8175 | * ignoring this setting. |
| 8176 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8177 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8178 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8179 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8180 | * compute the final state we want first and check if we need to |
| 8181 | * make any changes at all. |
| 8182 | */ |
| 8183 | final = val; |
| 8184 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8185 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8186 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8187 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8188 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8189 | |
| 8190 | final &= ~DREF_SSC_SOURCE_MASK; |
| 8191 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 8192 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8193 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8194 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8195 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8196 | |
| 8197 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8198 | final |= DREF_SSC1_ENABLE; |
| 8199 | |
| 8200 | if (has_cpu_edp) { |
| 8201 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8202 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8203 | else |
| 8204 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8205 | } else |
| 8206 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8207 | } else { |
| 8208 | final |= DREF_SSC_SOURCE_DISABLE; |
| 8209 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8210 | } |
| 8211 | |
| 8212 | if (final == val) |
| 8213 | return; |
| 8214 | |
| 8215 | /* Always enable nonspread source */ |
| 8216 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8217 | |
| 8218 | if (has_ck505) |
| 8219 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8220 | else |
| 8221 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8222 | |
| 8223 | if (has_panel) { |
| 8224 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8225 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8226 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8227 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8228 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8229 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8230 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8231 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8232 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8233 | |
| 8234 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8235 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8236 | POSTING_READ(PCH_DREF_CONTROL); |
| 8237 | udelay(200); |
| 8238 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8239 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8240 | |
| 8241 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8242 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8243 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8244 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8245 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8246 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8247 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8248 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8249 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8250 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8251 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8252 | POSTING_READ(PCH_DREF_CONTROL); |
| 8253 | udelay(200); |
| 8254 | } else { |
| 8255 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 8256 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8257 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8258 | |
| 8259 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8260 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8261 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8262 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8263 | POSTING_READ(PCH_DREF_CONTROL); |
| 8264 | udelay(200); |
| 8265 | |
| 8266 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8267 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8268 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8269 | |
| 8270 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8271 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8272 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8273 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8274 | POSTING_READ(PCH_DREF_CONTROL); |
| 8275 | udelay(200); |
| 8276 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8277 | |
| 8278 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8279 | } |
| 8280 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8281 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8282 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8283 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8284 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8285 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8286 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8287 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8288 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8289 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 8290 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 8291 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8292 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8293 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8294 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8295 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8296 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8297 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 8298 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 8299 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8300 | } |
| 8301 | |
| 8302 | /* WaMPhyProgramming:hsw */ |
| 8303 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8304 | { |
| 8305 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8306 | |
| 8307 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8308 | tmp &= ~(0xFF << 24); |
| 8309 | tmp |= (0x12 << 24); |
| 8310 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8311 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8312 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8313 | tmp |= (1 << 11); |
| 8314 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8315 | |
| 8316 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8317 | tmp |= (1 << 11); |
| 8318 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8319 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8320 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8321 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8322 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8323 | |
| 8324 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8325 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8326 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8327 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8328 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8329 | tmp &= ~(7 << 13); |
| 8330 | tmp |= (5 << 13); |
| 8331 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8332 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8333 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8334 | tmp &= ~(7 << 13); |
| 8335 | tmp |= (5 << 13); |
| 8336 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8337 | |
| 8338 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8339 | tmp &= ~0xFF; |
| 8340 | tmp |= 0x1C; |
| 8341 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8342 | |
| 8343 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8344 | tmp &= ~0xFF; |
| 8345 | tmp |= 0x1C; |
| 8346 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8347 | |
| 8348 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8349 | tmp &= ~(0xFF << 16); |
| 8350 | tmp |= (0x1C << 16); |
| 8351 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8352 | |
| 8353 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8354 | tmp &= ~(0xFF << 16); |
| 8355 | tmp |= (0x1C << 16); |
| 8356 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8357 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8358 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8359 | tmp |= (1 << 27); |
| 8360 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8361 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8362 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8363 | tmp |= (1 << 27); |
| 8364 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8365 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8366 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8367 | tmp &= ~(0xF << 28); |
| 8368 | tmp |= (4 << 28); |
| 8369 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8370 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8371 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8372 | tmp &= ~(0xF << 28); |
| 8373 | tmp |= (4 << 28); |
| 8374 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8375 | } |
| 8376 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8377 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8378 | * Programming" based on the parameters passed: |
| 8379 | * - Sequence to enable CLKOUT_DP |
| 8380 | * - Sequence to enable CLKOUT_DP without spread |
| 8381 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8382 | */ |
| 8383 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 8384 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8385 | { |
| 8386 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8387 | uint32_t reg, tmp; |
| 8388 | |
| 8389 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8390 | with_spread = true; |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8391 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8392 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8393 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8394 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8395 | |
| 8396 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8397 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8398 | tmp |= SBI_SSCCTL_PATHALT; |
| 8399 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8400 | |
| 8401 | udelay(24); |
| 8402 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8403 | if (with_spread) { |
| 8404 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8405 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8406 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8407 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8408 | if (with_fdi) { |
| 8409 | lpt_reset_fdi_mphy(dev_priv); |
| 8410 | lpt_program_fdi_mphy(dev_priv); |
| 8411 | } |
| 8412 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8413 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8414 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8415 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8416 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8417 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8418 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8419 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8420 | } |
| 8421 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8422 | /* Sequence to disable CLKOUT_DP */ |
| 8423 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 8424 | { |
| 8425 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8426 | uint32_t reg, tmp; |
| 8427 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8428 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8429 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8430 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8431 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8432 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8433 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8434 | |
| 8435 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8436 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8437 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8438 | tmp |= SBI_SSCCTL_PATHALT; |
| 8439 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8440 | udelay(32); |
| 8441 | } |
| 8442 | tmp |= SBI_SSCCTL_DISABLE; |
| 8443 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8444 | } |
| 8445 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8446 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8447 | } |
| 8448 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8449 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8450 | |
| 8451 | static const uint16_t sscdivintphase[] = { |
| 8452 | [BEND_IDX( 50)] = 0x3B23, |
| 8453 | [BEND_IDX( 45)] = 0x3B23, |
| 8454 | [BEND_IDX( 40)] = 0x3C23, |
| 8455 | [BEND_IDX( 35)] = 0x3C23, |
| 8456 | [BEND_IDX( 30)] = 0x3D23, |
| 8457 | [BEND_IDX( 25)] = 0x3D23, |
| 8458 | [BEND_IDX( 20)] = 0x3E23, |
| 8459 | [BEND_IDX( 15)] = 0x3E23, |
| 8460 | [BEND_IDX( 10)] = 0x3F23, |
| 8461 | [BEND_IDX( 5)] = 0x3F23, |
| 8462 | [BEND_IDX( 0)] = 0x0025, |
| 8463 | [BEND_IDX( -5)] = 0x0025, |
| 8464 | [BEND_IDX(-10)] = 0x0125, |
| 8465 | [BEND_IDX(-15)] = 0x0125, |
| 8466 | [BEND_IDX(-20)] = 0x0225, |
| 8467 | [BEND_IDX(-25)] = 0x0225, |
| 8468 | [BEND_IDX(-30)] = 0x0325, |
| 8469 | [BEND_IDX(-35)] = 0x0325, |
| 8470 | [BEND_IDX(-40)] = 0x0425, |
| 8471 | [BEND_IDX(-45)] = 0x0425, |
| 8472 | [BEND_IDX(-50)] = 0x0525, |
| 8473 | }; |
| 8474 | |
| 8475 | /* |
| 8476 | * Bend CLKOUT_DP |
| 8477 | * steps -50 to 50 inclusive, in steps of 5 |
| 8478 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8479 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8480 | */ |
| 8481 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8482 | { |
| 8483 | uint32_t tmp; |
| 8484 | int idx = BEND_IDX(steps); |
| 8485 | |
| 8486 | if (WARN_ON(steps % 5 != 0)) |
| 8487 | return; |
| 8488 | |
| 8489 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8490 | return; |
| 8491 | |
| 8492 | mutex_lock(&dev_priv->sb_lock); |
| 8493 | |
| 8494 | if (steps % 10 != 0) |
| 8495 | tmp = 0xAAAAAAAB; |
| 8496 | else |
| 8497 | tmp = 0x00000000; |
| 8498 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8499 | |
| 8500 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8501 | tmp &= 0xffff0000; |
| 8502 | tmp |= sscdivintphase[idx]; |
| 8503 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8504 | |
| 8505 | mutex_unlock(&dev_priv->sb_lock); |
| 8506 | } |
| 8507 | |
| 8508 | #undef BEND_IDX |
| 8509 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8510 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 8511 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8512 | struct intel_encoder *encoder; |
| 8513 | bool has_vga = false; |
| 8514 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8515 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8516 | switch (encoder->type) { |
| 8517 | case INTEL_OUTPUT_ANALOG: |
| 8518 | has_vga = true; |
| 8519 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8520 | default: |
| 8521 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8522 | } |
| 8523 | } |
| 8524 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8525 | if (has_vga) { |
| 8526 | lpt_bend_clkout_dp(to_i915(dev), 0); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8527 | lpt_enable_clkout_dp(dev, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8528 | } else { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8529 | lpt_disable_clkout_dp(dev); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8530 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8531 | } |
| 8532 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8533 | /* |
| 8534 | * Initialize reference clocks when the driver loads |
| 8535 | */ |
| 8536 | void intel_init_pch_refclk(struct drm_device *dev) |
| 8537 | { |
| 8538 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 8539 | ironlake_init_pch_refclk(dev); |
| 8540 | else if (HAS_PCH_LPT(dev)) |
| 8541 | lpt_init_pch_refclk(dev); |
| 8542 | } |
| 8543 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8544 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8545 | { |
| 8546 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8547 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8548 | int pipe = intel_crtc->pipe; |
| 8549 | uint32_t val; |
| 8550 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8551 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8552 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8553 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8554 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8555 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8556 | break; |
| 8557 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8558 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8559 | break; |
| 8560 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8561 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8562 | break; |
| 8563 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8564 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8565 | break; |
| 8566 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8567 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8568 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8569 | } |
| 8570 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8571 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8572 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8573 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8574 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8575 | val |= PIPECONF_INTERLACED_ILK; |
| 8576 | else |
| 8577 | val |= PIPECONF_PROGRESSIVE; |
| 8578 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8579 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8580 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8581 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8582 | I915_WRITE(PIPECONF(pipe), val); |
| 8583 | POSTING_READ(PIPECONF(pipe)); |
| 8584 | } |
| 8585 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8586 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8587 | { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8588 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8589 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8590 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8591 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8592 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8593 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8594 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8595 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8596 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8597 | val |= PIPECONF_INTERLACED_ILK; |
| 8598 | else |
| 8599 | val |= PIPECONF_PROGRESSIVE; |
| 8600 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8601 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8602 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8603 | } |
| 8604 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8605 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
| 8606 | { |
| 8607 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8608 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8609 | |
| 8610 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
| 8611 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8612 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8613 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8614 | case 18: |
| 8615 | val |= PIPEMISC_DITHER_6_BPC; |
| 8616 | break; |
| 8617 | case 24: |
| 8618 | val |= PIPEMISC_DITHER_8_BPC; |
| 8619 | break; |
| 8620 | case 30: |
| 8621 | val |= PIPEMISC_DITHER_10_BPC; |
| 8622 | break; |
| 8623 | case 36: |
| 8624 | val |= PIPEMISC_DITHER_12_BPC; |
| 8625 | break; |
| 8626 | default: |
| 8627 | /* Case prevented by pipe_config_set_bpp. */ |
| 8628 | BUG(); |
| 8629 | } |
| 8630 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8631 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8632 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8633 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8634 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8635 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8636 | } |
| 8637 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8638 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8639 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8640 | intel_clock_t *clock, |
| 8641 | bool *has_reduced_clock, |
| 8642 | intel_clock_t *reduced_clock) |
| 8643 | { |
| 8644 | struct drm_device *dev = crtc->dev; |
| 8645 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8646 | int refclk; |
| 8647 | const intel_limit_t *limit; |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 8648 | bool ret; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8649 | |
Ander Conselvan de Oliveira | 8f0d5b9 | 2016-03-21 18:00:04 +0200 | [diff] [blame] | 8650 | refclk = 120000; |
| 8651 | |
| 8652 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 8653 | if (intel_panel_use_ssc(dev_priv)) { |
| 8654 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8655 | dev_priv->vbt.lvds_ssc_freq); |
| 8656 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8657 | } |
| 8658 | |
| 8659 | if (intel_is_dual_link_lvds(dev)) { |
| 8660 | if (refclk == 100000) |
| 8661 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8662 | else |
| 8663 | limit = &intel_limits_ironlake_dual_lvds; |
| 8664 | } else { |
| 8665 | if (refclk == 100000) |
| 8666 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8667 | else |
| 8668 | limit = &intel_limits_ironlake_single_lvds; |
| 8669 | } |
Ander Conselvan de Oliveira | 26ce6d5 | 2016-03-21 18:00:03 +0200 | [diff] [blame] | 8670 | } else { |
Ander Conselvan de Oliveira | 8f0d5b9 | 2016-03-21 18:00:04 +0200 | [diff] [blame] | 8671 | limit = &intel_limits_ironlake_dac; |
Ander Conselvan de Oliveira | 26ce6d5 | 2016-03-21 18:00:03 +0200 | [diff] [blame] | 8672 | } |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8673 | |
| 8674 | /* |
| 8675 | * Returns a set of divisors for the desired target clock with the given |
| 8676 | * refclk, or FALSE. The returned values represent the clock equation: |
| 8677 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 8678 | */ |
Ander Conselvan de Oliveira | 2d7feac | 2016-03-21 18:00:05 +0200 | [diff] [blame] | 8679 | ret = g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8680 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8681 | if (!ret) |
| 8682 | return false; |
| 8683 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8684 | return true; |
| 8685 | } |
| 8686 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8687 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8688 | { |
| 8689 | /* |
| 8690 | * Account for spread spectrum to avoid |
| 8691 | * oversubscribing the link. Max center spread |
| 8692 | * is 2.5%; use 5% for safety's sake. |
| 8693 | */ |
| 8694 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8695 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8696 | } |
| 8697 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8698 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8699 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8700 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8701 | } |
| 8702 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8703 | 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] | 8704 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8705 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8706 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8707 | { |
| 8708 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8709 | struct drm_device *dev = crtc->dev; |
| 8710 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8711 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8712 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8713 | struct drm_connector_state *connector_state; |
| 8714 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8715 | uint32_t dpll; |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8716 | int factor, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 8717 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8718 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8719 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8720 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8721 | continue; |
| 8722 | |
| 8723 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8724 | |
| 8725 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8726 | case INTEL_OUTPUT_LVDS: |
| 8727 | is_lvds = true; |
| 8728 | break; |
| 8729 | case INTEL_OUTPUT_SDVO: |
| 8730 | case INTEL_OUTPUT_HDMI: |
| 8731 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8732 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8733 | default: |
| 8734 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8735 | } |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8736 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8737 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8738 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8739 | factor = 21; |
| 8740 | if (is_lvds) { |
| 8741 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8742 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 8743 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8744 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8745 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8746 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8747 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8748 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 8749 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8750 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8751 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 8752 | *fp2 |= FP_CB_TUNE; |
| 8753 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8754 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8755 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8756 | if (is_lvds) |
| 8757 | dpll |= DPLLB_MODE_LVDS; |
| 8758 | else |
| 8759 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8760 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8761 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8762 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8763 | |
| 8764 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8765 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8766 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8767 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8768 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8769 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8770 | 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] | 8771 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8772 | 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] | 8773 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8774 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8775 | case 5: |
| 8776 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8777 | break; |
| 8778 | case 7: |
| 8779 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8780 | break; |
| 8781 | case 10: |
| 8782 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8783 | break; |
| 8784 | case 14: |
| 8785 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8786 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8787 | } |
| 8788 | |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8789 | if (is_lvds && intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8790 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8791 | else |
| 8792 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8793 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 8794 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8795 | } |
| 8796 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8797 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8798 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8799 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8800 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8801 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8802 | u32 dpll = 0, fp = 0, fp2 = 0; |
Ander Conselvan de Oliveira | 7ed9f89 | 2016-03-21 18:00:07 +0200 | [diff] [blame^] | 8803 | bool has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 8804 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8805 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8806 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8807 | memset(&crtc_state->dpll_hw_state, 0, |
| 8808 | sizeof(crtc_state->dpll_hw_state)); |
| 8809 | |
Ville Syrjälä | 7905df2 | 2015-11-25 16:35:30 +0200 | [diff] [blame] | 8810 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8811 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8812 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 8813 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 8814 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8815 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | 7ed9f89 | 2016-03-21 18:00:07 +0200 | [diff] [blame^] | 8816 | if (!ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
| 8817 | &has_reduced_clock, |
| 8818 | &reduced_clock)) { |
| 8819 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8820 | return -EINVAL; |
| 8821 | } |
| 8822 | |
| 8823 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8824 | crtc_state->dpll.n = clock.n; |
| 8825 | crtc_state->dpll.m1 = clock.m1; |
| 8826 | crtc_state->dpll.m2 = clock.m2; |
| 8827 | crtc_state->dpll.p1 = clock.p1; |
| 8828 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8829 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8830 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8831 | /* 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] | 8832 | if (crtc_state->has_pch_encoder) { |
| 8833 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8834 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8835 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Ander Conselvan de Oliveira | bfa0444 | 2016-03-21 18:00:06 +0200 | [diff] [blame] | 8836 | else |
| 8837 | fp2 = fp; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8838 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8839 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8840 | &fp, &reduced_clock, |
| 8841 | has_reduced_clock ? &fp2 : NULL); |
| 8842 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8843 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8844 | crtc_state->dpll_hw_state.fp0 = fp; |
Ander Conselvan de Oliveira | bfa0444 | 2016-03-21 18:00:06 +0200 | [diff] [blame] | 8845 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8846 | |
Ander Conselvan de Oliveira | daedf20 | 2016-03-08 17:46:23 +0200 | [diff] [blame] | 8847 | pll = intel_get_shared_dpll(crtc, crtc_state, NULL); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8848 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 8849 | 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] | 8850 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 8851 | return -EINVAL; |
| 8852 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8853 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8854 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 8855 | if (is_lvds && has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8856 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 8857 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8858 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8859 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8860 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8861 | } |
| 8862 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8863 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8864 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8865 | { |
| 8866 | struct drm_device *dev = crtc->base.dev; |
| 8867 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8868 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8869 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8870 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8871 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8872 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8873 | & ~TU_SIZE_MASK; |
| 8874 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8875 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8876 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8877 | } |
| 8878 | |
| 8879 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8880 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8881 | struct intel_link_m_n *m_n, |
| 8882 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8883 | { |
| 8884 | struct drm_device *dev = crtc->base.dev; |
| 8885 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8886 | enum pipe pipe = crtc->pipe; |
| 8887 | |
| 8888 | if (INTEL_INFO(dev)->gen >= 5) { |
| 8889 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8890 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8891 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8892 | & ~TU_SIZE_MASK; |
| 8893 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8894 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8895 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8896 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8897 | * gen < 8) and if DRRS is supported (to make sure the |
| 8898 | * registers are not unnecessarily read). |
| 8899 | */ |
| 8900 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8901 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8902 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8903 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8904 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8905 | & ~TU_SIZE_MASK; |
| 8906 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8907 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8908 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8909 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8910 | } else { |
| 8911 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8912 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8913 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8914 | & ~TU_SIZE_MASK; |
| 8915 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8916 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8917 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8918 | } |
| 8919 | } |
| 8920 | |
| 8921 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8922 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8923 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8924 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8925 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8926 | else |
| 8927 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8928 | &pipe_config->dp_m_n, |
| 8929 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8930 | } |
| 8931 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8932 | 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] | 8933 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8934 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8935 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8936 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8937 | } |
| 8938 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8939 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8940 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8941 | { |
| 8942 | struct drm_device *dev = crtc->base.dev; |
| 8943 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8944 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8945 | uint32_t ps_ctrl = 0; |
| 8946 | int id = -1; |
| 8947 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8948 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8949 | /* find scaler attached to this pipe */ |
| 8950 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8951 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8952 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8953 | id = i; |
| 8954 | pipe_config->pch_pfit.enabled = true; |
| 8955 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8956 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8957 | break; |
| 8958 | } |
| 8959 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8960 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8961 | scaler_state->scaler_id = id; |
| 8962 | if (id >= 0) { |
| 8963 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8964 | } else { |
| 8965 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8966 | } |
| 8967 | } |
| 8968 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8969 | static void |
| 8970 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8971 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8972 | { |
| 8973 | struct drm_device *dev = crtc->base.dev; |
| 8974 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8975 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8976 | int pipe = crtc->pipe; |
| 8977 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8978 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8979 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8980 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8981 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8982 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8983 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8984 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8985 | return; |
| 8986 | } |
| 8987 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8988 | fb = &intel_fb->base; |
| 8989 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8990 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8991 | if (!(val & PLANE_CTL_ENABLE)) |
| 8992 | goto error; |
| 8993 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8994 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 8995 | fourcc = skl_format_to_fourcc(pixel_format, |
| 8996 | val & PLANE_CTL_ORDER_RGBX, |
| 8997 | val & PLANE_CTL_ALPHA_MASK); |
| 8998 | fb->pixel_format = fourcc; |
| 8999 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 9000 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9001 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9002 | switch (tiling) { |
| 9003 | case PLANE_CTL_TILED_LINEAR: |
| 9004 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 9005 | break; |
| 9006 | case PLANE_CTL_TILED_X: |
| 9007 | plane_config->tiling = I915_TILING_X; |
| 9008 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9009 | break; |
| 9010 | case PLANE_CTL_TILED_Y: |
| 9011 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 9012 | break; |
| 9013 | case PLANE_CTL_TILED_YF: |
| 9014 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 9015 | break; |
| 9016 | default: |
| 9017 | MISSING_CASE(tiling); |
| 9018 | goto error; |
| 9019 | } |
| 9020 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9021 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 9022 | plane_config->base = base; |
| 9023 | |
| 9024 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 9025 | |
| 9026 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 9027 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9028 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9029 | |
| 9030 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 9031 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9032 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9033 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9034 | |
| 9035 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9036 | fb->pixel_format, |
| 9037 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9038 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9039 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9040 | |
| 9041 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9042 | pipe_name(pipe), fb->width, fb->height, |
| 9043 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9044 | plane_config->size); |
| 9045 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9046 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9047 | return; |
| 9048 | |
| 9049 | error: |
| 9050 | kfree(fb); |
| 9051 | } |
| 9052 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9053 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9054 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9055 | { |
| 9056 | struct drm_device *dev = crtc->base.dev; |
| 9057 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9058 | uint32_t tmp; |
| 9059 | |
| 9060 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9061 | |
| 9062 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9063 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9064 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9065 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9066 | |
| 9067 | /* We currently do not free assignements of panel fitters on |
| 9068 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9069 | * differentiates them) so just WARN about this case for now. */ |
| 9070 | if (IS_GEN7(dev)) { |
| 9071 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9072 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9073 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9074 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9075 | } |
| 9076 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9077 | static void |
| 9078 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9079 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9080 | { |
| 9081 | struct drm_device *dev = crtc->base.dev; |
| 9082 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9083 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9084 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9085 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9086 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9087 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9088 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9089 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9090 | val = I915_READ(DSPCNTR(pipe)); |
| 9091 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 9092 | return; |
| 9093 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9094 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9095 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9096 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9097 | return; |
| 9098 | } |
| 9099 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9100 | fb = &intel_fb->base; |
| 9101 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9102 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9103 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9104 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9105 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9106 | } |
| 9107 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9108 | |
| 9109 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 9110 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9111 | fb->pixel_format = fourcc; |
| 9112 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9113 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9114 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9115 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9116 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9117 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9118 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9119 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9120 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9121 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9122 | } |
| 9123 | plane_config->base = base; |
| 9124 | |
| 9125 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9126 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 9127 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9128 | |
| 9129 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9130 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9131 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9132 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9133 | fb->pixel_format, |
| 9134 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9135 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9136 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9137 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 9138 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9139 | pipe_name(pipe), fb->width, fb->height, |
| 9140 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9141 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9142 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9143 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9144 | } |
| 9145 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9146 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9147 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9148 | { |
| 9149 | struct drm_device *dev = crtc->base.dev; |
| 9150 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9151 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9152 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9153 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9154 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9155 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9156 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9157 | return false; |
| 9158 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9159 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9160 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9161 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9162 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9163 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9164 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9165 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9166 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9167 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9168 | case PIPECONF_6BPC: |
| 9169 | pipe_config->pipe_bpp = 18; |
| 9170 | break; |
| 9171 | case PIPECONF_8BPC: |
| 9172 | pipe_config->pipe_bpp = 24; |
| 9173 | break; |
| 9174 | case PIPECONF_10BPC: |
| 9175 | pipe_config->pipe_bpp = 30; |
| 9176 | break; |
| 9177 | case PIPECONF_12BPC: |
| 9178 | pipe_config->pipe_bpp = 36; |
| 9179 | break; |
| 9180 | default: |
| 9181 | break; |
| 9182 | } |
| 9183 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9184 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9185 | pipe_config->limited_color_range = true; |
| 9186 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9187 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9188 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9189 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9190 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9191 | pipe_config->has_pch_encoder = true; |
| 9192 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9193 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9194 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9195 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9196 | |
| 9197 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9198 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9199 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9200 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9201 | } else { |
| 9202 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9203 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9204 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9205 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9206 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9207 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9208 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9209 | pipe_config->shared_dpll = |
| 9210 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9211 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9212 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9213 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 9214 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9215 | |
| 9216 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9217 | pipe_config->pixel_multiplier = |
| 9218 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9219 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9220 | |
| 9221 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9222 | } else { |
| 9223 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9224 | } |
| 9225 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9226 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9227 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9228 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9229 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9230 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9231 | ret = true; |
| 9232 | |
| 9233 | out: |
| 9234 | intel_display_power_put(dev_priv, power_domain); |
| 9235 | |
| 9236 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9237 | } |
| 9238 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9239 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9240 | { |
| 9241 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9242 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9243 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9244 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9245 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9246 | pipe_name(crtc->pipe)); |
| 9247 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9248 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 9249 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
Ville Syrjälä | 01403de | 2015-09-18 20:03:33 +0300 | [diff] [blame] | 9250 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9251 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9252 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 9253 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9254 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9255 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9256 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9257 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9258 | 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] | 9259 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9260 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9261 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9262 | 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] | 9263 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9264 | /* |
| 9265 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9266 | * interrupts remain enabled. We used to check for that, but since it's |
| 9267 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9268 | * the interrupts, the check below should be enough. |
| 9269 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9270 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9271 | } |
| 9272 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9273 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9274 | { |
| 9275 | struct drm_device *dev = dev_priv->dev; |
| 9276 | |
| 9277 | if (IS_HASWELL(dev)) |
| 9278 | return I915_READ(D_COMP_HSW); |
| 9279 | else |
| 9280 | return I915_READ(D_COMP_BDW); |
| 9281 | } |
| 9282 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9283 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9284 | { |
| 9285 | struct drm_device *dev = dev_priv->dev; |
| 9286 | |
| 9287 | if (IS_HASWELL(dev)) { |
| 9288 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9289 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9290 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 9291 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9292 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9293 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9294 | I915_WRITE(D_COMP_BDW, val); |
| 9295 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9296 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9297 | } |
| 9298 | |
| 9299 | /* |
| 9300 | * This function implements pieces of two sequences from BSpec: |
| 9301 | * - Sequence for display software to disable LCPLL |
| 9302 | * - Sequence for display software to allow package C8+ |
| 9303 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9304 | * register. Callers should take care of disabling all the display engine |
| 9305 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9306 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9307 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9308 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9309 | { |
| 9310 | uint32_t val; |
| 9311 | |
| 9312 | assert_can_disable_lcpll(dev_priv); |
| 9313 | |
| 9314 | val = I915_READ(LCPLL_CTL); |
| 9315 | |
| 9316 | if (switch_to_fclk) { |
| 9317 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9318 | I915_WRITE(LCPLL_CTL, val); |
| 9319 | |
| 9320 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9321 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9322 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9323 | |
| 9324 | val = I915_READ(LCPLL_CTL); |
| 9325 | } |
| 9326 | |
| 9327 | val |= LCPLL_PLL_DISABLE; |
| 9328 | I915_WRITE(LCPLL_CTL, val); |
| 9329 | POSTING_READ(LCPLL_CTL); |
| 9330 | |
| 9331 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 9332 | DRM_ERROR("LCPLL still locked\n"); |
| 9333 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9334 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9335 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9336 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9337 | ndelay(100); |
| 9338 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9339 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9340 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9341 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9342 | |
| 9343 | if (allow_power_down) { |
| 9344 | val = I915_READ(LCPLL_CTL); |
| 9345 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9346 | I915_WRITE(LCPLL_CTL, val); |
| 9347 | POSTING_READ(LCPLL_CTL); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | /* |
| 9352 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9353 | * source. |
| 9354 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9355 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9356 | { |
| 9357 | uint32_t val; |
| 9358 | |
| 9359 | val = I915_READ(LCPLL_CTL); |
| 9360 | |
| 9361 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9362 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9363 | return; |
| 9364 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9365 | /* |
| 9366 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9367 | * 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] | 9368 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9369 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9370 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9371 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9372 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9373 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9374 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9375 | } |
| 9376 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9377 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9378 | val |= D_COMP_COMP_FORCE; |
| 9379 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9380 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9381 | |
| 9382 | val = I915_READ(LCPLL_CTL); |
| 9383 | val &= ~LCPLL_PLL_DISABLE; |
| 9384 | I915_WRITE(LCPLL_CTL, val); |
| 9385 | |
| 9386 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 9387 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9388 | |
| 9389 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9390 | val = I915_READ(LCPLL_CTL); |
| 9391 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9392 | I915_WRITE(LCPLL_CTL, val); |
| 9393 | |
| 9394 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9395 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9396 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9397 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9398 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9399 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 9400 | intel_update_cdclk(dev_priv->dev); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9401 | } |
| 9402 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9403 | /* |
| 9404 | * Package states C8 and deeper are really deep PC states that can only be |
| 9405 | * reached when all the devices on the system allow it, so even if the graphics |
| 9406 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9407 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9408 | * |
| 9409 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9410 | * well is disabled and most interrupts are disabled, and these are also |
| 9411 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9412 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9413 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9414 | * hang the machine. |
| 9415 | * |
| 9416 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9417 | * the state of some registers, so when we come back from PC8+ we need to |
| 9418 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9419 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9420 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9421 | * because of the runtime PM support). |
| 9422 | * |
| 9423 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9424 | * documentation. |
| 9425 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9426 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9427 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9428 | struct drm_device *dev = dev_priv->dev; |
| 9429 | uint32_t val; |
| 9430 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9431 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9432 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9433 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9434 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9435 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9436 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9437 | } |
| 9438 | |
| 9439 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9440 | hsw_disable_lcpll(dev_priv, true, true); |
| 9441 | } |
| 9442 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9443 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9444 | { |
| 9445 | struct drm_device *dev = dev_priv->dev; |
| 9446 | uint32_t val; |
| 9447 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9448 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9449 | |
| 9450 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9451 | lpt_init_pch_refclk(dev); |
| 9452 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9453 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9454 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9455 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9456 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9457 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9458 | } |
| 9459 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9460 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9461 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9462 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9463 | struct intel_atomic_state *old_intel_state = |
| 9464 | to_intel_atomic_state(old_state); |
| 9465 | unsigned int req_cdclk = old_intel_state->dev_cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9466 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9467 | broxton_set_cdclk(dev, req_cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9468 | } |
| 9469 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9470 | /* compute the max rate for new configuration */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9471 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9472 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9473 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 9474 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 9475 | struct drm_crtc *crtc; |
| 9476 | struct drm_crtc_state *cstate; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9477 | struct intel_crtc_state *crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9478 | unsigned max_pixel_rate = 0, i; |
| 9479 | enum pipe pipe; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9480 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9481 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 9482 | sizeof(intel_state->min_pixclk)); |
| 9483 | |
| 9484 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9485 | int pixel_rate; |
| 9486 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9487 | crtc_state = to_intel_crtc_state(cstate); |
| 9488 | if (!crtc_state->base.enable) { |
| 9489 | intel_state->min_pixclk[i] = 0; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9490 | continue; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9491 | } |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9492 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9493 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9494 | |
| 9495 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9496 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9497 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
| 9498 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9499 | intel_state->min_pixclk[i] = pixel_rate; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9500 | } |
| 9501 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9502 | for_each_pipe(dev_priv, pipe) |
| 9503 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); |
| 9504 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9505 | return max_pixel_rate; |
| 9506 | } |
| 9507 | |
| 9508 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) |
| 9509 | { |
| 9510 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9511 | uint32_t val, data; |
| 9512 | int ret; |
| 9513 | |
| 9514 | if (WARN((I915_READ(LCPLL_CTL) & |
| 9515 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | |
| 9516 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | |
| 9517 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | |
| 9518 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, |
| 9519 | "trying to change cdclk frequency with cdclk not enabled\n")) |
| 9520 | return; |
| 9521 | |
| 9522 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9523 | ret = sandybridge_pcode_write(dev_priv, |
| 9524 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); |
| 9525 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9526 | if (ret) { |
| 9527 | DRM_ERROR("failed to inform pcode about cdclk change\n"); |
| 9528 | return; |
| 9529 | } |
| 9530 | |
| 9531 | val = I915_READ(LCPLL_CTL); |
| 9532 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9533 | I915_WRITE(LCPLL_CTL, val); |
| 9534 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9535 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9536 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9537 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9538 | |
| 9539 | val = I915_READ(LCPLL_CTL); |
| 9540 | val &= ~LCPLL_CLK_FREQ_MASK; |
| 9541 | |
| 9542 | switch (cdclk) { |
| 9543 | case 450000: |
| 9544 | val |= LCPLL_CLK_FREQ_450; |
| 9545 | data = 0; |
| 9546 | break; |
| 9547 | case 540000: |
| 9548 | val |= LCPLL_CLK_FREQ_54O_BDW; |
| 9549 | data = 1; |
| 9550 | break; |
| 9551 | case 337500: |
| 9552 | val |= LCPLL_CLK_FREQ_337_5_BDW; |
| 9553 | data = 2; |
| 9554 | break; |
| 9555 | case 675000: |
| 9556 | val |= LCPLL_CLK_FREQ_675_BDW; |
| 9557 | data = 3; |
| 9558 | break; |
| 9559 | default: |
| 9560 | WARN(1, "invalid cdclk frequency\n"); |
| 9561 | return; |
| 9562 | } |
| 9563 | |
| 9564 | I915_WRITE(LCPLL_CTL, val); |
| 9565 | |
| 9566 | val = I915_READ(LCPLL_CTL); |
| 9567 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9568 | I915_WRITE(LCPLL_CTL, val); |
| 9569 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9570 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9571 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9572 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9573 | |
| 9574 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9575 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); |
| 9576 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9577 | |
| 9578 | intel_update_cdclk(dev); |
| 9579 | |
| 9580 | WARN(cdclk != dev_priv->cdclk_freq, |
| 9581 | "cdclk requested %d kHz but got %d kHz\n", |
| 9582 | cdclk, dev_priv->cdclk_freq); |
| 9583 | } |
| 9584 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9585 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9586 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9587 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9588 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9589 | int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9590 | int cdclk; |
| 9591 | |
| 9592 | /* |
| 9593 | * FIXME should also account for plane ratio |
| 9594 | * once 64bpp pixel formats are supported. |
| 9595 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9596 | if (max_pixclk > 540000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9597 | cdclk = 675000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9598 | else if (max_pixclk > 450000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9599 | cdclk = 540000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9600 | else if (max_pixclk > 337500) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9601 | cdclk = 450000; |
| 9602 | else |
| 9603 | cdclk = 337500; |
| 9604 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9605 | if (cdclk > dev_priv->max_cdclk_freq) { |
Maarten Lankhorst | 63ba534 | 2015-11-24 11:29:03 +0100 | [diff] [blame] | 9606 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 9607 | cdclk, dev_priv->max_cdclk_freq); |
| 9608 | return -EINVAL; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9609 | } |
| 9610 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9611 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 9612 | if (!intel_state->active_crtcs) |
| 9613 | intel_state->dev_cdclk = 337500; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9614 | |
| 9615 | return 0; |
| 9616 | } |
| 9617 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9618 | 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] | 9619 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9620 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9621 | struct intel_atomic_state *old_intel_state = |
| 9622 | to_intel_atomic_state(old_state); |
| 9623 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9624 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9625 | broadwell_set_cdclk(dev, req_cdclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9626 | } |
| 9627 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9628 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9629 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9630 | { |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9631 | struct intel_encoder *intel_encoder = |
| 9632 | intel_ddi_get_crtc_new_encoder(crtc_state); |
| 9633 | |
| 9634 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { |
| 9635 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
| 9636 | return -EINVAL; |
| 9637 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9638 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9639 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 9640 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9641 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9642 | } |
| 9643 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9644 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9645 | enum port port, |
| 9646 | struct intel_crtc_state *pipe_config) |
| 9647 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9648 | enum intel_dpll_id id; |
| 9649 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9650 | switch (port) { |
| 9651 | case PORT_A: |
| 9652 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9653 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9654 | break; |
| 9655 | case PORT_B: |
| 9656 | pipe_config->ddi_pll_sel = SKL_DPLL1; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9657 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9658 | break; |
| 9659 | case PORT_C: |
| 9660 | pipe_config->ddi_pll_sel = SKL_DPLL2; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9661 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9662 | break; |
| 9663 | default: |
| 9664 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9665 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9666 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9667 | |
| 9668 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9669 | } |
| 9670 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9671 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9672 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9673 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9674 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9675 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9676 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9677 | |
| 9678 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 9679 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 9680 | |
| 9681 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9682 | case SKL_DPLL0: |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9683 | id = DPLL_ID_SKL_DPLL0; |
| 9684 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9685 | case SKL_DPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9686 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9687 | break; |
| 9688 | case SKL_DPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9689 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9690 | break; |
| 9691 | case SKL_DPLL3: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9692 | id = DPLL_ID_SKL_DPLL3; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9693 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9694 | default: |
| 9695 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9696 | return; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9697 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9698 | |
| 9699 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9700 | } |
| 9701 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9702 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9703 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9704 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9705 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9706 | enum intel_dpll_id id; |
| 9707 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9708 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 9709 | |
| 9710 | switch (pipe_config->ddi_pll_sel) { |
| 9711 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9712 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9713 | break; |
| 9714 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9715 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9716 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9717 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9718 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9719 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9720 | case PORT_CLK_SEL_LCPLL_810: |
| 9721 | id = DPLL_ID_LCPLL_810; |
| 9722 | break; |
| 9723 | case PORT_CLK_SEL_LCPLL_1350: |
| 9724 | id = DPLL_ID_LCPLL_1350; |
| 9725 | break; |
| 9726 | case PORT_CLK_SEL_LCPLL_2700: |
| 9727 | id = DPLL_ID_LCPLL_2700; |
| 9728 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9729 | default: |
| 9730 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9731 | /* fall through */ |
| 9732 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9733 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9734 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9735 | |
| 9736 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9737 | } |
| 9738 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9739 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9740 | struct intel_crtc_state *pipe_config, |
| 9741 | unsigned long *power_domain_mask) |
| 9742 | { |
| 9743 | struct drm_device *dev = crtc->base.dev; |
| 9744 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9745 | enum intel_display_power_domain power_domain; |
| 9746 | u32 tmp; |
| 9747 | |
| 9748 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9749 | |
| 9750 | /* |
| 9751 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9752 | * consistency and less surprising code; it's in always on power). |
| 9753 | */ |
| 9754 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9755 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9756 | enum pipe trans_edp_pipe; |
| 9757 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9758 | default: |
| 9759 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 9760 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9761 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9762 | trans_edp_pipe = PIPE_A; |
| 9763 | break; |
| 9764 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9765 | trans_edp_pipe = PIPE_B; |
| 9766 | break; |
| 9767 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9768 | trans_edp_pipe = PIPE_C; |
| 9769 | break; |
| 9770 | } |
| 9771 | |
| 9772 | if (trans_edp_pipe == crtc->pipe) |
| 9773 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9774 | } |
| 9775 | |
| 9776 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9777 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9778 | return false; |
| 9779 | *power_domain_mask |= BIT(power_domain); |
| 9780 | |
| 9781 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9782 | |
| 9783 | return tmp & PIPECONF_ENABLE; |
| 9784 | } |
| 9785 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9786 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9787 | struct intel_crtc_state *pipe_config, |
| 9788 | unsigned long *power_domain_mask) |
| 9789 | { |
| 9790 | struct drm_device *dev = crtc->base.dev; |
| 9791 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9792 | enum intel_display_power_domain power_domain; |
| 9793 | enum port port; |
| 9794 | enum transcoder cpu_transcoder; |
| 9795 | u32 tmp; |
| 9796 | |
| 9797 | pipe_config->has_dsi_encoder = false; |
| 9798 | |
| 9799 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9800 | if (port == PORT_A) |
| 9801 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9802 | else |
| 9803 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9804 | |
| 9805 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9806 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9807 | continue; |
| 9808 | *power_domain_mask |= BIT(power_domain); |
| 9809 | |
| 9810 | /* XXX: this works for video mode only */ |
| 9811 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9812 | if (!(tmp & DPI_ENABLE)) |
| 9813 | continue; |
| 9814 | |
| 9815 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9816 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9817 | continue; |
| 9818 | |
| 9819 | pipe_config->cpu_transcoder = cpu_transcoder; |
| 9820 | pipe_config->has_dsi_encoder = true; |
| 9821 | break; |
| 9822 | } |
| 9823 | |
| 9824 | return pipe_config->has_dsi_encoder; |
| 9825 | } |
| 9826 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9827 | 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] | 9828 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9829 | { |
| 9830 | struct drm_device *dev = crtc->base.dev; |
| 9831 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9832 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9833 | enum port port; |
| 9834 | uint32_t tmp; |
| 9835 | |
| 9836 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9837 | |
| 9838 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9839 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 9840 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9841 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9842 | else if (IS_BROXTON(dev)) |
| 9843 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9844 | else |
| 9845 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9846 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9847 | pll = pipe_config->shared_dpll; |
| 9848 | if (pll) { |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9849 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 9850 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9851 | } |
| 9852 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9853 | /* |
| 9854 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9855 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9856 | * the PCH transcoder is on. |
| 9857 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9858 | if (INTEL_INFO(dev)->gen < 9 && |
| 9859 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9860 | pipe_config->has_pch_encoder = true; |
| 9861 | |
| 9862 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9863 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9864 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9865 | |
| 9866 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9867 | } |
| 9868 | } |
| 9869 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9870 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9871 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9872 | { |
| 9873 | struct drm_device *dev = crtc->base.dev; |
| 9874 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9875 | enum intel_display_power_domain power_domain; |
| 9876 | unsigned long power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9877 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9878 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9879 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9880 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9881 | return false; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9882 | power_domain_mask = BIT(power_domain); |
| 9883 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9884 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9885 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9886 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9887 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9888 | if (IS_BROXTON(dev_priv)) { |
| 9889 | bxt_get_dsi_transcoder_state(crtc, pipe_config, |
| 9890 | &power_domain_mask); |
| 9891 | WARN_ON(active && pipe_config->has_dsi_encoder); |
| 9892 | if (pipe_config->has_dsi_encoder) |
| 9893 | active = true; |
| 9894 | } |
| 9895 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9896 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9897 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9898 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9899 | if (!pipe_config->has_dsi_encoder) { |
| 9900 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9901 | intel_get_pipe_timings(crtc, pipe_config); |
| 9902 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9903 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9904 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9905 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9906 | pipe_config->gamma_mode = |
| 9907 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9908 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9909 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9910 | skl_init_scalers(dev, crtc, pipe_config); |
| 9911 | } |
| 9912 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 9913 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9914 | pipe_config->scaler_state.scaler_id = -1; |
| 9915 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
| 9916 | } |
| 9917 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9918 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9919 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
| 9920 | power_domain_mask |= BIT(power_domain); |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9921 | if (INTEL_INFO(dev)->gen >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9922 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9923 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9924 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9925 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9926 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 9927 | if (IS_HASWELL(dev)) |
| 9928 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 9929 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 9930 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9931 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9932 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9933 | pipe_config->pixel_multiplier = |
| 9934 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9935 | } else { |
| 9936 | pipe_config->pixel_multiplier = 1; |
| 9937 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9938 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9939 | out: |
| 9940 | for_each_power_domain(power_domain, power_domain_mask) |
| 9941 | intel_display_power_put(dev_priv, power_domain); |
| 9942 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9943 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9944 | } |
| 9945 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9946 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
| 9947 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9948 | { |
| 9949 | struct drm_device *dev = crtc->dev; |
| 9950 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9951 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9952 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9953 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9954 | if (plane_state && plane_state->visible) { |
| 9955 | unsigned int width = plane_state->base.crtc_w; |
| 9956 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9957 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 9958 | |
| 9959 | switch (stride) { |
| 9960 | default: |
| 9961 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 9962 | width, stride); |
| 9963 | stride = 256; |
| 9964 | /* fallthrough */ |
| 9965 | case 256: |
| 9966 | case 512: |
| 9967 | case 1024: |
| 9968 | case 2048: |
| 9969 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9970 | } |
| 9971 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9972 | cntl |= CURSOR_ENABLE | |
| 9973 | CURSOR_GAMMA_ENABLE | |
| 9974 | CURSOR_FORMAT_ARGB | |
| 9975 | CURSOR_STRIDE(stride); |
| 9976 | |
| 9977 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9978 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9979 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9980 | if (intel_crtc->cursor_cntl != 0 && |
| 9981 | (intel_crtc->cursor_base != base || |
| 9982 | intel_crtc->cursor_size != size || |
| 9983 | intel_crtc->cursor_cntl != cntl)) { |
| 9984 | /* On these chipsets we can only modify the base/size/stride |
| 9985 | * whilst the cursor is disabled. |
| 9986 | */ |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 9987 | I915_WRITE(CURCNTR(PIPE_A), 0); |
| 9988 | POSTING_READ(CURCNTR(PIPE_A)); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9989 | intel_crtc->cursor_cntl = 0; |
| 9990 | } |
| 9991 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9992 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 9993 | I915_WRITE(CURBASE(PIPE_A), base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 9994 | intel_crtc->cursor_base = base; |
| 9995 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9996 | |
| 9997 | if (intel_crtc->cursor_size != size) { |
| 9998 | I915_WRITE(CURSIZE, size); |
| 9999 | intel_crtc->cursor_size = size; |
| 10000 | } |
| 10001 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10002 | if (intel_crtc->cursor_cntl != cntl) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10003 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
| 10004 | POSTING_READ(CURCNTR(PIPE_A)); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10005 | intel_crtc->cursor_cntl = cntl; |
| 10006 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10007 | } |
| 10008 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10009 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10010 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10011 | { |
| 10012 | struct drm_device *dev = crtc->dev; |
| 10013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10014 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10015 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | 663f312 | 2015-12-14 13:16:48 +0200 | [diff] [blame] | 10016 | uint32_t cntl = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10017 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10018 | if (plane_state && plane_state->visible) { |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10019 | cntl = MCURSOR_GAMMA_ENABLE; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10020 | switch (plane_state->base.crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10021 | case 64: |
| 10022 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 10023 | break; |
| 10024 | case 128: |
| 10025 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 10026 | break; |
| 10027 | case 256: |
| 10028 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 10029 | break; |
| 10030 | default: |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10031 | MISSING_CASE(plane_state->base.crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10032 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10033 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10034 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10035 | |
Bob Paauwe | fc6f93b | 2015-08-31 14:03:30 -0700 | [diff] [blame] | 10036 | if (HAS_DDI(dev)) |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10037 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10038 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10039 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) |
| 10040 | cntl |= CURSOR_ROTATE_180; |
| 10041 | } |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 10042 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10043 | if (intel_crtc->cursor_cntl != cntl) { |
| 10044 | I915_WRITE(CURCNTR(pipe), cntl); |
| 10045 | POSTING_READ(CURCNTR(pipe)); |
| 10046 | intel_crtc->cursor_cntl = cntl; |
| 10047 | } |
| 10048 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10049 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10050 | I915_WRITE(CURBASE(pipe), base); |
| 10051 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10052 | |
| 10053 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10054 | } |
| 10055 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10056 | /* 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] | 10057 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10058 | const struct intel_plane_state *plane_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10059 | { |
| 10060 | struct drm_device *dev = crtc->dev; |
| 10061 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10063 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10064 | u32 base = intel_crtc->cursor_addr; |
| 10065 | u32 pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10066 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10067 | if (plane_state) { |
| 10068 | int x = plane_state->base.crtc_x; |
| 10069 | int y = plane_state->base.crtc_y; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10070 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10071 | if (x < 0) { |
| 10072 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 10073 | x = -x; |
| 10074 | } |
| 10075 | pos |= x << CURSOR_X_SHIFT; |
| 10076 | |
| 10077 | if (y < 0) { |
| 10078 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 10079 | y = -y; |
| 10080 | } |
| 10081 | pos |= y << CURSOR_Y_SHIFT; |
| 10082 | |
| 10083 | /* ILK+ do this automagically */ |
| 10084 | if (HAS_GMCH_DISPLAY(dev) && |
| 10085 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { |
| 10086 | base += (plane_state->base.crtc_h * |
| 10087 | plane_state->base.crtc_w - 1) * 4; |
| 10088 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10089 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10090 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10091 | I915_WRITE(CURPOS(pipe), pos); |
| 10092 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 10093 | if (IS_845G(dev) || IS_I865G(dev)) |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10094 | i845_update_cursor(crtc, base, plane_state); |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10095 | else |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10096 | i9xx_update_cursor(crtc, base, plane_state); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10097 | } |
| 10098 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10099 | static bool cursor_size_ok(struct drm_device *dev, |
| 10100 | uint32_t width, uint32_t height) |
| 10101 | { |
| 10102 | if (width == 0 || height == 0) |
| 10103 | return false; |
| 10104 | |
| 10105 | /* |
| 10106 | * 845g/865g are special in that they are only limited by |
| 10107 | * the width of their cursors, the height is arbitrary up to |
| 10108 | * the precision of the register. Everything else requires |
| 10109 | * square cursors, limited to a few power-of-two sizes. |
| 10110 | */ |
| 10111 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 10112 | if ((width & 63) != 0) |
| 10113 | return false; |
| 10114 | |
| 10115 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 10116 | return false; |
| 10117 | |
| 10118 | if (height > 1023) |
| 10119 | return false; |
| 10120 | } else { |
| 10121 | switch (width | height) { |
| 10122 | case 256: |
| 10123 | case 128: |
| 10124 | if (IS_GEN2(dev)) |
| 10125 | return false; |
| 10126 | case 64: |
| 10127 | break; |
| 10128 | default: |
| 10129 | return false; |
| 10130 | } |
| 10131 | } |
| 10132 | |
| 10133 | return true; |
| 10134 | } |
| 10135 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10136 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 10137 | static struct drm_display_mode load_detect_mode = { |
| 10138 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10139 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10140 | }; |
| 10141 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10142 | struct drm_framebuffer * |
| 10143 | __intel_framebuffer_create(struct drm_device *dev, |
| 10144 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10145 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10146 | { |
| 10147 | struct intel_framebuffer *intel_fb; |
| 10148 | int ret; |
| 10149 | |
| 10150 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10151 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10152 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10153 | |
| 10154 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10155 | if (ret) |
| 10156 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10157 | |
| 10158 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10159 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10160 | err: |
| 10161 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10162 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10163 | } |
| 10164 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 10165 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10166 | intel_framebuffer_create(struct drm_device *dev, |
| 10167 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10168 | struct drm_i915_gem_object *obj) |
| 10169 | { |
| 10170 | struct drm_framebuffer *fb; |
| 10171 | int ret; |
| 10172 | |
| 10173 | ret = i915_mutex_lock_interruptible(dev); |
| 10174 | if (ret) |
| 10175 | return ERR_PTR(ret); |
| 10176 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 10177 | mutex_unlock(&dev->struct_mutex); |
| 10178 | |
| 10179 | return fb; |
| 10180 | } |
| 10181 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10182 | static u32 |
| 10183 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 10184 | { |
| 10185 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 10186 | return ALIGN(pitch, 64); |
| 10187 | } |
| 10188 | |
| 10189 | static u32 |
| 10190 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 10191 | { |
| 10192 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 10193 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10194 | } |
| 10195 | |
| 10196 | static struct drm_framebuffer * |
| 10197 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 10198 | struct drm_display_mode *mode, |
| 10199 | int depth, int bpp) |
| 10200 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10201 | struct drm_framebuffer *fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10202 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 10203 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10204 | |
| 10205 | obj = i915_gem_alloc_object(dev, |
| 10206 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 10207 | if (obj == NULL) |
| 10208 | return ERR_PTR(-ENOMEM); |
| 10209 | |
| 10210 | mode_cmd.width = mode->hdisplay; |
| 10211 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 10212 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 10213 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 10214 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10215 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10216 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
| 10217 | if (IS_ERR(fb)) |
| 10218 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10219 | |
| 10220 | return fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10221 | } |
| 10222 | |
| 10223 | static struct drm_framebuffer * |
| 10224 | mode_fits_in_fbdev(struct drm_device *dev, |
| 10225 | struct drm_display_mode *mode) |
| 10226 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 10227 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10228 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10229 | struct drm_i915_gem_object *obj; |
| 10230 | struct drm_framebuffer *fb; |
| 10231 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10232 | if (!dev_priv->fbdev) |
| 10233 | return NULL; |
| 10234 | |
| 10235 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10236 | return NULL; |
| 10237 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10238 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10239 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10240 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10241 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10242 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 10243 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10244 | return NULL; |
| 10245 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10246 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10247 | return NULL; |
| 10248 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10249 | drm_framebuffer_reference(fb); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10250 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 10251 | #else |
| 10252 | return NULL; |
| 10253 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10254 | } |
| 10255 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10256 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 10257 | struct drm_crtc *crtc, |
| 10258 | struct drm_display_mode *mode, |
| 10259 | struct drm_framebuffer *fb, |
| 10260 | int x, int y) |
| 10261 | { |
| 10262 | struct drm_plane_state *plane_state; |
| 10263 | int hdisplay, vdisplay; |
| 10264 | int ret; |
| 10265 | |
| 10266 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 10267 | if (IS_ERR(plane_state)) |
| 10268 | return PTR_ERR(plane_state); |
| 10269 | |
| 10270 | if (mode) |
| 10271 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 10272 | else |
| 10273 | hdisplay = vdisplay = 0; |
| 10274 | |
| 10275 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 10276 | if (ret) |
| 10277 | return ret; |
| 10278 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 10279 | plane_state->crtc_x = 0; |
| 10280 | plane_state->crtc_y = 0; |
| 10281 | plane_state->crtc_w = hdisplay; |
| 10282 | plane_state->crtc_h = vdisplay; |
| 10283 | plane_state->src_x = x << 16; |
| 10284 | plane_state->src_y = y << 16; |
| 10285 | plane_state->src_w = hdisplay << 16; |
| 10286 | plane_state->src_h = vdisplay << 16; |
| 10287 | |
| 10288 | return 0; |
| 10289 | } |
| 10290 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10291 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10292 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10293 | struct intel_load_detect_pipe *old, |
| 10294 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10295 | { |
| 10296 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10297 | struct intel_encoder *intel_encoder = |
| 10298 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10299 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10300 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10301 | struct drm_crtc *crtc = NULL; |
| 10302 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10303 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10304 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10305 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10306 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10307 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10308 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10309 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10310 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10311 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10312 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10313 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10314 | old->restore_state = NULL; |
| 10315 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10316 | retry: |
| 10317 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 10318 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10319 | goto fail; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10320 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10321 | /* |
| 10322 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10323 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10324 | * - if the connector already has an assigned crtc, use it (but make |
| 10325 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10326 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10327 | * - try to find the first unused crtc that can drive this connector, |
| 10328 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10329 | */ |
| 10330 | |
| 10331 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10332 | if (connector->state->crtc) { |
| 10333 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10334 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10335 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10336 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10337 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10338 | |
| 10339 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10340 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10341 | } |
| 10342 | |
| 10343 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10344 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10345 | i++; |
| 10346 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10347 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10348 | |
| 10349 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10350 | if (ret) |
| 10351 | goto fail; |
| 10352 | |
| 10353 | if (possible_crtc->state->enable) { |
| 10354 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10355 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10356 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10357 | |
| 10358 | crtc = possible_crtc; |
| 10359 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10360 | } |
| 10361 | |
| 10362 | /* |
| 10363 | * If we didn't find an unused CRTC, don't use any. |
| 10364 | */ |
| 10365 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10366 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10367 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10368 | } |
| 10369 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10370 | found: |
| 10371 | intel_crtc = to_intel_crtc(crtc); |
| 10372 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 10373 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 10374 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10375 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10376 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10377 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10378 | restore_state = drm_atomic_state_alloc(dev); |
| 10379 | if (!state || !restore_state) { |
| 10380 | ret = -ENOMEM; |
| 10381 | goto fail; |
| 10382 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10383 | |
| 10384 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10385 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10386 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10387 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10388 | if (IS_ERR(connector_state)) { |
| 10389 | ret = PTR_ERR(connector_state); |
| 10390 | goto fail; |
| 10391 | } |
| 10392 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10393 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10394 | if (ret) |
| 10395 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10396 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10397 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10398 | if (IS_ERR(crtc_state)) { |
| 10399 | ret = PTR_ERR(crtc_state); |
| 10400 | goto fail; |
| 10401 | } |
| 10402 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10403 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10404 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10405 | if (!mode) |
| 10406 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10407 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10408 | /* We need a framebuffer large enough to accommodate all accesses |
| 10409 | * that the plane may generate whilst we perform load detection. |
| 10410 | * We can not rely on the fbcon either being present (we get called |
| 10411 | * during its initialisation to detect all boot displays, or it may |
| 10412 | * not even exist) or that it is large enough to satisfy the |
| 10413 | * requested mode. |
| 10414 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10415 | fb = mode_fits_in_fbdev(dev, mode); |
| 10416 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10417 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10418 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10419 | } else |
| 10420 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10421 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10422 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10423 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10424 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10425 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10426 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 10427 | if (ret) |
| 10428 | goto fail; |
| 10429 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10430 | drm_framebuffer_unreference(fb); |
| 10431 | |
| 10432 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
| 10433 | if (ret) |
| 10434 | goto fail; |
| 10435 | |
| 10436 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10437 | if (!ret) |
| 10438 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); |
| 10439 | if (!ret) |
| 10440 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); |
| 10441 | if (ret) { |
| 10442 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10443 | goto fail; |
| 10444 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10445 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10446 | ret = drm_atomic_commit(state); |
| 10447 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10448 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10449 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10450 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10451 | |
| 10452 | old->restore_state = restore_state; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10453 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10454 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 10455 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10456 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10457 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10458 | fail: |
Ander Conselvan de Oliveira | e5d958e | 2015-04-21 17:12:57 +0300 | [diff] [blame] | 10459 | drm_atomic_state_free(state); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10460 | drm_atomic_state_free(restore_state); |
| 10461 | restore_state = state = NULL; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10462 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10463 | if (ret == -EDEADLK) { |
| 10464 | drm_modeset_backoff(ctx); |
| 10465 | goto retry; |
| 10466 | } |
| 10467 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10468 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10469 | } |
| 10470 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10471 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10472 | struct intel_load_detect_pipe *old, |
| 10473 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10474 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10475 | struct intel_encoder *intel_encoder = |
| 10476 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10477 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10478 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10479 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10480 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10481 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10482 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10483 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10484 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10485 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10486 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10487 | |
| 10488 | ret = drm_atomic_commit(state); |
| 10489 | if (ret) { |
| 10490 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
| 10491 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10492 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10493 | } |
| 10494 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10495 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10496 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10497 | { |
| 10498 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10499 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10500 | |
| 10501 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10502 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10503 | else if (HAS_PCH_SPLIT(dev)) |
| 10504 | return 120000; |
| 10505 | else if (!IS_GEN2(dev)) |
| 10506 | return 96000; |
| 10507 | else |
| 10508 | return 48000; |
| 10509 | } |
| 10510 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10511 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10512 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10513 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10514 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10515 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10516 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10517 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10518 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10519 | u32 fp; |
| 10520 | intel_clock_t clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10521 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10522 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10523 | |
| 10524 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10525 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10526 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10527 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10528 | |
| 10529 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10530 | if (IS_PINEVIEW(dev)) { |
| 10531 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10532 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10533 | } else { |
| 10534 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10535 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10536 | } |
| 10537 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 10538 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10539 | if (IS_PINEVIEW(dev)) |
| 10540 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10541 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10542 | else |
| 10543 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10544 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10545 | |
| 10546 | switch (dpll & DPLL_MODE_MASK) { |
| 10547 | case DPLLB_MODE_DAC_SERIAL: |
| 10548 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10549 | 5 : 10; |
| 10550 | break; |
| 10551 | case DPLLB_MODE_LVDS: |
| 10552 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10553 | 7 : 14; |
| 10554 | break; |
| 10555 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10556 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10557 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10558 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10559 | } |
| 10560 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10561 | if (IS_PINEVIEW(dev)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10562 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10563 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10564 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10565 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 10566 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10567 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10568 | |
| 10569 | if (is_lvds) { |
| 10570 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10571 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10572 | |
| 10573 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10574 | clock.p2 = 7; |
| 10575 | else |
| 10576 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10577 | } else { |
| 10578 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10579 | clock.p1 = 2; |
| 10580 | else { |
| 10581 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10582 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10583 | } |
| 10584 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10585 | clock.p2 = 4; |
| 10586 | else |
| 10587 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10588 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10589 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10590 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10591 | } |
| 10592 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10593 | /* |
| 10594 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10595 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10596 | * encoder's get_config() function. |
| 10597 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10598 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10599 | } |
| 10600 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10601 | int intel_dotclock_calculate(int link_freq, |
| 10602 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10603 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10604 | /* |
| 10605 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10606 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10607 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10608 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10609 | * |
| 10610 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10611 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10612 | */ |
| 10613 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10614 | if (!m_n->link_n) |
| 10615 | return 0; |
| 10616 | |
| 10617 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 10618 | } |
| 10619 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10620 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10621 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10622 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10623 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10624 | |
| 10625 | /* read out port_clock from the DPLL */ |
| 10626 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10627 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10628 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10629 | * In case there is an active pipe without active ports, |
| 10630 | * we may need some idea for the dotclock anyway. |
| 10631 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10632 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10633 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10634 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10635 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10636 | } |
| 10637 | |
| 10638 | /** Returns the currently programmed mode of the given pipe. */ |
| 10639 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 10640 | struct drm_crtc *crtc) |
| 10641 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 10642 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10643 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10644 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10645 | struct drm_display_mode *mode; |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10646 | struct intel_crtc_state *pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10647 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 10648 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10649 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 10650 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10651 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10652 | |
| 10653 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10654 | if (!mode) |
| 10655 | return NULL; |
| 10656 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10657 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10658 | if (!pipe_config) { |
| 10659 | kfree(mode); |
| 10660 | return NULL; |
| 10661 | } |
| 10662 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10663 | /* |
| 10664 | * Construct a pipe_config sufficient for getting the clock info |
| 10665 | * back out of crtc_clock_get. |
| 10666 | * |
| 10667 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 10668 | * to use a real value here instead. |
| 10669 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10670 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
| 10671 | pipe_config->pixel_multiplier = 1; |
| 10672 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 10673 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 10674 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
| 10675 | i9xx_crtc_clock_get(intel_crtc, pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10676 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10677 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10678 | mode->hdisplay = (htot & 0xffff) + 1; |
| 10679 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 10680 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 10681 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 10682 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 10683 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 10684 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 10685 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 10686 | |
| 10687 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10688 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10689 | kfree(pipe_config); |
| 10690 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10691 | return mode; |
| 10692 | } |
| 10693 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10694 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10695 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10696 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10697 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10698 | if (dev_priv->mm.busy) |
| 10699 | return; |
| 10700 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10701 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10702 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 10703 | if (INTEL_INFO(dev)->gen >= 6) |
| 10704 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10705 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10706 | } |
| 10707 | |
| 10708 | void intel_mark_idle(struct drm_device *dev) |
| 10709 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10710 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 10711 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10712 | if (!dev_priv->mm.busy) |
| 10713 | return; |
| 10714 | |
| 10715 | dev_priv->mm.busy = false; |
| 10716 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 10717 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 10718 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 10719 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10720 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10721 | } |
| 10722 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10723 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10724 | { |
| 10725 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10726 | struct drm_device *dev = crtc->dev; |
| 10727 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10728 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10729 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10730 | work = intel_crtc->unpin_work; |
| 10731 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10732 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10733 | |
| 10734 | if (work) { |
| 10735 | cancel_work_sync(&work->work); |
| 10736 | kfree(work); |
| 10737 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10738 | |
| 10739 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10740 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10741 | kfree(intel_crtc); |
| 10742 | } |
| 10743 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10744 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 10745 | { |
| 10746 | struct intel_unpin_work *work = |
| 10747 | container_of(__work, struct intel_unpin_work, work); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10748 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 10749 | struct drm_device *dev = crtc->base.dev; |
| 10750 | struct drm_plane *primary = crtc->base.primary; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10751 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10752 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 10753 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10754 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 10755 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10756 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10757 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10758 | mutex_unlock(&dev->struct_mutex); |
| 10759 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10760 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
Paulo Zanoni | 1eb5223 | 2016-01-19 11:35:44 -0200 | [diff] [blame] | 10761 | intel_fbc_post_update(crtc); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10762 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10763 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10764 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
| 10765 | atomic_dec(&crtc->unpin_work_count); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10766 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10767 | kfree(work); |
| 10768 | } |
| 10769 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10770 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10771 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10772 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10773 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10774 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10775 | unsigned long flags; |
| 10776 | |
| 10777 | /* Ignore early vblank irqs */ |
| 10778 | if (intel_crtc == NULL) |
| 10779 | return; |
| 10780 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10781 | /* |
| 10782 | * This is called both by irq handlers and the reset code (to complete |
| 10783 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10784 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10785 | spin_lock_irqsave(&dev->event_lock, flags); |
| 10786 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10787 | |
| 10788 | /* Ensure we don't miss a work->pending update ... */ |
| 10789 | smp_rmb(); |
| 10790 | |
| 10791 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10792 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10793 | return; |
| 10794 | } |
| 10795 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10796 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 10797 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10798 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10799 | } |
| 10800 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10801 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 10802 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10803 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10804 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10805 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10806 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10807 | } |
| 10808 | |
| 10809 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 10810 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10811 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10812 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 10813 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10814 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10815 | } |
| 10816 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10817 | /* Is 'a' after or equal to 'b'? */ |
| 10818 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 10819 | { |
| 10820 | return !((a - b) & 0x80000000); |
| 10821 | } |
| 10822 | |
| 10823 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 10824 | { |
| 10825 | struct drm_device *dev = crtc->base.dev; |
| 10826 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10827 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 10828 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 10829 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 10830 | return true; |
| 10831 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10832 | /* |
| 10833 | * The relevant registers doen't exist on pre-ctg. |
| 10834 | * As the flip done interrupt doesn't trigger for mmio |
| 10835 | * flips on gmch platforms, a flip count check isn't |
| 10836 | * really needed there. But since ctg has the registers, |
| 10837 | * include it in the check anyway. |
| 10838 | */ |
| 10839 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 10840 | return true; |
| 10841 | |
| 10842 | /* |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10843 | * BDW signals flip done immediately if the plane |
| 10844 | * is disabled, even if the plane enable is already |
| 10845 | * armed to occur at the next vblank :( |
| 10846 | */ |
| 10847 | |
| 10848 | /* |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10849 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 10850 | * used the same base address. In that case the mmio flip might |
| 10851 | * have completed, but the CS hasn't even executed the flip yet. |
| 10852 | * |
| 10853 | * A flip count check isn't enough as the CS might have updated |
| 10854 | * the base address just after start of vblank, but before we |
| 10855 | * managed to process the interrupt. This means we'd complete the |
| 10856 | * CS flip too soon. |
| 10857 | * |
| 10858 | * Combining both checks should get us a good enough result. It may |
| 10859 | * still happen that the CS flip has been executed, but has not |
| 10860 | * yet actually completed. But in case the base address is the same |
| 10861 | * anyway, we don't really care. |
| 10862 | */ |
| 10863 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 10864 | crtc->unpin_work->gtt_offset && |
Ville Syrjälä | fd8f507c | 2015-09-18 20:03:42 +0300 | [diff] [blame] | 10865 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10866 | crtc->unpin_work->flip_count); |
| 10867 | } |
| 10868 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10869 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 10870 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10871 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10872 | struct intel_crtc *intel_crtc = |
| 10873 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 10874 | unsigned long flags; |
| 10875 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10876 | |
| 10877 | /* |
| 10878 | * This is called both by irq handlers and the reset code (to complete |
| 10879 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10880 | * |
| 10881 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10882 | * generate a page-flip completion irq, i.e. every modeset |
| 10883 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 10884 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10885 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10886 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10887 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10888 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10889 | } |
| 10890 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10891 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10892 | { |
| 10893 | /* Ensure that the work item is consistent when activating it ... */ |
| 10894 | smp_wmb(); |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10895 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10896 | /* and that it is marked active as soon as the irq could fire. */ |
| 10897 | smp_wmb(); |
| 10898 | } |
| 10899 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10900 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 10901 | struct drm_crtc *crtc, |
| 10902 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10903 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10904 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10905 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10906 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 10907 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10908 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10909 | u32 flip_mask; |
| 10910 | int ret; |
| 10911 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10912 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10913 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10914 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10915 | |
| 10916 | /* Can't queue multiple flips, so wait for the previous |
| 10917 | * one to finish before executing the next. |
| 10918 | */ |
| 10919 | if (intel_crtc->plane) |
| 10920 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10921 | else |
| 10922 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10923 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 10924 | intel_ring_emit(engine, MI_NOOP); |
| 10925 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10926 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10927 | intel_ring_emit(engine, fb->pitches[0]); |
| 10928 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 10929 | intel_ring_emit(engine, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10930 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10931 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10932 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10933 | } |
| 10934 | |
| 10935 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 10936 | struct drm_crtc *crtc, |
| 10937 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10938 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10939 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10940 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10941 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 10942 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10943 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10944 | u32 flip_mask; |
| 10945 | int ret; |
| 10946 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10947 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10948 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10949 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10950 | |
| 10951 | if (intel_crtc->plane) |
| 10952 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 10953 | else |
| 10954 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10955 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 10956 | intel_ring_emit(engine, MI_NOOP); |
| 10957 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10958 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10959 | intel_ring_emit(engine, fb->pitches[0]); |
| 10960 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 10961 | intel_ring_emit(engine, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10962 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10963 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10964 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10965 | } |
| 10966 | |
| 10967 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 10968 | struct drm_crtc *crtc, |
| 10969 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10970 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10971 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10972 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10973 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 10974 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10976 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10977 | uint32_t pf, pipesrc; |
| 10978 | int ret; |
| 10979 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10980 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10981 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10982 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10983 | |
| 10984 | /* i965+ uses the linear or tiled offsets from the |
| 10985 | * Display Registers (which do not change across a page-flip) |
| 10986 | * so we need only reprogram the base address. |
| 10987 | */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10988 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 10989 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 10990 | intel_ring_emit(engine, fb->pitches[0]); |
| 10991 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 10992 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10993 | |
| 10994 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 10995 | * untested on non-native modes, so ignore it for now. |
| 10996 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 10997 | */ |
| 10998 | pf = 0; |
| 10999 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11000 | intel_ring_emit(engine, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11001 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11002 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11003 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11004 | } |
| 11005 | |
| 11006 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 11007 | struct drm_crtc *crtc, |
| 11008 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11009 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11010 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11011 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11012 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11013 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11014 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11016 | uint32_t pf, pipesrc; |
| 11017 | int ret; |
| 11018 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11019 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11020 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11021 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11022 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11023 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 11024 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11025 | intel_ring_emit(engine, fb->pitches[0] | obj->tiling_mode); |
| 11026 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11027 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 11028 | /* Contrary to the suggestions in the documentation, |
| 11029 | * "Enable Panel Fitter" does not seem to be required when page |
| 11030 | * flipping with a non-native mode, and worse causes a normal |
| 11031 | * modeset to fail. |
| 11032 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 11033 | */ |
| 11034 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11035 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11036 | intel_ring_emit(engine, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11037 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11038 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11039 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11040 | } |
| 11041 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11042 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 11043 | struct drm_crtc *crtc, |
| 11044 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11045 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11046 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11047 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11048 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11049 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11050 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11051 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11052 | int len, ret; |
| 11053 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 11054 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11055 | case PLANE_A: |
| 11056 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 11057 | break; |
| 11058 | case PLANE_B: |
| 11059 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 11060 | break; |
| 11061 | case PLANE_C: |
| 11062 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 11063 | break; |
| 11064 | default: |
| 11065 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11066 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11067 | } |
| 11068 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11069 | len = 4; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11070 | if (engine->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11071 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11072 | /* |
| 11073 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 11074 | * 48bits addresses, and we need a NOOP for the batch size to |
| 11075 | * stay even. |
| 11076 | */ |
| 11077 | if (IS_GEN8(dev)) |
| 11078 | len += 2; |
| 11079 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11080 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11081 | /* |
| 11082 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 11083 | * "The full packet must be contained within the same cache line." |
| 11084 | * |
| 11085 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 11086 | * cacheline, if we ever start emitting more commands before |
| 11087 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 11088 | * then do the cacheline alignment, and finally emit the |
| 11089 | * MI_DISPLAY_FLIP. |
| 11090 | */ |
John Harrison | bba09b1 | 2015-05-29 17:44:06 +0100 | [diff] [blame] | 11091 | ret = intel_ring_cacheline_align(req); |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11092 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11093 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11094 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11095 | ret = intel_ring_begin(req, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11096 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11097 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11098 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11099 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 11100 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 11101 | * more than one flip event at any time (or ensure that one flip message |
| 11102 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 11103 | * Experimentation says that BCS works despite DERRMR masking all |
| 11104 | * flip-done completion events and that unmasking all planes at once |
| 11105 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 11106 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 11107 | */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11108 | if (engine->id == RCS) { |
| 11109 | intel_ring_emit(engine, MI_LOAD_REGISTER_IMM(1)); |
| 11110 | intel_ring_emit_reg(engine, DERRMR); |
| 11111 | intel_ring_emit(engine, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 11112 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 11113 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11114 | if (IS_GEN8(dev)) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11115 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM_GEN8 | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11116 | MI_SRM_LRM_GLOBAL_GTT); |
| 11117 | else |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11118 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11119 | MI_SRM_LRM_GLOBAL_GTT); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11120 | intel_ring_emit_reg(engine, DERRMR); |
| 11121 | intel_ring_emit(engine, engine->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11122 | if (IS_GEN8(dev)) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11123 | intel_ring_emit(engine, 0); |
| 11124 | intel_ring_emit(engine, MI_NOOP); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11125 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11126 | } |
| 11127 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11128 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | plane_bit); |
| 11129 | intel_ring_emit(engine, (fb->pitches[0] | obj->tiling_mode)); |
| 11130 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 11131 | intel_ring_emit(engine, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11132 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11133 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11134 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11135 | } |
| 11136 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11137 | static bool use_mmio_flip(struct intel_engine_cs *engine, |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11138 | struct drm_i915_gem_object *obj) |
| 11139 | { |
| 11140 | /* |
| 11141 | * This is not being used for older platforms, because |
| 11142 | * non-availability of flip done interrupt forces us to use |
| 11143 | * CS flips. Older platforms derive flip done using some clever |
| 11144 | * tricks involving the flip_pending status bits and vblank irqs. |
| 11145 | * So using MMIO flips there would disrupt this mechanism. |
| 11146 | */ |
| 11147 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11148 | if (engine == NULL) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11149 | return true; |
| 11150 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11151 | if (INTEL_INFO(engine->dev)->gen < 5) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11152 | return false; |
| 11153 | |
| 11154 | if (i915.use_mmio_flip < 0) |
| 11155 | return false; |
| 11156 | else if (i915.use_mmio_flip > 0) |
| 11157 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 11158 | else if (i915.enable_execlists) |
| 11159 | return true; |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11160 | else if (obj->base.dma_buf && |
| 11161 | !reservation_object_test_signaled_rcu(obj->base.dma_buf->resv, |
| 11162 | false)) |
| 11163 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11164 | else |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 11165 | return engine != i915_gem_request_get_engine(obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11166 | } |
| 11167 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11168 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11169 | unsigned int rotation, |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11170 | struct intel_unpin_work *work) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11171 | { |
| 11172 | struct drm_device *dev = intel_crtc->base.dev; |
| 11173 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11174 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11175 | const enum pipe pipe = intel_crtc->pipe; |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11176 | u32 ctl, stride, tile_height; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11177 | |
| 11178 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 11179 | ctl &= ~PLANE_CTL_TILED_MASK; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11180 | switch (fb->modifier[0]) { |
| 11181 | case DRM_FORMAT_MOD_NONE: |
| 11182 | break; |
| 11183 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11184 | ctl |= PLANE_CTL_TILED_X; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11185 | break; |
| 11186 | case I915_FORMAT_MOD_Y_TILED: |
| 11187 | ctl |= PLANE_CTL_TILED_Y; |
| 11188 | break; |
| 11189 | case I915_FORMAT_MOD_Yf_TILED: |
| 11190 | ctl |= PLANE_CTL_TILED_YF; |
| 11191 | break; |
| 11192 | default: |
| 11193 | MISSING_CASE(fb->modifier[0]); |
| 11194 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11195 | |
| 11196 | /* |
| 11197 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 11198 | * linear buffers or in number of tiles for tiled buffers. |
| 11199 | */ |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11200 | if (intel_rotation_90_or_270(rotation)) { |
| 11201 | /* stride = Surface height in tiles */ |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 11202 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11203 | stride = DIV_ROUND_UP(fb->height, tile_height); |
| 11204 | } else { |
| 11205 | stride = fb->pitches[0] / |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 11206 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
| 11207 | fb->pixel_format); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11208 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11209 | |
| 11210 | /* |
| 11211 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 11212 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 11213 | */ |
| 11214 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 11215 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 11216 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11217 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11218 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 11219 | } |
| 11220 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11221 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 11222 | struct intel_unpin_work *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11223 | { |
| 11224 | struct drm_device *dev = intel_crtc->base.dev; |
| 11225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11226 | struct intel_framebuffer *intel_fb = |
| 11227 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 11228 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 11229 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11230 | u32 dspcntr; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11231 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11232 | dspcntr = I915_READ(reg); |
| 11233 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 11234 | if (obj->tiling_mode != I915_TILING_NONE) |
| 11235 | dspcntr |= DISPPLANE_TILED; |
| 11236 | else |
| 11237 | dspcntr &= ~DISPPLANE_TILED; |
| 11238 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11239 | I915_WRITE(reg, dspcntr); |
| 11240 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11241 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11242 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11243 | } |
| 11244 | |
| 11245 | /* |
| 11246 | * XXX: This is the temporary way to update the plane registers until we get |
| 11247 | * around to using the usual plane update functions for MMIO flips |
| 11248 | */ |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11249 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11250 | { |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11251 | struct intel_crtc *crtc = mmio_flip->crtc; |
| 11252 | struct intel_unpin_work *work; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11253 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11254 | spin_lock_irq(&crtc->base.dev->event_lock); |
| 11255 | work = crtc->unpin_work; |
| 11256 | spin_unlock_irq(&crtc->base.dev->event_lock); |
| 11257 | if (work == NULL) |
| 11258 | return; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11259 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11260 | intel_mark_page_flip_active(work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11261 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11262 | intel_pipe_update_start(crtc); |
| 11263 | |
| 11264 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11265 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11266 | else |
| 11267 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11268 | ilk_do_mmio_flip(crtc, work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11269 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11270 | intel_pipe_update_end(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11271 | } |
| 11272 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 11273 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11274 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11275 | struct intel_mmio_flip *mmio_flip = |
| 11276 | container_of(work, struct intel_mmio_flip, work); |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11277 | struct intel_framebuffer *intel_fb = |
| 11278 | to_intel_framebuffer(mmio_flip->crtc->base.primary->fb); |
| 11279 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11280 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11281 | if (mmio_flip->req) { |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11282 | WARN_ON(__i915_wait_request(mmio_flip->req, |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11283 | mmio_flip->crtc->reset_counter, |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11284 | false, NULL, |
| 11285 | &mmio_flip->i915->rps.mmioflips)); |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11286 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
| 11287 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11288 | |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11289 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 11290 | if (obj->base.dma_buf) |
| 11291 | WARN_ON(reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 11292 | false, false, |
| 11293 | MAX_SCHEDULE_TIMEOUT) < 0); |
| 11294 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11295 | intel_do_mmio_flip(mmio_flip); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11296 | kfree(mmio_flip); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11297 | } |
| 11298 | |
| 11299 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 11300 | struct drm_crtc *crtc, |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11301 | struct drm_i915_gem_object *obj) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11302 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11303 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11304 | |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11305 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); |
| 11306 | if (mmio_flip == NULL) |
| 11307 | return -ENOMEM; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11308 | |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11309 | mmio_flip->i915 = to_i915(dev); |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11310 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11311 | mmio_flip->crtc = to_intel_crtc(crtc); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11312 | mmio_flip->rotation = crtc->primary->state->rotation; |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11313 | |
| 11314 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
| 11315 | schedule_work(&mmio_flip->work); |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 11316 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11317 | return 0; |
| 11318 | } |
| 11319 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11320 | static int intel_default_queue_flip(struct drm_device *dev, |
| 11321 | struct drm_crtc *crtc, |
| 11322 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11323 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11324 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11325 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11326 | { |
| 11327 | return -ENODEV; |
| 11328 | } |
| 11329 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11330 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 11331 | struct drm_crtc *crtc) |
| 11332 | { |
| 11333 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11334 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11335 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 11336 | u32 addr; |
| 11337 | |
| 11338 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 11339 | return true; |
| 11340 | |
Chris Wilson | 908565c | 2015-08-12 13:08:22 +0100 | [diff] [blame] | 11341 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
| 11342 | return false; |
| 11343 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11344 | if (!work->enable_stall_check) |
| 11345 | return false; |
| 11346 | |
| 11347 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 11348 | if (work->flip_queued_req && |
| 11349 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11350 | return false; |
| 11351 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11352 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11353 | } |
| 11354 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11355 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11356 | return false; |
| 11357 | |
| 11358 | /* Potential stall - if we see that the flip has happened, |
| 11359 | * assume a missed interrupt. */ |
| 11360 | if (INTEL_INFO(dev)->gen >= 4) |
| 11361 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 11362 | else |
| 11363 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 11364 | |
| 11365 | /* There is a potential issue here with a false positive after a flip |
| 11366 | * to the same address. We could address this by checking for a |
| 11367 | * non-incrementing frame counter. |
| 11368 | */ |
| 11369 | return addr == work->gtt_offset; |
| 11370 | } |
| 11371 | |
| 11372 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 11373 | { |
| 11374 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11375 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 11376 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11377 | struct intel_unpin_work *work; |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11378 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 11379 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11380 | |
| 11381 | if (crtc == NULL) |
| 11382 | return; |
| 11383 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11384 | spin_lock(&dev->event_lock); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11385 | work = intel_crtc->unpin_work; |
| 11386 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11387 | 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] | 11388 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11389 | page_flip_completed(intel_crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11390 | work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11391 | } |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11392 | if (work != NULL && |
| 11393 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) |
| 11394 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11395 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11396 | } |
| 11397 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11398 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 11399 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11400 | struct drm_pending_vblank_event *event, |
| 11401 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11402 | { |
| 11403 | struct drm_device *dev = crtc->dev; |
| 11404 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11405 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11406 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11407 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11408 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11409 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11410 | struct intel_unpin_work *work; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11411 | struct intel_engine_cs *engine; |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11412 | bool mmio_flip; |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11413 | struct drm_i915_gem_request *request = NULL; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 11414 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11415 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11416 | /* |
| 11417 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 11418 | * check to be safe. In the future we may enable pageflipping from |
| 11419 | * a disabled primary plane. |
| 11420 | */ |
| 11421 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 11422 | return -EBUSY; |
| 11423 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11424 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11425 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11426 | return -EINVAL; |
| 11427 | |
| 11428 | /* |
| 11429 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 11430 | * Note that pitch changes could also affect these register. |
| 11431 | */ |
| 11432 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11433 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 11434 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11435 | return -EINVAL; |
| 11436 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11437 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 11438 | goto out_hang; |
| 11439 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 11440 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11441 | if (work == NULL) |
| 11442 | return -ENOMEM; |
| 11443 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11444 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11445 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11446 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11447 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 11448 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11449 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11450 | if (ret) |
| 11451 | goto free_work; |
| 11452 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11453 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11454 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11455 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11456 | /* Before declaring the flip queue wedged, check if |
| 11457 | * the hardware completed the operation behind our backs. |
| 11458 | */ |
| 11459 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 11460 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 11461 | page_flip_completed(intel_crtc); |
| 11462 | } else { |
| 11463 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11464 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 11465 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11466 | drm_crtc_vblank_put(crtc); |
| 11467 | kfree(work); |
| 11468 | return -EBUSY; |
| 11469 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11470 | } |
| 11471 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11472 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11473 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11474 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 11475 | flush_workqueue(dev_priv->wq); |
| 11476 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 11477 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11478 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 11479 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11480 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11481 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11482 | update_state_fb(crtc->primary); |
Paulo Zanoni | e8216e5 | 2016-01-19 11:35:56 -0200 | [diff] [blame] | 11483 | intel_fbc_pre_update(intel_crtc); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 11484 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11485 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11486 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11487 | ret = i915_mutex_lock_interruptible(dev); |
| 11488 | if (ret) |
| 11489 | goto cleanup; |
| 11490 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11491 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 11492 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11493 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11494 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Ville Syrjälä | fd8f507c | 2015-09-18 20:03:42 +0300 | [diff] [blame] | 11495 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11496 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 11497 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11498 | engine = &dev_priv->engine[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11499 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11500 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11501 | engine = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 11502 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11503 | engine = &dev_priv->engine[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11504 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 11505 | engine = i915_gem_request_get_engine(obj->last_write_req); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11506 | if (engine == NULL || engine->id != RCS) |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11507 | engine = &dev_priv->engine[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11508 | } else { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11509 | engine = &dev_priv->engine[RCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11510 | } |
| 11511 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11512 | mmio_flip = use_mmio_flip(engine, obj); |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11513 | |
| 11514 | /* When using CS flips, we want to emit semaphores between rings. |
| 11515 | * However, when using mmio flips we will create a task to do the |
| 11516 | * synchronisation, so all we want here is to pin the framebuffer |
| 11517 | * into the display plane and skip any waits. |
| 11518 | */ |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 11519 | if (!mmio_flip) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11520 | ret = i915_gem_object_sync(obj, engine, &request); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 11521 | if (ret) |
| 11522 | goto cleanup_pending; |
| 11523 | } |
| 11524 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 11525 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11526 | if (ret) |
| 11527 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11528 | |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 11529 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
| 11530 | obj, 0); |
| 11531 | work->gtt_offset += intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11532 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11533 | if (mmio_flip) { |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11534 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11535 | if (ret) |
| 11536 | goto cleanup_unpin; |
| 11537 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 11538 | i915_gem_request_assign(&work->flip_queued_req, |
| 11539 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11540 | } else { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11541 | if (!request) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11542 | request = i915_gem_request_alloc(engine, NULL); |
Dave Gordon | 2682708 | 2016-01-19 19:02:53 +0000 | [diff] [blame] | 11543 | if (IS_ERR(request)) { |
| 11544 | ret = PTR_ERR(request); |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11545 | goto cleanup_unpin; |
Dave Gordon | 2682708 | 2016-01-19 19:02:53 +0000 | [diff] [blame] | 11546 | } |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11547 | } |
| 11548 | |
| 11549 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11550 | page_flip_flags); |
| 11551 | if (ret) |
| 11552 | goto cleanup_unpin; |
| 11553 | |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11554 | i915_gem_request_assign(&work->flip_queued_req, request); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11555 | } |
| 11556 | |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11557 | if (request) |
John Harrison | 7528987 | 2015-05-29 17:43:49 +0100 | [diff] [blame] | 11558 | i915_add_request_no_flush(request); |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11559 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11560 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11561 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11562 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11563 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11564 | to_intel_plane(primary)->frontbuffer_bit); |
Paulo Zanoni | c80ac85 | 2015-07-02 19:25:13 -0300 | [diff] [blame] | 11565 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11566 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11567 | intel_frontbuffer_flip_prepare(dev, |
| 11568 | to_intel_plane(primary)->frontbuffer_bit); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11569 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 11570 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 11571 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11572 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11573 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11574 | cleanup_unpin: |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 11575 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11576 | cleanup_pending: |
Dave Gordon | 0aa498d | 2016-01-28 10:48:09 +0000 | [diff] [blame] | 11577 | if (!IS_ERR_OR_NULL(request)) |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11578 | i915_gem_request_cancel(request); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11579 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11580 | mutex_unlock(&dev->struct_mutex); |
| 11581 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11582 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11583 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11584 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11585 | drm_gem_object_unreference_unlocked(&obj->base); |
| 11586 | drm_framebuffer_unreference(work->old_fb); |
| 11587 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11588 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11589 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11590 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11591 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11592 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11593 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11594 | kfree(work); |
| 11595 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11596 | if (ret == -EIO) { |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11597 | struct drm_atomic_state *state; |
| 11598 | struct drm_plane_state *plane_state; |
| 11599 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11600 | out_hang: |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11601 | state = drm_atomic_state_alloc(dev); |
| 11602 | if (!state) |
| 11603 | return -ENOMEM; |
| 11604 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 11605 | |
| 11606 | retry: |
| 11607 | plane_state = drm_atomic_get_plane_state(state, primary); |
| 11608 | ret = PTR_ERR_OR_ZERO(plane_state); |
| 11609 | if (!ret) { |
| 11610 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 11611 | |
| 11612 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 11613 | if (!ret) |
| 11614 | ret = drm_atomic_commit(state); |
| 11615 | } |
| 11616 | |
| 11617 | if (ret == -EDEADLK) { |
| 11618 | drm_modeset_backoff(state->acquire_ctx); |
| 11619 | drm_atomic_state_clear(state); |
| 11620 | goto retry; |
| 11621 | } |
| 11622 | |
| 11623 | if (ret) |
| 11624 | drm_atomic_state_free(state); |
| 11625 | |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11626 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11627 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11628 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11629 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11630 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11631 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11632 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11633 | } |
| 11634 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11635 | |
| 11636 | /** |
| 11637 | * intel_wm_need_update - Check whether watermarks need updating |
| 11638 | * @plane: drm plane |
| 11639 | * @state: new plane state |
| 11640 | * |
| 11641 | * Check current plane state versus the new one to determine whether |
| 11642 | * watermarks need to be recalculated. |
| 11643 | * |
| 11644 | * Returns true or false. |
| 11645 | */ |
| 11646 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 11647 | struct drm_plane_state *state) |
| 11648 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11649 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 11650 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 11651 | |
| 11652 | /* Update watermarks on tiling or size changes. */ |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11653 | if (new->visible != cur->visible) |
| 11654 | return true; |
| 11655 | |
| 11656 | if (!cur->base.fb || !new->base.fb) |
| 11657 | return false; |
| 11658 | |
| 11659 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || |
| 11660 | cur->base.rotation != new->base.rotation || |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11661 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || |
| 11662 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || |
| 11663 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || |
| 11664 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11665 | return true; |
| 11666 | |
| 11667 | return false; |
| 11668 | } |
| 11669 | |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11670 | static bool needs_scaling(struct intel_plane_state *state) |
| 11671 | { |
| 11672 | int src_w = drm_rect_width(&state->src) >> 16; |
| 11673 | int src_h = drm_rect_height(&state->src) >> 16; |
| 11674 | int dst_w = drm_rect_width(&state->dst); |
| 11675 | int dst_h = drm_rect_height(&state->dst); |
| 11676 | |
| 11677 | return (src_w != dst_w || src_h != dst_h); |
| 11678 | } |
| 11679 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11680 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
| 11681 | struct drm_plane_state *plane_state) |
| 11682 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11683 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11684 | struct drm_crtc *crtc = crtc_state->crtc; |
| 11685 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11686 | struct drm_plane *plane = plane_state->plane; |
| 11687 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11688 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11689 | struct intel_plane_state *old_plane_state = |
| 11690 | to_intel_plane_state(plane->state); |
| 11691 | int idx = intel_crtc->base.base.id, ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11692 | bool mode_changed = needs_modeset(crtc_state); |
| 11693 | bool was_crtc_enabled = crtc->state->active; |
| 11694 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11695 | bool turn_off, turn_on, visible, was_visible; |
| 11696 | struct drm_framebuffer *fb = plane_state->fb; |
| 11697 | |
| 11698 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && |
| 11699 | plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11700 | ret = skl_update_scaler_plane( |
| 11701 | to_intel_crtc_state(crtc_state), |
| 11702 | to_intel_plane_state(plane_state)); |
| 11703 | if (ret) |
| 11704 | return ret; |
| 11705 | } |
| 11706 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11707 | was_visible = old_plane_state->visible; |
| 11708 | visible = to_intel_plane_state(plane_state)->visible; |
| 11709 | |
| 11710 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 11711 | was_visible = false; |
| 11712 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 11713 | /* |
| 11714 | * Visibility is calculated as if the crtc was on, but |
| 11715 | * after scaler setup everything depends on it being off |
| 11716 | * when the crtc isn't active. |
| 11717 | */ |
| 11718 | if (!is_crtc_enabled) |
| 11719 | to_intel_plane_state(plane_state)->visible = visible = false; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11720 | |
| 11721 | if (!was_visible && !visible) |
| 11722 | return 0; |
| 11723 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11724 | if (fb != old_plane_state->base.fb) |
| 11725 | pipe_config->fb_changed = true; |
| 11726 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11727 | turn_off = was_visible && (!visible || mode_changed); |
| 11728 | turn_on = visible && (!was_visible || mode_changed); |
| 11729 | |
| 11730 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, |
| 11731 | plane->base.id, fb ? fb->base.id : -1); |
| 11732 | |
| 11733 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", |
| 11734 | plane->base.id, was_visible, visible, |
| 11735 | turn_off, turn_on, mode_changed); |
| 11736 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11737 | if (turn_on) { |
| 11738 | pipe_config->update_wm_pre = true; |
| 11739 | |
| 11740 | /* must disable cxsr around plane enable/disable */ |
| 11741 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 11742 | pipe_config->disable_cxsr = true; |
| 11743 | } else if (turn_off) { |
| 11744 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11745 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11746 | /* must disable cxsr around plane enable/disable */ |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11747 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11748 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11749 | } else if (intel_wm_need_update(plane, plane_state)) { |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11750 | /* FIXME bollocks */ |
| 11751 | pipe_config->update_wm_pre = true; |
| 11752 | pipe_config->update_wm_post = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11753 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11754 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11755 | /* Pre-gen9 platforms need two-step watermark updates */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11756 | if ((pipe_config->update_wm_pre || pipe_config->update_wm_post) && |
| 11757 | INTEL_INFO(dev)->gen < 9 && dev_priv->display.optimize_watermarks) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11758 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; |
| 11759 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 11760 | if (visible || was_visible) |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 11761 | pipe_config->fb_bits |= to_intel_plane(plane)->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11762 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11763 | /* |
| 11764 | * WaCxSRDisabledForSpriteScaling:ivb |
| 11765 | * |
| 11766 | * cstate->update_wm was already set above, so this flag will |
| 11767 | * take effect when we commit and program watermarks. |
| 11768 | */ |
| 11769 | if (plane->type == DRM_PLANE_TYPE_OVERLAY && IS_IVYBRIDGE(dev) && |
| 11770 | needs_scaling(to_intel_plane_state(plane_state)) && |
| 11771 | !needs_scaling(old_plane_state)) |
| 11772 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11773 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11774 | return 0; |
| 11775 | } |
| 11776 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11777 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11778 | const struct intel_encoder *b) |
| 11779 | { |
| 11780 | /* masks could be asymmetric, so check both ways */ |
| 11781 | return a == b || (a->cloneable & (1 << b->type) && |
| 11782 | b->cloneable & (1 << a->type)); |
| 11783 | } |
| 11784 | |
| 11785 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11786 | struct intel_crtc *crtc, |
| 11787 | struct intel_encoder *encoder) |
| 11788 | { |
| 11789 | struct intel_encoder *source_encoder; |
| 11790 | struct drm_connector *connector; |
| 11791 | struct drm_connector_state *connector_state; |
| 11792 | int i; |
| 11793 | |
| 11794 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11795 | if (connector_state->crtc != &crtc->base) |
| 11796 | continue; |
| 11797 | |
| 11798 | source_encoder = |
| 11799 | to_intel_encoder(connector_state->best_encoder); |
| 11800 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11801 | return false; |
| 11802 | } |
| 11803 | |
| 11804 | return true; |
| 11805 | } |
| 11806 | |
| 11807 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 11808 | struct intel_crtc *crtc) |
| 11809 | { |
| 11810 | struct intel_encoder *encoder; |
| 11811 | struct drm_connector *connector; |
| 11812 | struct drm_connector_state *connector_state; |
| 11813 | int i; |
| 11814 | |
| 11815 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11816 | if (connector_state->crtc != &crtc->base) |
| 11817 | continue; |
| 11818 | |
| 11819 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11820 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
| 11821 | return false; |
| 11822 | } |
| 11823 | |
| 11824 | return true; |
| 11825 | } |
| 11826 | |
| 11827 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 11828 | struct drm_crtc_state *crtc_state) |
| 11829 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11830 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11831 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11833 | struct intel_crtc_state *pipe_config = |
| 11834 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11835 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11836 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11837 | bool mode_changed = needs_modeset(crtc_state); |
| 11838 | |
| 11839 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { |
| 11840 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11841 | return -EINVAL; |
| 11842 | } |
| 11843 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11844 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11845 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11846 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11847 | if (mode_changed && crtc_state->enable && |
| 11848 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11849 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11850 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11851 | pipe_config); |
| 11852 | if (ret) |
| 11853 | return ret; |
| 11854 | } |
| 11855 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11856 | if (crtc_state->color_mgmt_changed) { |
| 11857 | ret = intel_color_check(crtc, crtc_state); |
| 11858 | if (ret) |
| 11859 | return ret; |
| 11860 | } |
| 11861 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11862 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11863 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11864 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11865 | if (ret) { |
| 11866 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11867 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11868 | } |
| 11869 | } |
| 11870 | |
| 11871 | if (dev_priv->display.compute_intermediate_wm && |
| 11872 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 11873 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11874 | return 0; |
| 11875 | |
| 11876 | /* |
| 11877 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11878 | * old state and the new state. We can program these |
| 11879 | * immediately. |
| 11880 | */ |
| 11881 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, |
| 11882 | intel_crtc, |
| 11883 | pipe_config); |
| 11884 | if (ret) { |
| 11885 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11886 | return ret; |
| 11887 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11888 | } |
| 11889 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11890 | if (INTEL_INFO(dev)->gen >= 9) { |
| 11891 | if (mode_changed) |
| 11892 | ret = skl_update_scaler_crtc(pipe_config); |
| 11893 | |
| 11894 | if (!ret) |
| 11895 | ret = intel_atomic_setup_scalers(dev, intel_crtc, |
| 11896 | pipe_config); |
| 11897 | } |
| 11898 | |
| 11899 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11900 | } |
| 11901 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11902 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11903 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 11904 | .atomic_begin = intel_begin_crtc_commit, |
| 11905 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11906 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11907 | }; |
| 11908 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11909 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11910 | { |
| 11911 | struct intel_connector *connector; |
| 11912 | |
| 11913 | for_each_intel_connector(dev, connector) { |
| 11914 | if (connector->base.encoder) { |
| 11915 | connector->base.state->best_encoder = |
| 11916 | connector->base.encoder; |
| 11917 | connector->base.state->crtc = |
| 11918 | connector->base.encoder->crtc; |
| 11919 | } else { |
| 11920 | connector->base.state->best_encoder = NULL; |
| 11921 | connector->base.state->crtc = NULL; |
| 11922 | } |
| 11923 | } |
| 11924 | } |
| 11925 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11926 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 11927 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11928 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11929 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11930 | int bpp = pipe_config->pipe_bpp; |
| 11931 | |
| 11932 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 11933 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11934 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11935 | |
| 11936 | /* Don't use an invalid EDID bpc value */ |
| 11937 | if (connector->base.display_info.bpc && |
| 11938 | connector->base.display_info.bpc * 3 < bpp) { |
| 11939 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 11940 | bpp, connector->base.display_info.bpc*3); |
| 11941 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 11942 | } |
| 11943 | |
Jani Nikula | 013dd9e | 2016-01-13 16:35:20 +0200 | [diff] [blame] | 11944 | /* Clamp bpp to default limit on screens without EDID 1.4 */ |
| 11945 | if (connector->base.display_info.bpc == 0) { |
| 11946 | int type = connector->base.connector_type; |
| 11947 | int clamp_bpp = 24; |
| 11948 | |
| 11949 | /* Fall back to 18 bpp when DP sink capability is unknown. */ |
| 11950 | if (type == DRM_MODE_CONNECTOR_DisplayPort || |
| 11951 | type == DRM_MODE_CONNECTOR_eDP) |
| 11952 | clamp_bpp = 18; |
| 11953 | |
| 11954 | if (bpp > clamp_bpp) { |
| 11955 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", |
| 11956 | bpp, clamp_bpp); |
| 11957 | pipe_config->pipe_bpp = clamp_bpp; |
| 11958 | } |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11959 | } |
| 11960 | } |
| 11961 | |
| 11962 | static int |
| 11963 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11964 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11965 | { |
| 11966 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11967 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11968 | struct drm_connector *connector; |
| 11969 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11970 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11971 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 11972 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11973 | bpp = 10*3; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11974 | else if (INTEL_INFO(dev)->gen >= 5) |
| 11975 | bpp = 12*3; |
| 11976 | else |
| 11977 | bpp = 8*3; |
| 11978 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11979 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11980 | pipe_config->pipe_bpp = bpp; |
| 11981 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11982 | state = pipe_config->base.state; |
| 11983 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11984 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11985 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11986 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11987 | continue; |
| 11988 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11989 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 11990 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11991 | } |
| 11992 | |
| 11993 | return bpp; |
| 11994 | } |
| 11995 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11996 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11997 | { |
| 11998 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11999 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 12000 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12001 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 12002 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 12003 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 12004 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 12005 | } |
| 12006 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12007 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12008 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12009 | const char *context) |
| 12010 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12011 | struct drm_device *dev = crtc->base.dev; |
| 12012 | struct drm_plane *plane; |
| 12013 | struct intel_plane *intel_plane; |
| 12014 | struct intel_plane_state *state; |
| 12015 | struct drm_framebuffer *fb; |
| 12016 | |
| 12017 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 12018 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12019 | |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 12020 | DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config->cpu_transcoder)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12021 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 12022 | pipe_config->pipe_bpp, pipe_config->dither); |
| 12023 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 12024 | pipe_config->has_pch_encoder, |
| 12025 | pipe_config->fdi_lanes, |
| 12026 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 12027 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 12028 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12029 | 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] | 12030 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12031 | pipe_config->lane_count, |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12032 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 12033 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 12034 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12035 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12036 | 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] | 12037 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12038 | pipe_config->lane_count, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12039 | pipe_config->dp_m2_n2.gmch_m, |
| 12040 | pipe_config->dp_m2_n2.gmch_n, |
| 12041 | pipe_config->dp_m2_n2.link_m, |
| 12042 | pipe_config->dp_m2_n2.link_n, |
| 12043 | pipe_config->dp_m2_n2.tu); |
| 12044 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 12045 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 12046 | pipe_config->has_audio, |
| 12047 | pipe_config->has_infoframe); |
| 12048 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12049 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12050 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12051 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12052 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 12053 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 12054 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 12055 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 12056 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Tvrtko Ursulin | 0ec463d | 2015-05-13 16:51:08 +0100 | [diff] [blame] | 12057 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 12058 | crtc->num_scalers, |
| 12059 | pipe_config->scaler_state.scaler_users, |
| 12060 | pipe_config->scaler_state.scaler_id); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12061 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 12062 | pipe_config->gmch_pfit.control, |
| 12063 | pipe_config->gmch_pfit.pgm_ratios, |
| 12064 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12065 | 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] | 12066 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12067 | pipe_config->pch_pfit.size, |
| 12068 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12069 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 12070 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12071 | |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12072 | if (IS_BROXTON(dev)) { |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12073 | 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] | 12074 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12075 | "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] | 12076 | pipe_config->ddi_pll_sel, |
| 12077 | pipe_config->dpll_hw_state.ebb0, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12078 | pipe_config->dpll_hw_state.ebb4, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12079 | pipe_config->dpll_hw_state.pll0, |
| 12080 | pipe_config->dpll_hw_state.pll1, |
| 12081 | pipe_config->dpll_hw_state.pll2, |
| 12082 | pipe_config->dpll_hw_state.pll3, |
| 12083 | pipe_config->dpll_hw_state.pll6, |
| 12084 | pipe_config->dpll_hw_state.pll8, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12085 | pipe_config->dpll_hw_state.pll9, |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12086 | pipe_config->dpll_hw_state.pll10, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12087 | pipe_config->dpll_hw_state.pcsdw12); |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 12088 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12089 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
| 12090 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", |
| 12091 | pipe_config->ddi_pll_sel, |
| 12092 | pipe_config->dpll_hw_state.ctrl1, |
| 12093 | pipe_config->dpll_hw_state.cfgcr1, |
| 12094 | pipe_config->dpll_hw_state.cfgcr2); |
| 12095 | } else if (HAS_DDI(dev)) { |
Ville Syrjälä | 1260f07 | 2016-02-17 21:41:08 +0200 | [diff] [blame] | 12096 | DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12097 | pipe_config->ddi_pll_sel, |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12098 | pipe_config->dpll_hw_state.wrpll, |
| 12099 | pipe_config->dpll_hw_state.spll); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12100 | } else { |
| 12101 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " |
| 12102 | "fp0: 0x%x, fp1: 0x%x\n", |
| 12103 | pipe_config->dpll_hw_state.dpll, |
| 12104 | pipe_config->dpll_hw_state.dpll_md, |
| 12105 | pipe_config->dpll_hw_state.fp0, |
| 12106 | pipe_config->dpll_hw_state.fp1); |
| 12107 | } |
| 12108 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12109 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 12110 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 12111 | intel_plane = to_intel_plane(plane); |
| 12112 | if (intel_plane->pipe != crtc->pipe) |
| 12113 | continue; |
| 12114 | |
| 12115 | state = to_intel_plane_state(plane->state); |
| 12116 | fb = state->base.fb; |
| 12117 | if (!fb) { |
| 12118 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 12119 | "disabled, scaler_id = %d\n", |
| 12120 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12121 | plane->base.id, intel_plane->pipe, |
| 12122 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 12123 | drm_plane_index(plane), state->scaler_id); |
| 12124 | continue; |
| 12125 | } |
| 12126 | |
| 12127 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 12128 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12129 | plane->base.id, intel_plane->pipe, |
| 12130 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 12131 | drm_plane_index(plane)); |
| 12132 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 12133 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 12134 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 12135 | state->scaler_id, |
| 12136 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 12137 | drm_rect_width(&state->src) >> 16, |
| 12138 | drm_rect_height(&state->src) >> 16, |
| 12139 | state->dst.x1, state->dst.y1, |
| 12140 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 12141 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12142 | } |
| 12143 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12144 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12145 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12146 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12147 | struct drm_connector *connector; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12148 | unsigned int used_ports = 0; |
| 12149 | |
| 12150 | /* |
| 12151 | * Walk the connector list instead of the encoder |
| 12152 | * list to detect the problem on ddi platforms |
| 12153 | * where there's just one encoder per digital port. |
| 12154 | */ |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 12155 | drm_for_each_connector(connector, dev) { |
| 12156 | struct drm_connector_state *connector_state; |
| 12157 | struct intel_encoder *encoder; |
| 12158 | |
| 12159 | connector_state = drm_atomic_get_existing_connector_state(state, connector); |
| 12160 | if (!connector_state) |
| 12161 | connector_state = connector->state; |
| 12162 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12163 | if (!connector_state->best_encoder) |
| 12164 | continue; |
| 12165 | |
| 12166 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12167 | |
| 12168 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12169 | |
| 12170 | switch (encoder->type) { |
| 12171 | unsigned int port_mask; |
| 12172 | case INTEL_OUTPUT_UNKNOWN: |
| 12173 | if (WARN_ON(!HAS_DDI(dev))) |
| 12174 | break; |
| 12175 | case INTEL_OUTPUT_DISPLAYPORT: |
| 12176 | case INTEL_OUTPUT_HDMI: |
| 12177 | case INTEL_OUTPUT_EDP: |
| 12178 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 12179 | |
| 12180 | /* the same port mustn't appear more than once */ |
| 12181 | if (used_ports & port_mask) |
| 12182 | return false; |
| 12183 | |
| 12184 | used_ports |= port_mask; |
| 12185 | default: |
| 12186 | break; |
| 12187 | } |
| 12188 | } |
| 12189 | |
| 12190 | return true; |
| 12191 | } |
| 12192 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12193 | static void |
| 12194 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 12195 | { |
| 12196 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12197 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12198 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12199 | struct intel_shared_dpll *shared_dpll; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12200 | uint32_t ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12201 | bool force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12202 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 12203 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 12204 | * kzalloc'd. Code that depends on any field being zero should be |
| 12205 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 12206 | * only fields that are know to not cause problems are preserved. */ |
| 12207 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12208 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12209 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12210 | shared_dpll = crtc_state->shared_dpll; |
| 12211 | dpll_hw_state = crtc_state->dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12212 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12213 | force_thru = crtc_state->pch_pfit.force_thru; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12214 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12215 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12216 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12217 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12218 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12219 | crtc_state->shared_dpll = shared_dpll; |
| 12220 | crtc_state->dpll_hw_state = dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12221 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12222 | crtc_state->pch_pfit.force_thru = force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12223 | } |
| 12224 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12225 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12226 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12227 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12228 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12229 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12230 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12231 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12232 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12233 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12234 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12235 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12236 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12237 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12238 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 12239 | pipe_config->cpu_transcoder = |
| 12240 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12241 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12242 | /* |
| 12243 | * Sanitize sync polarity flags based on requested ones. If neither |
| 12244 | * positive or negative polarity is requested, treat this as meaning |
| 12245 | * negative polarity. |
| 12246 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12247 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12248 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12249 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12250 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12251 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12252 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12253 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12254 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12255 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 12256 | pipe_config); |
| 12257 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12258 | goto fail; |
| 12259 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12260 | /* |
| 12261 | * Determine the real pipe dimensions. Note that stereo modes can |
| 12262 | * increase the actual pipe size due to the frame doubling and |
| 12263 | * insertion of additional space for blanks between the frame. This |
| 12264 | * is stored in the crtc timings. We use the requested mode to do this |
| 12265 | * computation to clearly distinguish it from the adjusted mode, which |
| 12266 | * can be changed by the connectors in the below retry loop. |
| 12267 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12268 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 12269 | &pipe_config->pipe_src_w, |
| 12270 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12271 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12272 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12273 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12274 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12275 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12276 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12277 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12278 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 12279 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12280 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12281 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 12282 | * adjust it according to limitations or connector properties, and also |
| 12283 | * a chance to reject the mode entirely. |
| 12284 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12285 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12286 | if (connector_state->crtc != crtc) |
| 12287 | continue; |
| 12288 | |
| 12289 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12290 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 12291 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 12292 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12293 | goto fail; |
| 12294 | } |
| 12295 | } |
| 12296 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12297 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 12298 | * done afterwards in case the encoder adjusts the mode. */ |
| 12299 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12300 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 12301 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12302 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 12303 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12304 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12305 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 12306 | goto fail; |
| 12307 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12308 | |
| 12309 | if (ret == RETRY) { |
| 12310 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 12311 | ret = -EINVAL; |
| 12312 | goto fail; |
| 12313 | } |
| 12314 | |
| 12315 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 12316 | retry = false; |
| 12317 | goto encoder_retry; |
| 12318 | } |
| 12319 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 12320 | /* Dithering seems to not pass-through bits correctly when it should, so |
| 12321 | * only enable it on 6bpc panels. */ |
| 12322 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 12323 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12324 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12325 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12326 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12327 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12328 | } |
| 12329 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12330 | static void |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12331 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12332 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12333 | struct drm_crtc *crtc; |
| 12334 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12335 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12336 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12337 | /* Double check state. */ |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12338 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 3cb480b | 2015-06-01 12:49:49 +0200 | [diff] [blame] | 12339 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 12340 | |
| 12341 | /* Update hwmode for vblank functions */ |
| 12342 | if (crtc->state->active) |
| 12343 | crtc->hwmode = crtc->state->adjusted_mode; |
| 12344 | else |
| 12345 | crtc->hwmode.crtc_clock = 0; |
Maarten Lankhorst | 61067a5 | 2015-09-23 16:29:36 +0200 | [diff] [blame] | 12346 | |
| 12347 | /* |
| 12348 | * Update legacy state to satisfy fbc code. This can |
| 12349 | * be removed when fbc uses the atomic state. |
| 12350 | */ |
| 12351 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { |
| 12352 | struct drm_plane_state *plane_state = crtc->primary->state; |
| 12353 | |
| 12354 | crtc->primary->fb = plane_state->fb; |
| 12355 | crtc->x = plane_state->src_x >> 16; |
| 12356 | crtc->y = plane_state->src_y >> 16; |
| 12357 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12358 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12359 | } |
| 12360 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12361 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12362 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12363 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12364 | |
| 12365 | if (clock1 == clock2) |
| 12366 | return true; |
| 12367 | |
| 12368 | if (!clock1 || !clock2) |
| 12369 | return false; |
| 12370 | |
| 12371 | diff = abs(clock1 - clock2); |
| 12372 | |
| 12373 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 12374 | return true; |
| 12375 | |
| 12376 | return false; |
| 12377 | } |
| 12378 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12379 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 12380 | list_for_each_entry((intel_crtc), \ |
| 12381 | &(dev)->mode_config.crtc_list, \ |
| 12382 | base.head) \ |
Jani Nikula | 95150bd | 2015-11-24 21:21:56 +0200 | [diff] [blame] | 12383 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12384 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12385 | static bool |
| 12386 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 12387 | unsigned int m2, unsigned int n2, |
| 12388 | bool exact) |
| 12389 | { |
| 12390 | if (m == m2 && n == n2) |
| 12391 | return true; |
| 12392 | |
| 12393 | if (exact || !m || !n || !m2 || !n2) |
| 12394 | return false; |
| 12395 | |
| 12396 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 12397 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12398 | if (n > n2) { |
| 12399 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12400 | m2 <<= 1; |
| 12401 | n2 <<= 1; |
| 12402 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12403 | } else if (n < n2) { |
| 12404 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12405 | m <<= 1; |
| 12406 | n <<= 1; |
| 12407 | } |
| 12408 | } |
| 12409 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12410 | if (n != n2) |
| 12411 | return false; |
| 12412 | |
| 12413 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12414 | } |
| 12415 | |
| 12416 | static bool |
| 12417 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 12418 | struct intel_link_m_n *m2_n2, |
| 12419 | bool adjust) |
| 12420 | { |
| 12421 | if (m_n->tu == m2_n2->tu && |
| 12422 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 12423 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 12424 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 12425 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 12426 | if (adjust) |
| 12427 | *m2_n2 = *m_n; |
| 12428 | |
| 12429 | return true; |
| 12430 | } |
| 12431 | |
| 12432 | return false; |
| 12433 | } |
| 12434 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12435 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12436 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12437 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12438 | struct intel_crtc_state *pipe_config, |
| 12439 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12440 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12441 | bool ret = true; |
| 12442 | |
| 12443 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ |
| 12444 | do { \ |
| 12445 | if (!adjust) \ |
| 12446 | DRM_ERROR(fmt, ##__VA_ARGS__); \ |
| 12447 | else \ |
| 12448 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ |
| 12449 | } while (0) |
| 12450 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12451 | #define PIPE_CONF_CHECK_X(name) \ |
| 12452 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12453 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12454 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 12455 | current_config->name, \ |
| 12456 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12457 | ret = false; \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12458 | } |
| 12459 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12460 | #define PIPE_CONF_CHECK_I(name) \ |
| 12461 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12462 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12463 | "(expected %i, found %i)\n", \ |
| 12464 | current_config->name, \ |
| 12465 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12466 | ret = false; \ |
| 12467 | } |
| 12468 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12469 | #define PIPE_CONF_CHECK_P(name) \ |
| 12470 | if (current_config->name != pipe_config->name) { \ |
| 12471 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12472 | "(expected %p, found %p)\n", \ |
| 12473 | current_config->name, \ |
| 12474 | pipe_config->name); \ |
| 12475 | ret = false; \ |
| 12476 | } |
| 12477 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12478 | #define PIPE_CONF_CHECK_M_N(name) \ |
| 12479 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12480 | &pipe_config->name,\ |
| 12481 | adjust)) { \ |
| 12482 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12483 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12484 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12485 | current_config->name.tu, \ |
| 12486 | current_config->name.gmch_m, \ |
| 12487 | current_config->name.gmch_n, \ |
| 12488 | current_config->name.link_m, \ |
| 12489 | current_config->name.link_n, \ |
| 12490 | pipe_config->name.tu, \ |
| 12491 | pipe_config->name.gmch_m, \ |
| 12492 | pipe_config->name.gmch_n, \ |
| 12493 | pipe_config->name.link_m, \ |
| 12494 | pipe_config->name.link_n); \ |
| 12495 | ret = false; \ |
| 12496 | } |
| 12497 | |
| 12498 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
| 12499 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12500 | &pipe_config->name, adjust) && \ |
| 12501 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 12502 | &pipe_config->name, adjust)) { \ |
| 12503 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12504 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12505 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 12506 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12507 | current_config->name.tu, \ |
| 12508 | current_config->name.gmch_m, \ |
| 12509 | current_config->name.gmch_n, \ |
| 12510 | current_config->name.link_m, \ |
| 12511 | current_config->name.link_n, \ |
| 12512 | current_config->alt_name.tu, \ |
| 12513 | current_config->alt_name.gmch_m, \ |
| 12514 | current_config->alt_name.gmch_n, \ |
| 12515 | current_config->alt_name.link_m, \ |
| 12516 | current_config->alt_name.link_n, \ |
| 12517 | pipe_config->name.tu, \ |
| 12518 | pipe_config->name.gmch_m, \ |
| 12519 | pipe_config->name.gmch_n, \ |
| 12520 | pipe_config->name.link_m, \ |
| 12521 | pipe_config->name.link_n); \ |
| 12522 | ret = false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 12523 | } |
| 12524 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12525 | /* This is required for BDW+ where there is only one set of registers for |
| 12526 | * switching between high and low RR. |
| 12527 | * This macro can be used whenever a comparison has to be made between one |
| 12528 | * hw state and multiple sw state variables. |
| 12529 | */ |
| 12530 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 12531 | if ((current_config->name != pipe_config->name) && \ |
| 12532 | (current_config->alt_name != pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12533 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12534 | "(expected %i or %i, found %i)\n", \ |
| 12535 | current_config->name, \ |
| 12536 | current_config->alt_name, \ |
| 12537 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12538 | ret = false; \ |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12539 | } |
| 12540 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12541 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 12542 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12543 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12544 | "(expected %i, found %i)\n", \ |
| 12545 | current_config->name & (mask), \ |
| 12546 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12547 | ret = false; \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12548 | } |
| 12549 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12550 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 12551 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12552 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12553 | "(expected %i, found %i)\n", \ |
| 12554 | current_config->name, \ |
| 12555 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12556 | ret = false; \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12557 | } |
| 12558 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12559 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12560 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12561 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12562 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12563 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12564 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 12565 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12566 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12567 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12568 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12569 | PIPE_CONF_CHECK_I(lane_count); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12570 | |
| 12571 | if (INTEL_INFO(dev)->gen < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12572 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12573 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12574 | if (current_config->has_drrs) |
| 12575 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12576 | } else |
| 12577 | 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] | 12578 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 12579 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
| 12580 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12581 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12582 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12583 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12584 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12585 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12586 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12587 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12588 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12589 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12590 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12591 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12592 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12593 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12594 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12595 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 12596 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12597 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 12598 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12599 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 12600 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12601 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12602 | PIPE_CONF_CHECK_I(has_audio); |
| 12603 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12604 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12605 | DRM_MODE_FLAG_INTERLACE); |
| 12606 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12607 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12608 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12609 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12610 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12611 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12612 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12613 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12614 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12615 | DRM_MODE_FLAG_NVSYNC); |
| 12616 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12617 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12618 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12619 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 12620 | if (INTEL_INFO(dev)->gen < 4) |
| 12621 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12622 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12623 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12624 | if (!adjust) { |
| 12625 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12626 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 12627 | |
| 12628 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 12629 | if (current_config->pch_pfit.enabled) { |
| 12630 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 12631 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 12632 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12633 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12634 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 12635 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12636 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 12637 | /* BDW+ don't expose a synchronous way to read the state */ |
| 12638 | if (IS_HASWELL(dev)) |
| 12639 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12640 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12641 | PIPE_CONF_CHECK_I(double_wide); |
| 12642 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 12643 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 12644 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12645 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12646 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12647 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12648 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12649 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12650 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12651 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12652 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12653 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12654 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12655 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12656 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 12657 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12658 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12659 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12660 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12661 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12662 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12663 | #undef PIPE_CONF_CHECK_I |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12664 | #undef PIPE_CONF_CHECK_P |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12665 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12666 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12667 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12668 | #undef PIPE_CONF_QUIRK |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12669 | #undef INTEL_ERR_OR_DBG_KMS |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12670 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12671 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12672 | } |
| 12673 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12674 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 12675 | const struct intel_crtc_state *pipe_config) |
| 12676 | { |
| 12677 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 12678 | int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12679 | &pipe_config->fdi_m_n); |
| 12680 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 12681 | |
| 12682 | /* |
| 12683 | * FDI already provided one idea for the dotclock. |
| 12684 | * Yell if the encoder disagrees. |
| 12685 | */ |
| 12686 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 12687 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 12688 | fdi_dotclock, dotclock); |
| 12689 | } |
| 12690 | } |
| 12691 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12692 | static void check_wm_state(struct drm_device *dev) |
| 12693 | { |
| 12694 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12695 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 12696 | struct intel_crtc *intel_crtc; |
| 12697 | int plane; |
| 12698 | |
| 12699 | if (INTEL_INFO(dev)->gen < 9) |
| 12700 | return; |
| 12701 | |
| 12702 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12703 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12704 | |
| 12705 | for_each_intel_crtc(dev, intel_crtc) { |
| 12706 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 12707 | const enum pipe pipe = intel_crtc->pipe; |
| 12708 | |
| 12709 | if (!intel_crtc->active) |
| 12710 | continue; |
| 12711 | |
| 12712 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 12713 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12714 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 12715 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 12716 | |
| 12717 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12718 | continue; |
| 12719 | |
| 12720 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 12721 | "(expected (%u,%u), found (%u,%u))\n", |
| 12722 | pipe_name(pipe), plane + 1, |
| 12723 | sw_entry->start, sw_entry->end, |
| 12724 | hw_entry->start, hw_entry->end); |
| 12725 | } |
| 12726 | |
| 12727 | /* cursor */ |
Matt Roper | 4969d33 | 2015-09-24 15:53:10 -0700 | [diff] [blame] | 12728 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 12729 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12730 | |
| 12731 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12732 | continue; |
| 12733 | |
| 12734 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 12735 | "(expected (%u,%u), found (%u,%u))\n", |
| 12736 | pipe_name(pipe), |
| 12737 | sw_entry->start, sw_entry->end, |
| 12738 | hw_entry->start, hw_entry->end); |
| 12739 | } |
| 12740 | } |
| 12741 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12742 | static void |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12743 | check_connector_state(struct drm_device *dev, |
| 12744 | struct drm_atomic_state *old_state) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12745 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12746 | struct drm_connector_state *old_conn_state; |
| 12747 | struct drm_connector *connector; |
| 12748 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12749 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12750 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 12751 | struct drm_encoder *encoder = connector->encoder; |
| 12752 | struct drm_connector_state *state = connector->state; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12753 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12754 | /* This also checks the encoder/connector hw state with the |
| 12755 | * ->get_hw_state callbacks. */ |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12756 | intel_connector_check_state(to_intel_connector(connector)); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12757 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12758 | I915_STATE_WARN(state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12759 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12760 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12761 | } |
| 12762 | |
| 12763 | static void |
| 12764 | check_encoder_state(struct drm_device *dev) |
| 12765 | { |
| 12766 | struct intel_encoder *encoder; |
| 12767 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12768 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12769 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12770 | bool enabled = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12771 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12772 | |
| 12773 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12774 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12775 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12776 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12777 | for_each_intel_connector(dev, connector) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12778 | if (connector->base.state->best_encoder != &encoder->base) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12779 | continue; |
| 12780 | enabled = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12781 | |
| 12782 | I915_STATE_WARN(connector->base.state->crtc != |
| 12783 | encoder->base.crtc, |
| 12784 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12785 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12786 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12787 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12788 | "encoder's enabled state mismatch " |
| 12789 | "(expected %i, found %i)\n", |
| 12790 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12791 | |
| 12792 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12793 | bool active; |
| 12794 | |
| 12795 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12796 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12797 | "encoder detached but still enabled on pipe %c.\n", |
| 12798 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12799 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12800 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12801 | } |
| 12802 | |
| 12803 | static void |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12804 | 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] | 12805 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12806 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12807 | struct intel_encoder *encoder; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12808 | struct drm_crtc_state *old_crtc_state; |
| 12809 | struct drm_crtc *crtc; |
| 12810 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12811 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12812 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 12813 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12814 | struct intel_crtc_state *pipe_config, *sw_config; |
Maarten Lankhorst | 7b89b8d | 2015-08-05 12:37:03 +0200 | [diff] [blame] | 12815 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12816 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12817 | if (!needs_modeset(crtc->state) && |
| 12818 | !to_intel_crtc_state(crtc->state)->update_pipe) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12819 | continue; |
| 12820 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12821 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
| 12822 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12823 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12824 | pipe_config->base.crtc = crtc; |
| 12825 | pipe_config->base.state = old_state; |
| 12826 | |
| 12827 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 12828 | crtc->base.id); |
| 12829 | |
| 12830 | active = dev_priv->display.get_pipe_config(intel_crtc, |
| 12831 | pipe_config); |
| 12832 | |
| 12833 | /* hw state is inconsistent with the pipe quirk */ |
| 12834 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 12835 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 12836 | active = crtc->state->active; |
| 12837 | |
| 12838 | I915_STATE_WARN(crtc->state->active != active, |
| 12839 | "crtc active state doesn't match with hw state " |
| 12840 | "(expected %i, found %i)\n", crtc->state->active, active); |
| 12841 | |
| 12842 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
| 12843 | "transitional active state does not match atomic hw state " |
| 12844 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
| 12845 | |
| 12846 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12847 | enum pipe pipe; |
| 12848 | |
| 12849 | active = encoder->get_hw_state(encoder, &pipe); |
| 12850 | I915_STATE_WARN(active != crtc->state->active, |
| 12851 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12852 | encoder->base.base.id, active, crtc->state->active); |
| 12853 | |
| 12854 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12855 | "Encoder connected to wrong pipe %c\n", |
| 12856 | pipe_name(pipe)); |
| 12857 | |
| 12858 | if (active) |
| 12859 | encoder->get_config(encoder, pipe_config); |
| 12860 | } |
| 12861 | |
| 12862 | if (!crtc->state->active) |
| 12863 | continue; |
| 12864 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12865 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
| 12866 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12867 | sw_config = to_intel_crtc_state(crtc->state); |
| 12868 | if (!intel_pipe_config_compare(dev, sw_config, |
| 12869 | pipe_config, false)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12870 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12871 | intel_dump_pipe_config(intel_crtc, pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12872 | "[hw state]"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12873 | intel_dump_pipe_config(intel_crtc, sw_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12874 | "[sw state]"); |
| 12875 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12876 | } |
| 12877 | } |
| 12878 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12879 | static void |
| 12880 | check_shared_dpll_state(struct drm_device *dev) |
| 12881 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12882 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12883 | struct intel_crtc *crtc; |
| 12884 | struct intel_dpll_hw_state dpll_hw_state; |
| 12885 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12886 | |
| 12887 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12888 | struct intel_shared_dpll *pll = |
| 12889 | intel_get_shared_dpll_by_id(dev_priv, i); |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12890 | unsigned enabled_crtcs = 0, active_crtcs = 0; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12891 | bool active; |
| 12892 | |
| 12893 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12894 | |
| 12895 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 12896 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 12897 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12898 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12899 | I915_STATE_WARN(pll->active_mask & ~pll->config.crtc_mask, |
| 12900 | "more active pll users than references: %x vs %x\n", |
| 12901 | pll->active_mask, pll->config.crtc_mask); |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 12902 | |
| 12903 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12904 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12905 | "pll in active use but not on in sw tracking\n"); |
| 12906 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12907 | "pll is on but not used by any active crtc\n"); |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 12908 | I915_STATE_WARN(pll->on != active, |
| 12909 | "pll on state mismatch (expected %i, found %i)\n", |
| 12910 | pll->on, active); |
| 12911 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12912 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12913 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12914 | if (crtc->base.state->enable && crtc->config->shared_dpll == pll) |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12915 | enabled_crtcs |= 1 << drm_crtc_index(&crtc->base); |
| 12916 | if (crtc->base.state->active && crtc->config->shared_dpll == pll) |
| 12917 | active_crtcs |= 1 << drm_crtc_index(&crtc->base); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12918 | } |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12919 | |
| 12920 | I915_STATE_WARN(pll->active_mask != active_crtcs, |
| 12921 | "pll active crtcs mismatch (expected %x, found %x)\n", |
| 12922 | pll->active_mask, active_crtcs); |
| 12923 | I915_STATE_WARN(pll->config.crtc_mask != enabled_crtcs, |
| 12924 | "pll enabled crtcs mismatch (expected %x, found %x)\n", |
| 12925 | pll->config.crtc_mask, enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12926 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12927 | 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] | 12928 | sizeof(dpll_hw_state)), |
| 12929 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12930 | } |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 12931 | } |
| 12932 | |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 12933 | static void |
| 12934 | intel_modeset_check_state(struct drm_device *dev, |
| 12935 | struct drm_atomic_state *old_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12936 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12937 | check_wm_state(dev); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12938 | check_connector_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12939 | check_encoder_state(dev); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12940 | check_crtc_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12941 | check_shared_dpll_state(dev); |
| 12942 | } |
| 12943 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12944 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 12945 | { |
| 12946 | struct drm_device *dev = crtc->base.dev; |
| 12947 | |
| 12948 | /* |
| 12949 | * The scanline counter increments at the leading edge of hsync. |
| 12950 | * |
| 12951 | * On most platforms it starts counting from vtotal-1 on the |
| 12952 | * first active line. That means the scanline counter value is |
| 12953 | * always one less than what we would expect. Ie. just after |
| 12954 | * start of vblank, which also occurs at start of hsync (on the |
| 12955 | * last active line), the scanline counter will read vblank_start-1. |
| 12956 | * |
| 12957 | * On gen2 the scanline counter starts counting from 1 instead |
| 12958 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12959 | * to keep the value positive), instead of adding one. |
| 12960 | * |
| 12961 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12962 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12963 | * there's an extra 1 line difference. So we need to add two instead of |
| 12964 | * one to the value. |
| 12965 | */ |
| 12966 | if (IS_GEN2(dev)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12967 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12968 | int vtotal; |
| 12969 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12970 | vtotal = adjusted_mode->crtc_vtotal; |
| 12971 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12972 | vtotal /= 2; |
| 12973 | |
| 12974 | crtc->scanline_offset = vtotal - 1; |
| 12975 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 12976 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12977 | crtc->scanline_offset = 2; |
| 12978 | } else |
| 12979 | crtc->scanline_offset = 1; |
| 12980 | } |
| 12981 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12982 | 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] | 12983 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12984 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12985 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12986 | struct intel_shared_dpll_config *shared_dpll = NULL; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12987 | struct drm_crtc *crtc; |
| 12988 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12989 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12990 | |
| 12991 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12992 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12993 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12994 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12995 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12996 | struct intel_shared_dpll *old_dpll = |
| 12997 | to_intel_crtc_state(crtc->state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12998 | |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12999 | if (!needs_modeset(crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13000 | continue; |
| 13001 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13002 | to_intel_crtc_state(crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13003 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13004 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13005 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13006 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13007 | if (!shared_dpll) |
| 13008 | shared_dpll = intel_atomic_get_shared_dpll_state(state); |
| 13009 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13010 | intel_shared_dpll_config_put(shared_dpll, old_dpll, intel_crtc); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13011 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13012 | } |
| 13013 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13014 | /* |
| 13015 | * This implements the workaround described in the "notes" section of the mode |
| 13016 | * set sequence documentation. When going from no pipes or single pipe to |
| 13017 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 13018 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 13019 | */ |
| 13020 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 13021 | { |
| 13022 | struct drm_crtc_state *crtc_state; |
| 13023 | struct intel_crtc *intel_crtc; |
| 13024 | struct drm_crtc *crtc; |
| 13025 | struct intel_crtc_state *first_crtc_state = NULL; |
| 13026 | struct intel_crtc_state *other_crtc_state = NULL; |
| 13027 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 13028 | int i; |
| 13029 | |
| 13030 | /* look at all crtc's that are going to be enabled in during modeset */ |
| 13031 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13032 | intel_crtc = to_intel_crtc(crtc); |
| 13033 | |
| 13034 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 13035 | continue; |
| 13036 | |
| 13037 | if (first_crtc_state) { |
| 13038 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 13039 | break; |
| 13040 | } else { |
| 13041 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 13042 | first_pipe = intel_crtc->pipe; |
| 13043 | } |
| 13044 | } |
| 13045 | |
| 13046 | /* No workaround needed? */ |
| 13047 | if (!first_crtc_state) |
| 13048 | return 0; |
| 13049 | |
| 13050 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 13051 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 13052 | struct intel_crtc_state *pipe_config; |
| 13053 | |
| 13054 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 13055 | if (IS_ERR(pipe_config)) |
| 13056 | return PTR_ERR(pipe_config); |
| 13057 | |
| 13058 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 13059 | |
| 13060 | if (!pipe_config->base.active || |
| 13061 | needs_modeset(&pipe_config->base)) |
| 13062 | continue; |
| 13063 | |
| 13064 | /* 2 or more enabled crtcs means no need for w/a */ |
| 13065 | if (enabled_pipe != INVALID_PIPE) |
| 13066 | return 0; |
| 13067 | |
| 13068 | enabled_pipe = intel_crtc->pipe; |
| 13069 | } |
| 13070 | |
| 13071 | if (enabled_pipe != INVALID_PIPE) |
| 13072 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 13073 | else if (other_crtc_state) |
| 13074 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 13075 | |
| 13076 | return 0; |
| 13077 | } |
| 13078 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13079 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 13080 | { |
| 13081 | struct drm_crtc *crtc; |
| 13082 | struct drm_crtc_state *crtc_state; |
| 13083 | int ret = 0; |
| 13084 | |
| 13085 | /* add all active pipes to the state */ |
| 13086 | for_each_crtc(state->dev, crtc) { |
| 13087 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13088 | if (IS_ERR(crtc_state)) |
| 13089 | return PTR_ERR(crtc_state); |
| 13090 | |
| 13091 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 13092 | continue; |
| 13093 | |
| 13094 | crtc_state->mode_changed = true; |
| 13095 | |
| 13096 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13097 | if (ret) |
| 13098 | break; |
| 13099 | |
| 13100 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13101 | if (ret) |
| 13102 | break; |
| 13103 | } |
| 13104 | |
| 13105 | return ret; |
| 13106 | } |
| 13107 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13108 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13109 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13110 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13111 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 13112 | struct drm_crtc *crtc; |
| 13113 | struct drm_crtc_state *crtc_state; |
| 13114 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13115 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13116 | if (!check_digital_port_conflicts(state)) { |
| 13117 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 13118 | return -EINVAL; |
| 13119 | } |
| 13120 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13121 | intel_state->modeset = true; |
| 13122 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 13123 | |
| 13124 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13125 | if (crtc_state->active) |
| 13126 | intel_state->active_crtcs |= 1 << i; |
| 13127 | else |
| 13128 | intel_state->active_crtcs &= ~(1 << i); |
| 13129 | } |
| 13130 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13131 | /* |
| 13132 | * See if the config requires any additional preparation, e.g. |
| 13133 | * to adjust global state with pipes off. We need to do this |
| 13134 | * here so we can get the modeset_pipe updated config for the new |
| 13135 | * mode set on this crtc. For other crtcs we need to use the |
| 13136 | * adjusted_mode bits in the crtc directly. |
| 13137 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13138 | if (dev_priv->display.modeset_calc_cdclk) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13139 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 13140 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13141 | if (!ret && intel_state->dev_cdclk != dev_priv->cdclk_freq) |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13142 | ret = intel_modeset_all_pipes(state); |
| 13143 | |
| 13144 | if (ret < 0) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13145 | return ret; |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 13146 | |
| 13147 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", |
| 13148 | intel_state->cdclk, intel_state->dev_cdclk); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13149 | } else |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13150 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13151 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13152 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13153 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13154 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13155 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13156 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13157 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13158 | } |
| 13159 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13160 | /* |
| 13161 | * Handle calculation of various watermark data at the end of the atomic check |
| 13162 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 13163 | * handlers to ensure that all derived state has been updated. |
| 13164 | */ |
| 13165 | static void calc_watermark_data(struct drm_atomic_state *state) |
| 13166 | { |
| 13167 | struct drm_device *dev = state->dev; |
| 13168 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13169 | struct drm_crtc *crtc; |
| 13170 | struct drm_crtc_state *cstate; |
| 13171 | struct drm_plane *plane; |
| 13172 | struct drm_plane_state *pstate; |
| 13173 | |
| 13174 | /* |
| 13175 | * Calculate watermark configuration details now that derived |
| 13176 | * plane/crtc state is all properly updated. |
| 13177 | */ |
| 13178 | drm_for_each_crtc(crtc, dev) { |
| 13179 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: |
| 13180 | crtc->state; |
| 13181 | |
| 13182 | if (cstate->active) |
| 13183 | intel_state->wm_config.num_pipes_active++; |
| 13184 | } |
| 13185 | drm_for_each_legacy_plane(plane, dev) { |
| 13186 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: |
| 13187 | plane->state; |
| 13188 | |
| 13189 | if (!to_intel_plane_state(pstate)->visible) |
| 13190 | continue; |
| 13191 | |
| 13192 | intel_state->wm_config.sprites_enabled = true; |
| 13193 | if (pstate->crtc_w != pstate->src_w >> 16 || |
| 13194 | pstate->crtc_h != pstate->src_h >> 16) |
| 13195 | intel_state->wm_config.sprites_scaled = true; |
| 13196 | } |
| 13197 | } |
| 13198 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13199 | /** |
| 13200 | * intel_atomic_check - validate state object |
| 13201 | * @dev: drm device |
| 13202 | * @state: state to validate |
| 13203 | */ |
| 13204 | static int intel_atomic_check(struct drm_device *dev, |
| 13205 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13206 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13207 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13208 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13209 | struct drm_crtc *crtc; |
| 13210 | struct drm_crtc_state *crtc_state; |
| 13211 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13212 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13213 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13214 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13215 | if (ret) |
| 13216 | return ret; |
| 13217 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13218 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13219 | struct intel_crtc_state *pipe_config = |
| 13220 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13221 | |
| 13222 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 13223 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) |
| 13224 | crtc_state->mode_changed = true; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13225 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13226 | if (!crtc_state->enable) { |
| 13227 | if (needs_modeset(crtc_state)) |
| 13228 | any_ms = true; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13229 | continue; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13230 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13231 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13232 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13233 | continue; |
| 13234 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13235 | /* FIXME: For only active_changed we shouldn't need to do any |
| 13236 | * state recomputation at all. */ |
| 13237 | |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13238 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13239 | if (ret) |
| 13240 | return ret; |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13241 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13242 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13243 | if (ret) |
| 13244 | return ret; |
| 13245 | |
Jani Nikula | 7383123 | 2015-11-19 10:26:30 +0200 | [diff] [blame] | 13246 | if (i915.fastboot && |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13247 | intel_pipe_config_compare(dev, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13248 | to_intel_crtc_state(crtc->state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13249 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13250 | crtc_state->mode_changed = false; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13251 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13252 | } |
| 13253 | |
| 13254 | if (needs_modeset(crtc_state)) { |
| 13255 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13256 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13257 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13258 | if (ret) |
| 13259 | return ret; |
| 13260 | } |
| 13261 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13262 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 13263 | needs_modeset(crtc_state) ? |
| 13264 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13265 | } |
| 13266 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13267 | if (any_ms) { |
| 13268 | ret = intel_modeset_checks(state); |
| 13269 | |
| 13270 | if (ret) |
| 13271 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13272 | } else |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13273 | intel_state->cdclk = dev_priv->cdclk_freq; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13274 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13275 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13276 | if (ret) |
| 13277 | return ret; |
| 13278 | |
Paulo Zanoni | f51be2e | 2016-01-19 11:35:50 -0200 | [diff] [blame] | 13279 | intel_fbc_choose_crtc(dev_priv, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13280 | calc_watermark_data(state); |
| 13281 | |
| 13282 | return 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13283 | } |
| 13284 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13285 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
| 13286 | struct drm_atomic_state *state, |
| 13287 | bool async) |
| 13288 | { |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13289 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13290 | struct drm_plane_state *plane_state; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13291 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13292 | struct drm_plane *plane; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13293 | struct drm_crtc *crtc; |
| 13294 | int i, ret; |
| 13295 | |
| 13296 | if (async) { |
| 13297 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); |
| 13298 | return -EINVAL; |
| 13299 | } |
| 13300 | |
| 13301 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13302 | ret = intel_crtc_wait_for_pending_flips(crtc); |
| 13303 | if (ret) |
| 13304 | return ret; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13305 | |
| 13306 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) |
| 13307 | flush_workqueue(dev_priv->wq); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13308 | } |
| 13309 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13310 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 13311 | if (ret) |
| 13312 | return ret; |
| 13313 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13314 | ret = drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13315 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
| 13316 | u32 reset_counter; |
| 13317 | |
| 13318 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
| 13319 | mutex_unlock(&dev->struct_mutex); |
| 13320 | |
| 13321 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 13322 | struct intel_plane_state *intel_plane_state = |
| 13323 | to_intel_plane_state(plane_state); |
| 13324 | |
| 13325 | if (!intel_plane_state->wait_req) |
| 13326 | continue; |
| 13327 | |
| 13328 | ret = __i915_wait_request(intel_plane_state->wait_req, |
| 13329 | reset_counter, true, |
| 13330 | NULL, NULL); |
| 13331 | |
| 13332 | /* Swallow -EIO errors to allow updates during hw lockup. */ |
| 13333 | if (ret == -EIO) |
| 13334 | ret = 0; |
| 13335 | |
| 13336 | if (ret) |
| 13337 | break; |
| 13338 | } |
| 13339 | |
| 13340 | if (!ret) |
| 13341 | return 0; |
| 13342 | |
| 13343 | mutex_lock(&dev->struct_mutex); |
| 13344 | drm_atomic_helper_cleanup_planes(dev, state); |
| 13345 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13346 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13347 | mutex_unlock(&dev->struct_mutex); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13348 | return ret; |
| 13349 | } |
| 13350 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13351 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
| 13352 | struct drm_i915_private *dev_priv, |
| 13353 | unsigned crtc_mask) |
| 13354 | { |
| 13355 | unsigned last_vblank_count[I915_MAX_PIPES]; |
| 13356 | enum pipe pipe; |
| 13357 | int ret; |
| 13358 | |
| 13359 | if (!crtc_mask) |
| 13360 | return; |
| 13361 | |
| 13362 | for_each_pipe(dev_priv, pipe) { |
| 13363 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 13364 | |
| 13365 | if (!((1 << pipe) & crtc_mask)) |
| 13366 | continue; |
| 13367 | |
| 13368 | ret = drm_crtc_vblank_get(crtc); |
| 13369 | if (WARN_ON(ret != 0)) { |
| 13370 | crtc_mask &= ~(1 << pipe); |
| 13371 | continue; |
| 13372 | } |
| 13373 | |
| 13374 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); |
| 13375 | } |
| 13376 | |
| 13377 | for_each_pipe(dev_priv, pipe) { |
| 13378 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 13379 | long lret; |
| 13380 | |
| 13381 | if (!((1 << pipe) & crtc_mask)) |
| 13382 | continue; |
| 13383 | |
| 13384 | lret = wait_event_timeout(dev->vblank[pipe].queue, |
| 13385 | last_vblank_count[pipe] != |
| 13386 | drm_crtc_vblank_count(crtc), |
| 13387 | msecs_to_jiffies(50)); |
| 13388 | |
| 13389 | WARN_ON(!lret); |
| 13390 | |
| 13391 | drm_crtc_vblank_put(crtc); |
| 13392 | } |
| 13393 | } |
| 13394 | |
| 13395 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) |
| 13396 | { |
| 13397 | /* fb updated, need to unpin old fb */ |
| 13398 | if (crtc_state->fb_changed) |
| 13399 | return true; |
| 13400 | |
| 13401 | /* wm changes, need vblank before final wm's */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 13402 | if (crtc_state->update_wm_post) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13403 | return true; |
| 13404 | |
| 13405 | /* |
| 13406 | * cxsr is re-enabled after vblank. |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 13407 | * This is already handled by crtc_state->update_wm_post, |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13408 | * but added for clarity. |
| 13409 | */ |
| 13410 | if (crtc_state->disable_cxsr) |
| 13411 | return true; |
| 13412 | |
| 13413 | return false; |
| 13414 | } |
| 13415 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13416 | /** |
| 13417 | * intel_atomic_commit - commit validated state object |
| 13418 | * @dev: DRM device |
| 13419 | * @state: the top-level driver state object |
| 13420 | * @async: asynchronous commit |
| 13421 | * |
| 13422 | * This function commits a top-level state object that has been validated |
| 13423 | * with drm_atomic_helper_check(). |
| 13424 | * |
| 13425 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment |
| 13426 | * we can only handle plane-related operations and do not yet support |
| 13427 | * asynchronous commit. |
| 13428 | * |
| 13429 | * RETURNS |
| 13430 | * Zero for success or -errno. |
| 13431 | */ |
| 13432 | static int intel_atomic_commit(struct drm_device *dev, |
| 13433 | struct drm_atomic_state *state, |
| 13434 | bool async) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13435 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13436 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13437 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13438 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13439 | struct drm_crtc *crtc; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13440 | struct intel_crtc_state *intel_cstate; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13441 | int ret = 0, i; |
| 13442 | bool hw_check = intel_state->modeset; |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13443 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13444 | unsigned crtc_vblank_mask = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13445 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13446 | ret = intel_atomic_prepare_commit(dev, state, async); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13447 | if (ret) { |
| 13448 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13449 | return ret; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13450 | } |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13451 | |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13452 | drm_atomic_helper_swap_state(dev, state); |
Maarten Lankhorst | a1475e7 | 2016-03-14 09:27:53 +0100 | [diff] [blame] | 13453 | dev_priv->wm.config = intel_state->wm_config; |
| 13454 | intel_shared_dpll_commit(state); |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13455 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13456 | if (intel_state->modeset) { |
| 13457 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, |
| 13458 | sizeof(intel_state->min_pixclk)); |
| 13459 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13460 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13461 | |
| 13462 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13463 | } |
| 13464 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13465 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13466 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13467 | |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13468 | if (needs_modeset(crtc->state) || |
| 13469 | to_intel_crtc_state(crtc->state)->update_pipe) { |
| 13470 | hw_check = true; |
| 13471 | |
| 13472 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 13473 | modeset_get_crtc_power_domains(crtc, |
| 13474 | to_intel_crtc_state(crtc->state)); |
| 13475 | } |
| 13476 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13477 | if (!needs_modeset(crtc->state)) |
| 13478 | continue; |
| 13479 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13480 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13481 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13482 | if (old_crtc_state->active) { |
| 13483 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13484 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13485 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13486 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13487 | intel_disable_shared_dpll(intel_crtc); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13488 | |
| 13489 | /* |
| 13490 | * Underruns don't always raise |
| 13491 | * interrupts, so check manually. |
| 13492 | */ |
| 13493 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13494 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13495 | |
| 13496 | if (!crtc->state->active) |
| 13497 | intel_update_watermarks(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13498 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13499 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13500 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13501 | /* Only after disabling all output pipelines that will be changed can we |
| 13502 | * update the the output configuration. */ |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13503 | intel_modeset_update_crtc_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13504 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13505 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13506 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13507 | |
| 13508 | if (dev_priv->display.modeset_commit_cdclk && |
| 13509 | intel_state->dev_cdclk != dev_priv->cdclk_freq) |
| 13510 | dev_priv->display.modeset_commit_cdclk(state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13511 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13512 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13513 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13514 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13515 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13516 | bool modeset = needs_modeset(crtc->state); |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13517 | struct intel_crtc_state *pipe_config = |
| 13518 | to_intel_crtc_state(crtc->state); |
| 13519 | bool update_pipe = !modeset && pipe_config->update_pipe; |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 13520 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13521 | if (modeset && crtc->state->active) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13522 | update_scanline_offset(to_intel_crtc(crtc)); |
| 13523 | dev_priv->display.crtc_enable(crtc); |
| 13524 | } |
| 13525 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13526 | if (!modeset && |
| 13527 | crtc->state->active && |
| 13528 | crtc->state->color_mgmt_changed) { |
| 13529 | /* |
| 13530 | * Only update color management when not doing |
| 13531 | * a modeset as this will be done by |
| 13532 | * crtc_enable already. |
| 13533 | */ |
| 13534 | intel_color_set_csc(crtc); |
| 13535 | intel_color_load_luts(crtc); |
| 13536 | } |
| 13537 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13538 | if (!modeset) |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13539 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13540 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 13541 | if (crtc->state->active && |
| 13542 | drm_atomic_get_existing_plane_state(state, crtc->primary)) |
Paulo Zanoni | 49227c4 | 2016-01-19 11:35:52 -0200 | [diff] [blame] | 13543 | intel_fbc_enable(intel_crtc); |
| 13544 | |
Maarten Lankhorst | 6173ee2 | 2015-09-23 16:29:39 +0200 | [diff] [blame] | 13545 | if (crtc->state->active && |
| 13546 | (crtc->state->planes_changed || update_pipe)) |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13547 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13548 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13549 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) |
| 13550 | crtc_vblank_mask |= 1 << i; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13551 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13552 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13553 | /* FIXME: add subpixel order */ |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13554 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13555 | if (!state->legacy_cursor_update) |
| 13556 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13557 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13558 | /* |
| 13559 | * Now that the vblank has passed, we can go ahead and program the |
| 13560 | * optimal watermarks on platforms that need two-step watermark |
| 13561 | * programming. |
| 13562 | * |
| 13563 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13564 | */ |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13565 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13566 | intel_cstate = to_intel_crtc_state(crtc->state); |
| 13567 | |
| 13568 | if (dev_priv->display.optimize_watermarks) |
| 13569 | dev_priv->display.optimize_watermarks(intel_cstate); |
| 13570 | } |
| 13571 | |
Matt Roper | 177246a | 2016-03-04 15:59:39 -0800 | [diff] [blame] | 13572 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 13573 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13574 | |
| 13575 | if (put_domains[i]) |
| 13576 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13577 | } |
| 13578 | |
| 13579 | if (intel_state->modeset) |
| 13580 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
| 13581 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13582 | mutex_lock(&dev->struct_mutex); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13583 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13584 | mutex_unlock(&dev->struct_mutex); |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13585 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13586 | if (hw_check) |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 13587 | intel_modeset_check_state(dev, state); |
| 13588 | |
| 13589 | drm_atomic_state_free(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 13590 | |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13591 | /* As one of the primary mmio accessors, KMS has a high likelihood |
| 13592 | * of triggering bugs in unclaimed access. After we finish |
| 13593 | * modesetting, see if an error has been flagged, and if so |
| 13594 | * enable debugging for the next modeset - and hope we catch |
| 13595 | * the culprit. |
| 13596 | * |
| 13597 | * XXX note that we assume display power is on at this point. |
| 13598 | * This might hold true now but we need to add pm helper to check |
| 13599 | * unclaimed only when the hardware is on, as atomic commits |
| 13600 | * can happen also when the device is completely off. |
| 13601 | */ |
| 13602 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
| 13603 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13604 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13605 | } |
| 13606 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13607 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 13608 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13609 | struct drm_device *dev = crtc->dev; |
| 13610 | struct drm_atomic_state *state; |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13611 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13612 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13613 | |
| 13614 | state = drm_atomic_state_alloc(dev); |
| 13615 | if (!state) { |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13616 | 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] | 13617 | crtc->base.id); |
| 13618 | return; |
| 13619 | } |
| 13620 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13621 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13622 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13623 | retry: |
| 13624 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13625 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 13626 | if (!ret) { |
| 13627 | if (!crtc_state->active) |
| 13628 | goto out; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13629 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13630 | crtc_state->mode_changed = true; |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13631 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13632 | } |
| 13633 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13634 | if (ret == -EDEADLK) { |
| 13635 | drm_atomic_state_clear(state); |
| 13636 | drm_modeset_backoff(state->acquire_ctx); |
| 13637 | goto retry; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 13638 | } |
| 13639 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13640 | if (ret) |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13641 | out: |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13642 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13643 | } |
| 13644 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 13645 | #undef for_each_intel_crtc_masked |
| 13646 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13647 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13648 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13649 | .set_config = drm_atomic_helper_set_config, |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13650 | .set_property = drm_atomic_helper_crtc_set_property, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13651 | .destroy = intel_crtc_destroy, |
| 13652 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13653 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13654 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13655 | }; |
| 13656 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13657 | /** |
| 13658 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13659 | * @plane: drm plane to prepare for |
| 13660 | * @fb: framebuffer to prepare for presentation |
| 13661 | * |
| 13662 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13663 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13664 | * bits. Some older platforms need special physical address handling for |
| 13665 | * cursor planes. |
| 13666 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13667 | * Must be called with struct_mutex held. |
| 13668 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13669 | * Returns 0 on success, negative error code on failure. |
| 13670 | */ |
| 13671 | int |
| 13672 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13673 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13674 | { |
| 13675 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13676 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13677 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13678 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13679 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13680 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13681 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13682 | if (!obj && !old_obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13683 | return 0; |
| 13684 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13685 | if (old_obj) { |
| 13686 | struct drm_crtc_state *crtc_state = |
| 13687 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); |
| 13688 | |
| 13689 | /* Big Hammer, we also need to ensure that any pending |
| 13690 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13691 | * current scanout is retired before unpinning the old |
| 13692 | * framebuffer. Note that we rely on userspace rendering |
| 13693 | * into the buffer attached to the pipe they are waiting |
| 13694 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13695 | * point to the MI_WAIT_FOR_EVENT. |
| 13696 | * |
| 13697 | * This should only fail upon a hung GPU, in which case we |
| 13698 | * can safely continue. |
| 13699 | */ |
| 13700 | if (needs_modeset(crtc_state)) |
| 13701 | ret = i915_gem_object_wait_rendering(old_obj, true); |
| 13702 | |
| 13703 | /* Swallow -EIO errors to allow updates during hw lockup. */ |
| 13704 | if (ret && ret != -EIO) |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13705 | return ret; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13706 | } |
| 13707 | |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13708 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 13709 | if (obj && obj->base.dma_buf) { |
Maarten Lankhorst | bcf8be2 | 2015-12-08 15:52:56 +0100 | [diff] [blame] | 13710 | long lret; |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13711 | |
Maarten Lankhorst | bcf8be2 | 2015-12-08 15:52:56 +0100 | [diff] [blame] | 13712 | lret = reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 13713 | false, true, |
| 13714 | MAX_SCHEDULE_TIMEOUT); |
| 13715 | if (lret == -ERESTARTSYS) |
| 13716 | return lret; |
| 13717 | |
| 13718 | WARN(lret < 0, "waiting returns %li\n", lret); |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13719 | } |
| 13720 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13721 | if (!obj) { |
| 13722 | ret = 0; |
| 13723 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13724 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 13725 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 13726 | ret = i915_gem_object_attach_phys(obj, align); |
| 13727 | if (ret) |
| 13728 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 13729 | } else { |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 13730 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13731 | } |
| 13732 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13733 | if (ret == 0) { |
| 13734 | if (obj) { |
| 13735 | struct intel_plane_state *plane_state = |
| 13736 | to_intel_plane_state(new_state); |
| 13737 | |
| 13738 | i915_gem_request_assign(&plane_state->wait_req, |
| 13739 | obj->last_write_req); |
| 13740 | } |
| 13741 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13742 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13743 | } |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13744 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13745 | return ret; |
| 13746 | } |
| 13747 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13748 | /** |
| 13749 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13750 | * @plane: drm plane to clean up for |
| 13751 | * @fb: old framebuffer that was on plane |
| 13752 | * |
| 13753 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13754 | * |
| 13755 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13756 | */ |
| 13757 | void |
| 13758 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13759 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13760 | { |
| 13761 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13762 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13763 | struct intel_plane_state *old_intel_state; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13764 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
| 13765 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13766 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13767 | old_intel_state = to_intel_plane_state(old_state); |
| 13768 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13769 | if (!obj && !old_obj) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13770 | return; |
| 13771 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13772 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 13773 | !INTEL_INFO(dev)->cursor_needs_physical)) |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 13774 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13775 | |
| 13776 | /* prepare_fb aborted? */ |
| 13777 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || |
| 13778 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) |
| 13779 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13780 | |
| 13781 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13782 | } |
| 13783 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13784 | int |
| 13785 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 13786 | { |
| 13787 | int max_scale; |
| 13788 | struct drm_device *dev; |
| 13789 | struct drm_i915_private *dev_priv; |
| 13790 | int crtc_clock, cdclk; |
| 13791 | |
Maarten Lankhorst | bf8a0af | 2015-11-24 11:29:02 +0100 | [diff] [blame] | 13792 | if (!intel_crtc || !crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13793 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13794 | |
| 13795 | dev = intel_crtc->base.dev; |
| 13796 | dev_priv = dev->dev_private; |
| 13797 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13798 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13799 | |
Tvrtko Ursulin | 54bf1ce | 2015-10-20 17:17:07 +0100 | [diff] [blame] | 13800 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13801 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13802 | |
| 13803 | /* |
| 13804 | * skl max scale is lower of: |
| 13805 | * close to 3 but not 3, -1 is for that purpose |
| 13806 | * or |
| 13807 | * cdclk/crtc_clock |
| 13808 | */ |
| 13809 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 13810 | |
| 13811 | return max_scale; |
| 13812 | } |
| 13813 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13814 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13815 | intel_check_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13816 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13817 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13818 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13819 | struct drm_crtc *crtc = state->base.crtc; |
| 13820 | struct drm_framebuffer *fb = state->base.fb; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13821 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13822 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 13823 | bool can_position = false; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13824 | |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 13825 | if (INTEL_INFO(plane->dev)->gen >= 9) { |
| 13826 | /* use scaler when colorkey is not required */ |
| 13827 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { |
| 13828 | min_scale = 1; |
| 13829 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); |
| 13830 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13831 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13832 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13833 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13834 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 13835 | &state->dst, &state->clip, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13836 | min_scale, max_scale, |
| 13837 | can_position, true, |
| 13838 | &state->visible); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13839 | } |
| 13840 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13841 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13842 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13843 | { |
| 13844 | struct drm_device *dev = crtc->dev; |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13845 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13846 | struct intel_crtc_state *old_intel_state = |
| 13847 | to_intel_crtc_state(old_crtc_state); |
| 13848 | bool modeset = needs_modeset(crtc->state); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13849 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 13850 | /* Perform vblank evasion around commit operation */ |
Maarten Lankhorst | 6285262 | 2015-09-23 16:29:38 +0200 | [diff] [blame] | 13851 | intel_pipe_update_start(intel_crtc); |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 13852 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13853 | if (modeset) |
| 13854 | return; |
| 13855 | |
| 13856 | if (to_intel_crtc_state(crtc->state)->update_pipe) |
| 13857 | intel_update_pipe_config(intel_crtc, old_intel_state); |
| 13858 | else if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 13859 | skl_detach_scalers(intel_crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13860 | } |
| 13861 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13862 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13863 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13864 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13865 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13866 | |
Maarten Lankhorst | 6285262 | 2015-09-23 16:29:38 +0200 | [diff] [blame] | 13867 | intel_pipe_update_end(intel_crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13868 | } |
| 13869 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13870 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13871 | * intel_plane_destroy - destroy a plane |
| 13872 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13873 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13874 | * Common destruction function for all types of planes (primary, cursor, |
| 13875 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13876 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13877 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13878 | { |
| 13879 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13880 | drm_plane_cleanup(plane); |
| 13881 | kfree(intel_plane); |
| 13882 | } |
| 13883 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13884 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 13885 | .update_plane = drm_atomic_helper_update_plane, |
| 13886 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13887 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 13888 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 13889 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13890 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13891 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13892 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13893 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13894 | }; |
| 13895 | |
| 13896 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 13897 | int pipe) |
| 13898 | { |
| 13899 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13900 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13901 | const uint32_t *intel_primary_formats; |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 13902 | unsigned int num_formats; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13903 | |
| 13904 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 13905 | if (primary == NULL) |
| 13906 | return NULL; |
| 13907 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13908 | state = intel_create_plane_state(&primary->base); |
| 13909 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13910 | kfree(primary); |
| 13911 | return NULL; |
| 13912 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13913 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13914 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13915 | primary->can_scale = false; |
| 13916 | primary->max_downscale = 1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13917 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13918 | primary->can_scale = true; |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13919 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13920 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13921 | primary->pipe = pipe; |
| 13922 | primary->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13923 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13924 | primary->check_plane = intel_check_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13925 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 13926 | primary->plane = !pipe; |
| 13927 | |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13928 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13929 | intel_primary_formats = skl_primary_formats; |
| 13930 | num_formats = ARRAY_SIZE(skl_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13931 | |
| 13932 | primary->update_plane = skylake_update_primary_plane; |
| 13933 | primary->disable_plane = skylake_disable_primary_plane; |
| 13934 | } else if (HAS_PCH_SPLIT(dev)) { |
| 13935 | intel_primary_formats = i965_primary_formats; |
| 13936 | num_formats = ARRAY_SIZE(i965_primary_formats); |
| 13937 | |
| 13938 | primary->update_plane = ironlake_update_primary_plane; |
| 13939 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13940 | } else if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13941 | intel_primary_formats = i965_primary_formats; |
| 13942 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13943 | |
| 13944 | primary->update_plane = i9xx_update_primary_plane; |
| 13945 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13946 | } else { |
| 13947 | intel_primary_formats = i8xx_primary_formats; |
| 13948 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13949 | |
| 13950 | primary->update_plane = i9xx_update_primary_plane; |
| 13951 | primary->disable_plane = i9xx_disable_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13952 | } |
| 13953 | |
| 13954 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13955 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13956 | intel_primary_formats, num_formats, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 13957 | DRM_PLANE_TYPE_PRIMARY, NULL); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13958 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13959 | if (INTEL_INFO(dev)->gen >= 4) |
| 13960 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13961 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13962 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 13963 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13964 | return &primary->base; |
| 13965 | } |
| 13966 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 13967 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 13968 | { |
| 13969 | if (!dev->mode_config.rotation_property) { |
| 13970 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 13971 | BIT(DRM_ROTATE_180); |
| 13972 | |
| 13973 | if (INTEL_INFO(dev)->gen >= 9) |
| 13974 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 13975 | |
| 13976 | dev->mode_config.rotation_property = |
| 13977 | drm_mode_create_rotation_property(dev, flags); |
| 13978 | } |
| 13979 | if (dev->mode_config.rotation_property) |
| 13980 | drm_object_attach_property(&plane->base.base, |
| 13981 | dev->mode_config.rotation_property, |
| 13982 | plane->base.state->rotation); |
| 13983 | } |
| 13984 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13985 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13986 | intel_check_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13987 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13988 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13989 | { |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13990 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13991 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13992 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 13993 | enum pipe pipe = to_intel_plane(plane)->pipe; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13994 | unsigned stride; |
| 13995 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13996 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13997 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 13998 | &state->dst, &state->clip, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13999 | DRM_PLANE_HELPER_NO_SCALING, |
| 14000 | DRM_PLANE_HELPER_NO_SCALING, |
| 14001 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14002 | if (ret) |
| 14003 | return ret; |
| 14004 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14005 | /* if we want to turn off the cursor ignore width and height */ |
| 14006 | if (!obj) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14007 | return 0; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14008 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14009 | /* Check for which cursor types we support */ |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14010 | 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] | 14011 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 14012 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14013 | return -EINVAL; |
| 14014 | } |
| 14015 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14016 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 14017 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14018 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 14019 | return -ENOMEM; |
| 14020 | } |
| 14021 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 14022 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14023 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14024 | return -EINVAL; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14025 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14026 | |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 14027 | /* |
| 14028 | * There's something wrong with the cursor on CHV pipe C. |
| 14029 | * If it straddles the left edge of the screen then |
| 14030 | * moving it away from the edge or disabling it often |
| 14031 | * results in a pipe underrun, and often that can lead to |
| 14032 | * dead pipe (constant underrun reported, and it scans |
| 14033 | * out just a solid color). To recover from that, the |
| 14034 | * display power well must be turned off and on again. |
| 14035 | * Refuse the put the cursor into that compromised position. |
| 14036 | */ |
| 14037 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && |
| 14038 | state->visible && state->base.crtc_x < 0) { |
| 14039 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 14040 | return -EINVAL; |
| 14041 | } |
| 14042 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14043 | return 0; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14044 | } |
| 14045 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14046 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14047 | intel_disable_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 14048 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14049 | { |
Maarten Lankhorst | f285802 | 2016-01-07 11:54:09 +0100 | [diff] [blame] | 14050 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14051 | |
| 14052 | intel_crtc->cursor_addr = 0; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14053 | intel_crtc_update_cursor(crtc, NULL); |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14054 | } |
| 14055 | |
| 14056 | static void |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14057 | intel_update_cursor_plane(struct drm_plane *plane, |
| 14058 | const struct intel_crtc_state *crtc_state, |
| 14059 | const struct intel_plane_state *state) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14060 | { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14061 | struct drm_crtc *crtc = crtc_state->base.crtc; |
| 14062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14063 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14064 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14065 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14066 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14067 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14068 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14069 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14070 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14071 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14072 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14073 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14074 | intel_crtc->cursor_addr = addr; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14075 | intel_crtc_update_cursor(crtc, state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14076 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14077 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14078 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 14079 | int pipe) |
| 14080 | { |
| 14081 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14082 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14083 | |
| 14084 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 14085 | if (cursor == NULL) |
| 14086 | return NULL; |
| 14087 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14088 | state = intel_create_plane_state(&cursor->base); |
| 14089 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14090 | kfree(cursor); |
| 14091 | return NULL; |
| 14092 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14093 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14094 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14095 | cursor->can_scale = false; |
| 14096 | cursor->max_downscale = 1; |
| 14097 | cursor->pipe = pipe; |
| 14098 | cursor->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 14099 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 14100 | cursor->check_plane = intel_check_cursor_plane; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14101 | cursor->update_plane = intel_update_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14102 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14103 | |
| 14104 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 14105 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14106 | intel_cursor_formats, |
| 14107 | ARRAY_SIZE(intel_cursor_formats), |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 14108 | DRM_PLANE_TYPE_CURSOR, NULL); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14109 | |
| 14110 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14111 | if (!dev->mode_config.rotation_property) |
| 14112 | dev->mode_config.rotation_property = |
| 14113 | drm_mode_create_rotation_property(dev, |
| 14114 | BIT(DRM_ROTATE_0) | |
| 14115 | BIT(DRM_ROTATE_180)); |
| 14116 | if (dev->mode_config.rotation_property) |
| 14117 | drm_object_attach_property(&cursor->base.base, |
| 14118 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14119 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14120 | } |
| 14121 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 14122 | if (INTEL_INFO(dev)->gen >=9) |
| 14123 | state->scaler_id = -1; |
| 14124 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14125 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14126 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14127 | return &cursor->base; |
| 14128 | } |
| 14129 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14130 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 14131 | struct intel_crtc_state *crtc_state) |
| 14132 | { |
| 14133 | int i; |
| 14134 | struct intel_scaler *intel_scaler; |
| 14135 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 14136 | |
| 14137 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 14138 | intel_scaler = &scaler_state->scalers[i]; |
| 14139 | intel_scaler->in_use = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14140 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 14141 | } |
| 14142 | |
| 14143 | scaler_state->scaler_id = -1; |
| 14144 | } |
| 14145 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 14146 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14147 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14148 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14149 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14150 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14151 | struct drm_plane *primary = NULL; |
| 14152 | struct drm_plane *cursor = NULL; |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14153 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14154 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14155 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14156 | if (intel_crtc == NULL) |
| 14157 | return; |
| 14158 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14159 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 14160 | if (!crtc_state) |
| 14161 | goto fail; |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14162 | intel_crtc->config = crtc_state; |
| 14163 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14164 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14165 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14166 | /* initialize shared scalers */ |
| 14167 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14168 | if (pipe == PIPE_C) |
| 14169 | intel_crtc->num_scalers = 1; |
| 14170 | else |
| 14171 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 14172 | |
| 14173 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 14174 | } |
| 14175 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14176 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14177 | if (!primary) |
| 14178 | goto fail; |
| 14179 | |
| 14180 | cursor = intel_cursor_plane_create(dev, pipe); |
| 14181 | if (!cursor) |
| 14182 | goto fail; |
| 14183 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14184 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 14185 | cursor, &intel_crtc_funcs, NULL); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14186 | if (ret) |
| 14187 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14188 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 14189 | /* |
| 14190 | * 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] | 14191 | * 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] | 14192 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14193 | intel_crtc->pipe = pipe; |
| 14194 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 14195 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14196 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 14197 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14198 | } |
| 14199 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 14200 | intel_crtc->cursor_base = ~0; |
| 14201 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14202 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 14203 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 14204 | intel_crtc->wm.cxsr_allowed = true; |
| 14205 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14206 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14207 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 14208 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 14209 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 14210 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14211 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14212 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14213 | intel_color_init(&intel_crtc->base); |
| 14214 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14215 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14216 | return; |
| 14217 | |
| 14218 | fail: |
| 14219 | if (primary) |
| 14220 | drm_plane_cleanup(primary); |
| 14221 | if (cursor) |
| 14222 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14223 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14224 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14225 | } |
| 14226 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14227 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 14228 | { |
| 14229 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14230 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14231 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 14232 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14233 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 14234 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14235 | return INVALID_PIPE; |
| 14236 | |
| 14237 | return to_intel_crtc(encoder->crtc)->pipe; |
| 14238 | } |
| 14239 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14240 | 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] | 14241 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14242 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14243 | 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] | 14244 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14245 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14246 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14247 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14248 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14249 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14250 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14251 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14252 | } |
| 14253 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14254 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14255 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14256 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14257 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14258 | } |
| 14259 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14260 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14261 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14262 | struct drm_device *dev = encoder->base.dev; |
| 14263 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14264 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14265 | int entry = 0; |
| 14266 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14267 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14268 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14269 | index_mask |= (1 << entry); |
| 14270 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14271 | entry++; |
| 14272 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14273 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14274 | return index_mask; |
| 14275 | } |
| 14276 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14277 | static bool has_edp_a(struct drm_device *dev) |
| 14278 | { |
| 14279 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14280 | |
| 14281 | if (!IS_MOBILE(dev)) |
| 14282 | return false; |
| 14283 | |
| 14284 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14285 | return false; |
| 14286 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 14287 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14288 | return false; |
| 14289 | |
| 14290 | return true; |
| 14291 | } |
| 14292 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14293 | static bool intel_crt_present(struct drm_device *dev) |
| 14294 | { |
| 14295 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14296 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14297 | if (INTEL_INFO(dev)->gen >= 9) |
| 14298 | return false; |
| 14299 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 14300 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14301 | return false; |
| 14302 | |
| 14303 | if (IS_CHERRYVIEW(dev)) |
| 14304 | return false; |
| 14305 | |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14306 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
| 14307 | return false; |
| 14308 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14309 | /* DDI E can't be used if DDI A requires 4 lanes */ |
| 14310 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
| 14311 | return false; |
| 14312 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14313 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14314 | return false; |
| 14315 | |
| 14316 | return true; |
| 14317 | } |
| 14318 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14319 | static void intel_setup_outputs(struct drm_device *dev) |
| 14320 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14321 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14322 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14323 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14324 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 14325 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14326 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14327 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 14328 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14329 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14330 | if (IS_BROXTON(dev)) { |
| 14331 | /* |
| 14332 | * FIXME: Broxton doesn't support port detection via the |
| 14333 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14334 | * detect the ports. |
| 14335 | */ |
| 14336 | intel_ddi_init(dev, PORT_A); |
| 14337 | intel_ddi_init(dev, PORT_B); |
| 14338 | intel_ddi_init(dev, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14339 | |
| 14340 | intel_dsi_init(dev); |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14341 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14342 | int found; |
| 14343 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14344 | /* |
| 14345 | * Haswell uses DDI functions to detect digital outputs. |
| 14346 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14347 | * it's there. |
| 14348 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14349 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14350 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14351 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14352 | intel_ddi_init(dev, PORT_A); |
| 14353 | |
| 14354 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 14355 | * register */ |
| 14356 | found = I915_READ(SFUSE_STRAP); |
| 14357 | |
| 14358 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 14359 | intel_ddi_init(dev, PORT_B); |
| 14360 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 14361 | intel_ddi_init(dev, PORT_C); |
| 14362 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 14363 | intel_ddi_init(dev, PORT_D); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14364 | /* |
| 14365 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14366 | */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14367 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14368 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14369 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14370 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
| 14371 | intel_ddi_init(dev, PORT_E); |
| 14372 | |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14373 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14374 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 14375 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14376 | |
| 14377 | if (has_edp_a(dev)) |
| 14378 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14379 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14380 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14381 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14382 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14383 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14384 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14385 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14386 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14387 | } |
| 14388 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14389 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14390 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14391 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14392 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14393 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14394 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14395 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14396 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14397 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14398 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14399 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14400 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14401 | /* |
| 14402 | * The DP_DETECTED bit is the latched state of the DDC |
| 14403 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14404 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14405 | * eDP ports may have been muxed to an alternate function. |
| 14406 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14407 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14408 | * detect eDP ports. |
| 14409 | */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14410 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14411 | !intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14412 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
| 14413 | if (I915_READ(VLV_DP_B) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14414 | intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14415 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14416 | |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14417 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14418 | !intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14419 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
| 14420 | if (I915_READ(VLV_DP_C) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14421 | intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14422 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14423 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14424 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14425 | /* eDP not supported on port D, so don't check VBT */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14426 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
| 14427 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); |
| 14428 | if (I915_READ(CHV_DP_D) & DP_DETECTED) |
| 14429 | intel_dp_init(dev, CHV_DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14430 | } |
| 14431 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 14432 | intel_dsi_init(dev); |
Daniel Vetter | 09da55d | 2015-07-07 11:44:32 +0200 | [diff] [blame] | 14433 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14434 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14435 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14436 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14437 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14438 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14439 | if (!found && IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14440 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14441 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14442 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14443 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14444 | if (!found && IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14445 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14446 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14447 | |
| 14448 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14449 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14450 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14451 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14452 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14453 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14454 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14455 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14456 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14457 | if (IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14458 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14459 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14460 | } |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14461 | if (IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14462 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14463 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14464 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14465 | if (IS_G4X(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 14466 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14467 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 14468 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14469 | intel_dvo_init(dev); |
| 14470 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 14471 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14472 | intel_tv_init(dev); |
| 14473 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 14474 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14475 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14476 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14477 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14478 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14479 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14480 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14481 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 14482 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14483 | |
| 14484 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14485 | } |
| 14486 | |
| 14487 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14488 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14489 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14490 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14491 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14492 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14493 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14494 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14495 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 14496 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14497 | kfree(intel_fb); |
| 14498 | } |
| 14499 | |
| 14500 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14501 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14502 | unsigned int *handle) |
| 14503 | { |
| 14504 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14505 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14506 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14507 | if (obj->userptr.mm) { |
| 14508 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14509 | return -EINVAL; |
| 14510 | } |
| 14511 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14512 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14513 | } |
| 14514 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14515 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14516 | struct drm_file *file, |
| 14517 | unsigned flags, unsigned color, |
| 14518 | struct drm_clip_rect *clips, |
| 14519 | unsigned num_clips) |
| 14520 | { |
| 14521 | struct drm_device *dev = fb->dev; |
| 14522 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 14523 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 14524 | |
| 14525 | mutex_lock(&dev->struct_mutex); |
Paulo Zanoni | 74b4ea1 | 2015-07-14 16:29:14 -0300 | [diff] [blame] | 14526 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14527 | mutex_unlock(&dev->struct_mutex); |
| 14528 | |
| 14529 | return 0; |
| 14530 | } |
| 14531 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14532 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14533 | .destroy = intel_user_framebuffer_destroy, |
| 14534 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14535 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14536 | }; |
| 14537 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14538 | static |
| 14539 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 14540 | uint32_t pixel_format) |
| 14541 | { |
| 14542 | u32 gen = INTEL_INFO(dev)->gen; |
| 14543 | |
| 14544 | if (gen >= 9) { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14545 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 14546 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14547 | /* "The stride in bytes must not exceed the of the size of 8K |
| 14548 | * pixels and 32K bytes." |
| 14549 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14550 | return min(8192 * cpp, 32768); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14551 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14552 | return 32*1024; |
| 14553 | } else if (gen >= 4) { |
| 14554 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14555 | return 16*1024; |
| 14556 | else |
| 14557 | return 32*1024; |
| 14558 | } else if (gen >= 3) { |
| 14559 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14560 | return 8*1024; |
| 14561 | else |
| 14562 | return 16*1024; |
| 14563 | } else { |
| 14564 | /* XXX DSPC is limited to 4k tiled */ |
| 14565 | return 8*1024; |
| 14566 | } |
| 14567 | } |
| 14568 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 14569 | static int intel_framebuffer_init(struct drm_device *dev, |
| 14570 | struct intel_framebuffer *intel_fb, |
| 14571 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 14572 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14573 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14574 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 14575 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14576 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14577 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14578 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14579 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 14580 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14581 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 14582 | /* Enforce that fb modifier and tiling mode match, but only for |
| 14583 | * X-tiled. This is needed for FBC. */ |
| 14584 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 14585 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 14586 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 14587 | return -EINVAL; |
| 14588 | } |
| 14589 | } else { |
| 14590 | if (obj->tiling_mode == I915_TILING_X) |
| 14591 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 14592 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 14593 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 14594 | return -EINVAL; |
| 14595 | } |
| 14596 | } |
| 14597 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14598 | /* Passed in modifier sanity checking. */ |
| 14599 | switch (mode_cmd->modifier[0]) { |
| 14600 | case I915_FORMAT_MOD_Y_TILED: |
| 14601 | case I915_FORMAT_MOD_Yf_TILED: |
| 14602 | if (INTEL_INFO(dev)->gen < 9) { |
| 14603 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 14604 | mode_cmd->modifier[0]); |
| 14605 | return -EINVAL; |
| 14606 | } |
| 14607 | case DRM_FORMAT_MOD_NONE: |
| 14608 | case I915_FORMAT_MOD_X_TILED: |
| 14609 | break; |
| 14610 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 14611 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 14612 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14613 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14614 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14615 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14616 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
| 14617 | mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14618 | mode_cmd->pixel_format); |
| 14619 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 14620 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 14621 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14622 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14623 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14624 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14625 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 14626 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14627 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14628 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 14629 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14630 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14631 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14632 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14633 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14634 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14635 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14636 | mode_cmd->pitches[0] != obj->stride) { |
| 14637 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 14638 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14639 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14640 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14641 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14642 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14643 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14644 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14645 | case DRM_FORMAT_RGB565: |
| 14646 | case DRM_FORMAT_XRGB8888: |
| 14647 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14648 | break; |
| 14649 | case DRM_FORMAT_XRGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14650 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14651 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14652 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14653 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14654 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14655 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14656 | case DRM_FORMAT_ABGR8888: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14657 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
| 14658 | INTEL_INFO(dev)->gen < 9) { |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14659 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14660 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14661 | return -EINVAL; |
| 14662 | } |
| 14663 | break; |
| 14664 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14665 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14666 | case DRM_FORMAT_XBGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14667 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14668 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14669 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14670 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14671 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14672 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14673 | case DRM_FORMAT_ABGR2101010: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14674 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14675 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14676 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14677 | return -EINVAL; |
| 14678 | } |
| 14679 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14680 | case DRM_FORMAT_YUYV: |
| 14681 | case DRM_FORMAT_UYVY: |
| 14682 | case DRM_FORMAT_YVYU: |
| 14683 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14684 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14685 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14686 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14687 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14688 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14689 | break; |
| 14690 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14691 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14692 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14693 | return -EINVAL; |
| 14694 | } |
| 14695 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14696 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14697 | if (mode_cmd->offsets[0] != 0) |
| 14698 | return -EINVAL; |
| 14699 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 14700 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 14701 | mode_cmd->pixel_format, |
| 14702 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 14703 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 14704 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 14705 | return -EINVAL; |
| 14706 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14707 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 14708 | intel_fb->obj = obj; |
| 14709 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14710 | intel_fill_fb_info(dev_priv, &intel_fb->base); |
| 14711 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14712 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 14713 | if (ret) { |
| 14714 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 14715 | return ret; |
| 14716 | } |
| 14717 | |
Ville Syrjälä | 0b05e1e | 2016-01-14 15:22:09 +0200 | [diff] [blame] | 14718 | intel_fb->obj->framebuffer_references++; |
| 14719 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14720 | return 0; |
| 14721 | } |
| 14722 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14723 | static struct drm_framebuffer * |
| 14724 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14725 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14726 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14727 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14728 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14729 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14730 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14731 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14732 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14733 | mode_cmd.handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 14734 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14735 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14736 | |
Daniel Vetter | 92907cb | 2015-11-23 09:04:05 +0100 | [diff] [blame] | 14737 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14738 | if (IS_ERR(fb)) |
| 14739 | drm_gem_object_unreference_unlocked(&obj->base); |
| 14740 | |
| 14741 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14742 | } |
| 14743 | |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 14744 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14745 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14746 | { |
| 14747 | } |
| 14748 | #endif |
| 14749 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14750 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14751 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14752 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14753 | .atomic_check = intel_atomic_check, |
| 14754 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14755 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14756 | .atomic_state_clear = intel_atomic_state_clear, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14757 | }; |
| 14758 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14759 | /** |
| 14760 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14761 | * @dev_priv: device private |
| 14762 | */ |
| 14763 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14764 | { |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14765 | if (HAS_PCH_SPLIT(dev_priv) || IS_G4X(dev_priv)) |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14766 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14767 | else if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 14768 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14769 | else if (IS_VALLEYVIEW(dev_priv)) |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14770 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14771 | else if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 14772 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 14773 | else |
| 14774 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 14775 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14776 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14777 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14778 | dev_priv->display.get_initial_plane_config = |
| 14779 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14780 | dev_priv->display.crtc_compute_clock = |
| 14781 | haswell_crtc_compute_clock; |
| 14782 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14783 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14784 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14785 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14786 | dev_priv->display.get_initial_plane_config = |
| 14787 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14788 | dev_priv->display.crtc_compute_clock = |
| 14789 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14790 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14791 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14792 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14793 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14794 | dev_priv->display.get_initial_plane_config = |
| 14795 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14796 | dev_priv->display.crtc_compute_clock = |
| 14797 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14798 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14799 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14800 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14801 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14802 | dev_priv->display.get_initial_plane_config = |
| 14803 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14804 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14805 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14806 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14807 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14808 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14809 | dev_priv->display.get_initial_plane_config = |
| 14810 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14811 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14812 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14813 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14814 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14815 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14816 | /* Returns the core display clock speed */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14817 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14818 | dev_priv->display.get_display_clock_speed = |
| 14819 | skylake_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14820 | else if (IS_BROXTON(dev_priv)) |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 14821 | dev_priv->display.get_display_clock_speed = |
| 14822 | broxton_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14823 | else if (IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14824 | dev_priv->display.get_display_clock_speed = |
| 14825 | broadwell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14826 | else if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14827 | dev_priv->display.get_display_clock_speed = |
| 14828 | haswell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14829 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 14830 | dev_priv->display.get_display_clock_speed = |
| 14831 | valleyview_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14832 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 14833 | dev_priv->display.get_display_clock_speed = |
| 14834 | ilk_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14835 | else if (IS_I945G(dev_priv) || IS_BROADWATER(dev_priv) || |
| 14836 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14837 | dev_priv->display.get_display_clock_speed = |
| 14838 | i945_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14839 | else if (IS_GM45(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14840 | dev_priv->display.get_display_clock_speed = |
| 14841 | gm45_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14842 | else if (IS_CRESTLINE(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14843 | dev_priv->display.get_display_clock_speed = |
| 14844 | i965gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14845 | else if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14846 | dev_priv->display.get_display_clock_speed = |
| 14847 | pnv_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14848 | else if (IS_G33(dev_priv) || IS_G4X(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14849 | dev_priv->display.get_display_clock_speed = |
| 14850 | g33_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14851 | else if (IS_I915G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14852 | dev_priv->display.get_display_clock_speed = |
| 14853 | i915_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14854 | else if (IS_I945GM(dev_priv) || IS_845G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14855 | dev_priv->display.get_display_clock_speed = |
| 14856 | i9xx_misc_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14857 | else if (IS_I915GM(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14858 | dev_priv->display.get_display_clock_speed = |
| 14859 | i915gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14860 | else if (IS_I865G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14861 | dev_priv->display.get_display_clock_speed = |
| 14862 | i865_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14863 | else if (IS_I85X(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14864 | dev_priv->display.get_display_clock_speed = |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 14865 | i85x_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14866 | else { /* 830 */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14867 | WARN(!IS_I830(dev_priv), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14868 | dev_priv->display.get_display_clock_speed = |
| 14869 | i830_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14870 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14871 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14872 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14873 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14874 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14875 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14876 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14877 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14878 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14879 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14880 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14881 | if (IS_BROADWELL(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14882 | dev_priv->display.modeset_commit_cdclk = |
| 14883 | broadwell_modeset_commit_cdclk; |
| 14884 | dev_priv->display.modeset_calc_cdclk = |
| 14885 | broadwell_modeset_calc_cdclk; |
| 14886 | } |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14887 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14888 | dev_priv->display.modeset_commit_cdclk = |
| 14889 | valleyview_modeset_commit_cdclk; |
| 14890 | dev_priv->display.modeset_calc_cdclk = |
| 14891 | valleyview_modeset_calc_cdclk; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14892 | } else if (IS_BROXTON(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14893 | dev_priv->display.modeset_commit_cdclk = |
| 14894 | broxton_modeset_commit_cdclk; |
| 14895 | dev_priv->display.modeset_calc_cdclk = |
| 14896 | broxton_modeset_calc_cdclk; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14897 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14898 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14899 | switch (INTEL_INFO(dev_priv)->gen) { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14900 | case 2: |
| 14901 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 14902 | break; |
| 14903 | |
| 14904 | case 3: |
| 14905 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 14906 | break; |
| 14907 | |
| 14908 | case 4: |
| 14909 | case 5: |
| 14910 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 14911 | break; |
| 14912 | |
| 14913 | case 6: |
| 14914 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 14915 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14916 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 14917 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14918 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 14919 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 14920 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 14921 | /* Drop through - unsupported since execlist only. */ |
| 14922 | default: |
| 14923 | /* Default just returns -ENODEV to indicate unsupported */ |
| 14924 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14925 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14926 | } |
| 14927 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14928 | /* |
| 14929 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 14930 | * resume, or other times. This quirk makes sure that's the case for |
| 14931 | * affected systems. |
| 14932 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 14933 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14934 | { |
| 14935 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14936 | |
| 14937 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14938 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14939 | } |
| 14940 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 14941 | static void quirk_pipeb_force(struct drm_device *dev) |
| 14942 | { |
| 14943 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14944 | |
| 14945 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 14946 | DRM_INFO("applying pipe b force quirk\n"); |
| 14947 | } |
| 14948 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14949 | /* |
| 14950 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 14951 | */ |
| 14952 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 14953 | { |
| 14954 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14955 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14956 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14957 | } |
| 14958 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14959 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14960 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 14961 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14962 | */ |
| 14963 | static void quirk_invert_brightness(struct drm_device *dev) |
| 14964 | { |
| 14965 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14966 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14967 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14968 | } |
| 14969 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14970 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 14971 | static void quirk_backlight_present(struct drm_device *dev) |
| 14972 | { |
| 14973 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14974 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 14975 | DRM_INFO("applying backlight present quirk\n"); |
| 14976 | } |
| 14977 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14978 | struct intel_quirk { |
| 14979 | int device; |
| 14980 | int subsystem_vendor; |
| 14981 | int subsystem_device; |
| 14982 | void (*hook)(struct drm_device *dev); |
| 14983 | }; |
| 14984 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14985 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 14986 | struct intel_dmi_quirk { |
| 14987 | void (*hook)(struct drm_device *dev); |
| 14988 | const struct dmi_system_id (*dmi_id_list)[]; |
| 14989 | }; |
| 14990 | |
| 14991 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 14992 | { |
| 14993 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 14994 | return 1; |
| 14995 | } |
| 14996 | |
| 14997 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 14998 | { |
| 14999 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 15000 | { |
| 15001 | .callback = intel_dmi_reverse_brightness, |
| 15002 | .ident = "NCR Corporation", |
| 15003 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 15004 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 15005 | }, |
| 15006 | }, |
| 15007 | { } /* terminating entry */ |
| 15008 | }, |
| 15009 | .hook = quirk_invert_brightness, |
| 15010 | }, |
| 15011 | }; |
| 15012 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 15013 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15014 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 15015 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 15016 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15017 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 15018 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 15019 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 15020 | /* 830 needs to leave pipe A & dpll A up */ |
| 15021 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 15022 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 15023 | /* 830 needs to leave pipe B & dpll B up */ |
| 15024 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 15025 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15026 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 15027 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 15028 | |
| 15029 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 15030 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 15031 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 15032 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 15033 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 15034 | |
| 15035 | /* Acer/eMachines G725 */ |
| 15036 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 15037 | |
| 15038 | /* Acer/eMachines e725 */ |
| 15039 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 15040 | |
| 15041 | /* Acer/Packard Bell NCL20 */ |
| 15042 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 15043 | |
| 15044 | /* Acer Aspire 4736Z */ |
| 15045 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 15046 | |
| 15047 | /* Acer Aspire 5336 */ |
| 15048 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 15049 | |
| 15050 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 15051 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15052 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 15053 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 15054 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 15055 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 15056 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 15057 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 15058 | |
Jani Nikula | 1b9448b0 | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 15059 | /* Apple Macbook 4,1 */ |
| 15060 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 15061 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15062 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 15063 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 15064 | |
| 15065 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 15066 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 15067 | |
| 15068 | /* Dell Chromebook 11 */ |
| 15069 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 15070 | |
| 15071 | /* Dell Chromebook 11 (2015 version) */ |
| 15072 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15073 | }; |
| 15074 | |
| 15075 | static void intel_init_quirks(struct drm_device *dev) |
| 15076 | { |
| 15077 | struct pci_dev *d = dev->pdev; |
| 15078 | int i; |
| 15079 | |
| 15080 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 15081 | struct intel_quirk *q = &intel_quirks[i]; |
| 15082 | |
| 15083 | if (d->device == q->device && |
| 15084 | (d->subsystem_vendor == q->subsystem_vendor || |
| 15085 | q->subsystem_vendor == PCI_ANY_ID) && |
| 15086 | (d->subsystem_device == q->subsystem_device || |
| 15087 | q->subsystem_device == PCI_ANY_ID)) |
| 15088 | q->hook(dev); |
| 15089 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 15090 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 15091 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 15092 | intel_dmi_quirks[i].hook(dev); |
| 15093 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15094 | } |
| 15095 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15096 | /* Disable the VGA plane that we never use */ |
| 15097 | static void i915_disable_vga(struct drm_device *dev) |
| 15098 | { |
| 15099 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15100 | u8 sr1; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15101 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15102 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 15103 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15104 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 15105 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15106 | sr1 = inb(VGA_SR_DATA); |
| 15107 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 15108 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 15109 | udelay(300); |
| 15110 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 15111 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15112 | POSTING_READ(vga_reg); |
| 15113 | } |
| 15114 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15115 | void intel_modeset_init_hw(struct drm_device *dev) |
| 15116 | { |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15117 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15118 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 15119 | intel_update_cdclk(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15120 | |
| 15121 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; |
| 15122 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15123 | intel_init_clock_gating(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 15124 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15125 | } |
| 15126 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15127 | /* |
| 15128 | * Calculate what we think the watermarks should be for the state we've read |
| 15129 | * out of the hardware and then immediately program those watermarks so that |
| 15130 | * we ensure the hardware settings match our internal state. |
| 15131 | * |
| 15132 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 15133 | * current state (which was constructed during hardware readout) and running it |
| 15134 | * through the atomic check code to calculate new watermark values in the |
| 15135 | * state object. |
| 15136 | */ |
| 15137 | static void sanitize_watermarks(struct drm_device *dev) |
| 15138 | { |
| 15139 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15140 | struct drm_atomic_state *state; |
| 15141 | struct drm_crtc *crtc; |
| 15142 | struct drm_crtc_state *cstate; |
| 15143 | struct drm_modeset_acquire_ctx ctx; |
| 15144 | int ret; |
| 15145 | int i; |
| 15146 | |
| 15147 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15148 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15149 | return; |
| 15150 | |
| 15151 | /* |
| 15152 | * We need to hold connection_mutex before calling duplicate_state so |
| 15153 | * that the connector loop is protected. |
| 15154 | */ |
| 15155 | drm_modeset_acquire_init(&ctx, 0); |
| 15156 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15157 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15158 | if (ret == -EDEADLK) { |
| 15159 | drm_modeset_backoff(&ctx); |
| 15160 | goto retry; |
| 15161 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15162 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15163 | } |
| 15164 | |
| 15165 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15166 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15167 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15168 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15169 | /* |
| 15170 | * Hardware readout is the only time we don't want to calculate |
| 15171 | * intermediate watermarks (since we don't trust the current |
| 15172 | * watermarks). |
| 15173 | */ |
| 15174 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
| 15175 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15176 | ret = intel_atomic_check(dev, state); |
| 15177 | if (ret) { |
| 15178 | /* |
| 15179 | * If we fail here, it means that the hardware appears to be |
| 15180 | * programmed in a way that shouldn't be possible, given our |
| 15181 | * understanding of watermark requirements. This might mean a |
| 15182 | * mistake in the hardware readout code or a mistake in the |
| 15183 | * watermark calculations for a given platform. Raise a WARN |
| 15184 | * so that this is noticeable. |
| 15185 | * |
| 15186 | * If this actually happens, we'll have to just leave the |
| 15187 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15188 | */ |
| 15189 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15190 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15191 | } |
| 15192 | |
| 15193 | /* Write calculated watermark values back */ |
| 15194 | to_i915(dev)->wm.config = to_intel_atomic_state(state)->wm_config; |
| 15195 | for_each_crtc_in_state(state, crtc, cstate, i) { |
| 15196 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15197 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15198 | cs->wm.need_postvbl_update = true; |
| 15199 | dev_priv->display.optimize_watermarks(cs); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15200 | } |
| 15201 | |
| 15202 | drm_atomic_state_free(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15203 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15204 | drm_modeset_drop_locks(&ctx); |
| 15205 | drm_modeset_acquire_fini(&ctx); |
| 15206 | } |
| 15207 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15208 | void intel_modeset_init(struct drm_device *dev) |
| 15209 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15210 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15211 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15212 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15213 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15214 | |
| 15215 | drm_mode_config_init(dev); |
| 15216 | |
| 15217 | dev->mode_config.min_width = 0; |
| 15218 | dev->mode_config.min_height = 0; |
| 15219 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15220 | dev->mode_config.preferred_depth = 24; |
| 15221 | dev->mode_config.prefer_shadow = 1; |
| 15222 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15223 | dev->mode_config.allow_fb_modifiers = true; |
| 15224 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15225 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15226 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15227 | intel_init_quirks(dev); |
| 15228 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15229 | intel_init_pm(dev); |
| 15230 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 15231 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 15232 | return; |
| 15233 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15234 | /* |
| 15235 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15236 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15237 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15238 | * indicates as much. |
| 15239 | */ |
| 15240 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { |
| 15241 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15242 | DREF_SSC1_ENABLE); |
| 15243 | |
| 15244 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15245 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15246 | bios_lvds_use_ssc ? "en" : "dis", |
| 15247 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15248 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15249 | } |
| 15250 | } |
| 15251 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15252 | if (IS_GEN2(dev)) { |
| 15253 | dev->mode_config.max_width = 2048; |
| 15254 | dev->mode_config.max_height = 2048; |
| 15255 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15256 | dev->mode_config.max_width = 4096; |
| 15257 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15258 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15259 | dev->mode_config.max_width = 8192; |
| 15260 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15261 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15262 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15263 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 15264 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 15265 | dev->mode_config.cursor_height = 1023; |
| 15266 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15267 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 15268 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 15269 | } else { |
| 15270 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 15271 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 15272 | } |
| 15273 | |
Joonas Lahtinen | 62106b4 | 2016-03-18 10:42:57 +0200 | [diff] [blame] | 15274 | dev->mode_config.fb_base = dev_priv->ggtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15275 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15276 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15277 | INTEL_INFO(dev)->num_pipes, |
| 15278 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15279 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15280 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15281 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 15282 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15283 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15284 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 15285 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15286 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15287 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15288 | } |
| 15289 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 15290 | intel_update_czclk(dev_priv); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 15291 | intel_update_rawclk(dev_priv); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 15292 | intel_update_cdclk(dev); |
| 15293 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15294 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15295 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15296 | /* Just disable it once at startup */ |
| 15297 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15298 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15299 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15300 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15301 | intel_modeset_setup_hw_state(dev); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15302 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15303 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15304 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15305 | struct intel_initial_plane_config plane_config = {}; |
| 15306 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15307 | if (!crtc->active) |
| 15308 | continue; |
| 15309 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15310 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15311 | * Note that reserving the BIOS fb up front prevents us |
| 15312 | * from stuffing other stolen allocations like the ring |
| 15313 | * on top. This prevents some ugliness at boot time, and |
| 15314 | * can even allow for smooth boot transitions if the BIOS |
| 15315 | * fb is large enough for the active pipe configuration. |
| 15316 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15317 | dev_priv->display.get_initial_plane_config(crtc, |
| 15318 | &plane_config); |
| 15319 | |
| 15320 | /* |
| 15321 | * If the fb is shared between multiple heads, we'll |
| 15322 | * just get the first one. |
| 15323 | */ |
| 15324 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15325 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15326 | |
| 15327 | /* |
| 15328 | * Make sure hardware watermarks really match the state we read out. |
| 15329 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15330 | * since the watermark calculation done here will use pstate->fb. |
| 15331 | */ |
| 15332 | sanitize_watermarks(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15333 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15334 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15335 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 15336 | { |
| 15337 | struct intel_connector *connector; |
| 15338 | struct drm_connector *crt = NULL; |
| 15339 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15340 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15341 | |
| 15342 | /* We can't just switch on the pipe A, we need to set things up with a |
| 15343 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 15344 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15345 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15346 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 15347 | crt = &connector->base; |
| 15348 | break; |
| 15349 | } |
| 15350 | } |
| 15351 | |
| 15352 | if (!crt) |
| 15353 | return; |
| 15354 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15355 | 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] | 15356 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15357 | } |
| 15358 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15359 | static bool |
| 15360 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 15361 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15362 | struct drm_device *dev = crtc->base.dev; |
| 15363 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15364 | u32 val; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15365 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15366 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15367 | return true; |
| 15368 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15369 | val = I915_READ(DSPCNTR(!crtc->plane)); |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15370 | |
| 15371 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 15372 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 15373 | return false; |
| 15374 | |
| 15375 | return true; |
| 15376 | } |
| 15377 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15378 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15379 | { |
| 15380 | struct drm_device *dev = crtc->base.dev; |
| 15381 | struct intel_encoder *encoder; |
| 15382 | |
| 15383 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15384 | return true; |
| 15385 | |
| 15386 | return false; |
| 15387 | } |
| 15388 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15389 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) |
| 15390 | { |
| 15391 | struct drm_device *dev = encoder->base.dev; |
| 15392 | struct intel_connector *connector; |
| 15393 | |
| 15394 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15395 | return true; |
| 15396 | |
| 15397 | return false; |
| 15398 | } |
| 15399 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15400 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 15401 | { |
| 15402 | struct drm_device *dev = crtc->base.dev; |
| 15403 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15404 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15405 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15406 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15407 | if (!transcoder_is_dsi(cpu_transcoder)) { |
| 15408 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15409 | |
| 15410 | I915_WRITE(reg, |
| 15411 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15412 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15413 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15414 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15415 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 15416 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15417 | struct intel_plane *plane; |
| 15418 | |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15419 | drm_crtc_vblank_on(&crtc->base); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15420 | |
| 15421 | /* Disable everything but the primary plane */ |
| 15422 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 15423 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 15424 | continue; |
| 15425 | |
| 15426 | plane->disable_plane(&plane->base, &crtc->base); |
| 15427 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15428 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15429 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15430 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15431 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 15432 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 15433 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15434 | bool plane; |
| 15435 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15436 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 15437 | crtc->base.base.id); |
| 15438 | |
| 15439 | /* Pipe has the wrong plane attached and the plane is active. |
| 15440 | * Temporarily change the plane mapping and disable everything |
| 15441 | * ... */ |
| 15442 | plane = crtc->plane; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15443 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15444 | crtc->plane = !plane; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15445 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15446 | crtc->plane = plane; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15447 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15448 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15449 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 15450 | crtc->pipe == PIPE_A && !crtc->active) { |
| 15451 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 15452 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 15453 | * call below we restore the pipe to the right state, but leave |
| 15454 | * the required bits on. */ |
| 15455 | intel_enable_pipe_a(dev); |
| 15456 | } |
| 15457 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15458 | /* Adjust the state of the output pipe according to whether we |
| 15459 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 15460 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15461 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15462 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 15463 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15464 | /* |
| 15465 | * We start out with underrun reporting disabled to avoid races. |
| 15466 | * For correct bookkeeping mark this on active crtcs. |
| 15467 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15468 | * Also on gmch platforms we dont have any hardware bits to |
| 15469 | * disable the underrun reporting. Which means we need to start |
| 15470 | * out with underrun reporting disabled also on inactive pipes, |
| 15471 | * since otherwise we'll complain about the garbage we read when |
| 15472 | * e.g. coming up after runtime pm. |
| 15473 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15474 | * No protection against concurrent access is required - at |
| 15475 | * worst a fifo underrun happens which also sets this to false. |
| 15476 | */ |
| 15477 | crtc->cpu_fifo_underrun_disabled = true; |
| 15478 | crtc->pch_fifo_underrun_disabled = true; |
| 15479 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15480 | } |
| 15481 | |
| 15482 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15483 | { |
| 15484 | struct intel_connector *connector; |
| 15485 | struct drm_device *dev = encoder->base.dev; |
| 15486 | |
| 15487 | /* We need to check both for a crtc link (meaning that the |
| 15488 | * encoder is active and trying to read from a pipe) and the |
| 15489 | * pipe itself being active. */ |
| 15490 | bool has_active_crtc = encoder->base.crtc && |
| 15491 | to_intel_crtc(encoder->base.crtc)->active; |
| 15492 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15493 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15494 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15495 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15496 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15497 | |
| 15498 | /* Connector is active, but has no active pipe. This is |
| 15499 | * fallout from our resume register restoring. Disable |
| 15500 | * the encoder manually again. */ |
| 15501 | if (encoder->base.crtc) { |
| 15502 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15503 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15504 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15505 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15506 | if (encoder->post_disable) |
| 15507 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15508 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15509 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15510 | |
| 15511 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15512 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15513 | * in our code, like the register restore mess on resume. Clamp |
| 15514 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15515 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15516 | if (connector->encoder != encoder) |
| 15517 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15518 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15519 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15520 | } |
| 15521 | } |
| 15522 | /* Enabled encoders without active connectors will be fixed in |
| 15523 | * the crtc fixup. */ |
| 15524 | } |
| 15525 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15526 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15527 | { |
| 15528 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15529 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15530 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15531 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15532 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 15533 | i915_disable_vga(dev); |
| 15534 | } |
| 15535 | } |
| 15536 | |
| 15537 | void i915_redisable_vga(struct drm_device *dev) |
| 15538 | { |
| 15539 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15540 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15541 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15542 | * at a very early point in our resume sequence, where the power well |
| 15543 | * structures are not yet restored. Since this function is at a very |
| 15544 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15545 | * level, just check if the power well is enabled instead of trying to |
| 15546 | * follow the "don't touch the power well if we don't need it" policy |
| 15547 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15548 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15549 | return; |
| 15550 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15551 | i915_redisable_vga_power_on(dev); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15552 | |
| 15553 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15554 | } |
| 15555 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15556 | static bool primary_get_hw_state(struct intel_plane *plane) |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15557 | { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15558 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15559 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15560 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15561 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15562 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15563 | /* FIXME read out full plane state for all planes */ |
| 15564 | static void readout_plane_state(struct intel_crtc *crtc) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15565 | { |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15566 | struct drm_plane *primary = crtc->base.primary; |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15567 | struct intel_plane_state *plane_state = |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15568 | to_intel_plane_state(primary->state); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15569 | |
Matt Roper | 19b8d38 | 2015-09-24 15:53:17 -0700 | [diff] [blame] | 15570 | plane_state->visible = crtc->active && |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15571 | primary_get_hw_state(to_intel_plane(primary)); |
| 15572 | |
| 15573 | if (plane_state->visible) |
| 15574 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15575 | } |
| 15576 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15577 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15578 | { |
| 15579 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15580 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15581 | struct intel_crtc *crtc; |
| 15582 | struct intel_encoder *encoder; |
| 15583 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15584 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15585 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15586 | dev_priv->active_crtcs = 0; |
| 15587 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15588 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15589 | struct intel_crtc_state *crtc_state = crtc->config; |
| 15590 | int pixclk = 0; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15591 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15592 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, &crtc_state->base); |
| 15593 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15594 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15595 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15596 | crtc_state->base.active = crtc_state->base.enable = |
| 15597 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15598 | |
| 15599 | crtc->base.enabled = crtc_state->base.enable; |
| 15600 | crtc->active = crtc_state->base.active; |
| 15601 | |
| 15602 | if (crtc_state->base.active) { |
| 15603 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15604 | |
| 15605 | if (IS_BROADWELL(dev_priv)) { |
| 15606 | pixclk = ilk_pipe_pixel_rate(crtc_state); |
| 15607 | |
| 15608 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 15609 | if (crtc_state->ips_enabled) |
| 15610 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); |
| 15611 | } else if (IS_VALLEYVIEW(dev_priv) || |
| 15612 | IS_CHERRYVIEW(dev_priv) || |
| 15613 | IS_BROXTON(dev_priv)) |
| 15614 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; |
| 15615 | else |
| 15616 | WARN_ON(dev_priv->display.modeset_calc_cdclk); |
| 15617 | } |
| 15618 | |
| 15619 | dev_priv->min_pixclk[crtc->pipe] = pixclk; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15620 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15621 | readout_plane_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15622 | |
| 15623 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 15624 | crtc->base.base.id, |
| 15625 | crtc->active ? "enabled" : "disabled"); |
| 15626 | } |
| 15627 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15628 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15629 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15630 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 15631 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
| 15632 | &pll->config.hw_state); |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15633 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15634 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15635 | if (crtc->active && crtc->config->shared_dpll == pll) |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15636 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15637 | } |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15638 | pll->active_mask = pll->config.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15639 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15640 | 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] | 15641 | pll->name, pll->config.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15642 | } |
| 15643 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15644 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15645 | pipe = 0; |
| 15646 | |
| 15647 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15648 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15649 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15650 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15651 | } else { |
| 15652 | encoder->base.crtc = NULL; |
| 15653 | } |
| 15654 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15655 | 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] | 15656 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15657 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15658 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15659 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15660 | } |
| 15661 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15662 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15663 | if (connector->get_hw_state(connector)) { |
| 15664 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15665 | |
| 15666 | encoder = connector->encoder; |
| 15667 | connector->base.encoder = &encoder->base; |
| 15668 | |
| 15669 | if (encoder->base.crtc && |
| 15670 | encoder->base.crtc->state->active) { |
| 15671 | /* |
| 15672 | * This has to be done during hardware readout |
| 15673 | * because anything calling .crtc_disable may |
| 15674 | * rely on the connector_mask being accurate. |
| 15675 | */ |
| 15676 | encoder->base.crtc->state->connector_mask |= |
| 15677 | 1 << drm_connector_index(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15678 | encoder->base.crtc->state->encoder_mask |= |
| 15679 | 1 << drm_encoder_index(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15680 | } |
| 15681 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15682 | } else { |
| 15683 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15684 | connector->base.encoder = NULL; |
| 15685 | } |
| 15686 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 15687 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 15688 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15689 | connector->base.encoder ? "enabled" : "disabled"); |
| 15690 | } |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15691 | |
| 15692 | for_each_intel_crtc(dev, crtc) { |
| 15693 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
| 15694 | |
| 15695 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
| 15696 | if (crtc->base.state->active) { |
| 15697 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); |
| 15698 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); |
| 15699 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15700 | |
| 15701 | /* |
| 15702 | * The initial mode needs to be set in order to keep |
| 15703 | * the atomic core happy. It wants a valid mode if the |
| 15704 | * crtc's enabled, so we do the above call. |
| 15705 | * |
| 15706 | * At this point some state updated by the connectors |
| 15707 | * in their ->detect() callback has not run yet, so |
| 15708 | * no recalculation can be done yet. |
| 15709 | * |
| 15710 | * Even if we could do a recalculation and modeset |
| 15711 | * right now it would cause a double modeset if |
| 15712 | * fbdev or userspace chooses a different initial mode. |
| 15713 | * |
| 15714 | * If that happens, someone indicated they wanted a |
| 15715 | * mode change, which means it's safe to do a full |
| 15716 | * recalculation. |
| 15717 | */ |
| 15718 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15719 | |
| 15720 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
| 15721 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15722 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15723 | |
| 15724 | intel_pipe_config_sanity_check(dev_priv, crtc->config); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15725 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15726 | } |
| 15727 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15728 | /* Scan out the current hw modeset state, |
| 15729 | * and sanitizes it to the current state |
| 15730 | */ |
| 15731 | static void |
| 15732 | intel_modeset_setup_hw_state(struct drm_device *dev) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15733 | { |
| 15734 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15735 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15736 | struct intel_crtc *crtc; |
| 15737 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15738 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15739 | |
| 15740 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15741 | |
| 15742 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15743 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15744 | intel_sanitize_encoder(encoder); |
| 15745 | } |
| 15746 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15747 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15748 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15749 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15750 | intel_dump_pipe_config(crtc, crtc->config, |
| 15751 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15752 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15753 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15754 | intel_modeset_update_connector_atomic_state(dev); |
| 15755 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15756 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15757 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15758 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15759 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15760 | continue; |
| 15761 | |
| 15762 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 15763 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 15764 | pll->funcs.disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15765 | pll->on = false; |
| 15766 | } |
| 15767 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 15768 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15769 | vlv_wm_get_hw_state(dev); |
| 15770 | else if (IS_GEN9(dev)) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15771 | skl_wm_get_hw_state(dev); |
| 15772 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15773 | ilk_wm_get_hw_state(dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15774 | |
| 15775 | for_each_intel_crtc(dev, crtc) { |
| 15776 | unsigned long put_domains; |
| 15777 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 15778 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15779 | if (WARN_ON(put_domains)) |
| 15780 | modeset_put_power_domains(dev_priv, put_domains); |
| 15781 | } |
| 15782 | intel_display_set_init_power(dev_priv, false); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15783 | |
| 15784 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15785 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15786 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15787 | void intel_display_resume(struct drm_device *dev) |
| 15788 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15789 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15790 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15791 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15792 | int ret; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15793 | bool setup = false; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15794 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15795 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15796 | |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 15797 | /* |
| 15798 | * This is a cludge because with real atomic modeset mode_config.mutex |
| 15799 | * won't be taken. Unfortunately some probed state like |
| 15800 | * audio_codec_enable is still protected by mode_config.mutex, so lock |
| 15801 | * it here for now. |
| 15802 | */ |
| 15803 | mutex_lock(&dev->mode_config.mutex); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15804 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15805 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15806 | retry: |
| 15807 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15808 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15809 | if (ret == 0 && !setup) { |
| 15810 | setup = true; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15811 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15812 | intel_modeset_setup_hw_state(dev); |
| 15813 | i915_redisable_vga(dev); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 15814 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 15815 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15816 | if (ret == 0 && state) { |
| 15817 | struct drm_crtc_state *crtc_state; |
| 15818 | struct drm_crtc *crtc; |
| 15819 | int i; |
| 15820 | |
| 15821 | state->acquire_ctx = &ctx; |
| 15822 | |
| 15823 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 15824 | /* |
| 15825 | * Force recalculation even if we restore |
| 15826 | * current state. With fast modeset this may not result |
| 15827 | * in a modeset when the state is compatible. |
| 15828 | */ |
| 15829 | crtc_state->mode_changed = true; |
| 15830 | } |
| 15831 | |
| 15832 | ret = drm_atomic_commit(state); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15833 | } |
| 15834 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15835 | if (ret == -EDEADLK) { |
| 15836 | drm_modeset_backoff(&ctx); |
| 15837 | goto retry; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15838 | } |
| 15839 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15840 | drm_modeset_drop_locks(&ctx); |
| 15841 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 15842 | mutex_unlock(&dev->mode_config.mutex); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15843 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15844 | if (ret) { |
| 15845 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 15846 | drm_atomic_state_free(state); |
| 15847 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15848 | } |
| 15849 | |
| 15850 | void intel_modeset_gem_init(struct drm_device *dev) |
| 15851 | { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15852 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15853 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15854 | int ret; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15855 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15856 | intel_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15857 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 15858 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 15859 | |
| 15860 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15861 | |
| 15862 | /* |
| 15863 | * Make sure any fbs we allocated at startup are properly |
| 15864 | * pinned & fenced. When we do the allocation it's too early |
| 15865 | * for this. |
| 15866 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 15867 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15868 | obj = intel_fb_obj(c->primary->fb); |
| 15869 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15870 | continue; |
| 15871 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15872 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 15873 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, |
| 15874 | c->primary->state->rotation); |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15875 | mutex_unlock(&dev->struct_mutex); |
| 15876 | if (ret) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15877 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 15878 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 15879 | drm_framebuffer_unreference(c->primary->fb); |
| 15880 | c->primary->fb = NULL; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15881 | c->primary->crtc = c->primary->state->crtc = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 15882 | update_state_fb(c->primary); |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15883 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15884 | } |
| 15885 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15886 | |
| 15887 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15888 | } |
| 15889 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15890 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 15891 | { |
| 15892 | struct drm_connector *connector = &intel_connector->base; |
| 15893 | |
| 15894 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 15895 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15896 | } |
| 15897 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15898 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15899 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15900 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 15901 | struct intel_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15902 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15903 | intel_disable_gt_powersave(dev); |
| 15904 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15905 | intel_backlight_unregister(dev); |
| 15906 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15907 | /* |
| 15908 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15909 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15910 | * experience fancy races otherwise. |
| 15911 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15912 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15913 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15914 | /* |
| 15915 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15916 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15917 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 15918 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15919 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15920 | intel_unregister_dsm_handler(); |
| 15921 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 15922 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15923 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15924 | /* flush any delayed tasks or pending work */ |
| 15925 | flush_scheduled_work(); |
| 15926 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 15927 | /* destroy the backlight and sysfs files before encoders/connectors */ |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 15928 | for_each_intel_connector(dev, connector) |
| 15929 | connector->unregister(connector); |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 15930 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15931 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15932 | |
| 15933 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15934 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15935 | intel_cleanup_gt_powersave(dev); |
Daniel Vetter | f594914 | 2016-01-13 11:55:28 +0100 | [diff] [blame] | 15936 | |
| 15937 | intel_teardown_gmbus(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15938 | } |
| 15939 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15940 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 15941 | * Return which encoder is currently attached for connector. |
| 15942 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15943 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15944 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15945 | return &intel_attached_encoder(connector)->base; |
| 15946 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15947 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15948 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 15949 | struct intel_encoder *encoder) |
| 15950 | { |
| 15951 | connector->encoder = encoder; |
| 15952 | drm_mode_connector_attach_encoder(&connector->base, |
| 15953 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15954 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15955 | |
| 15956 | /* |
| 15957 | * set vga decode state - true == enable VGA decode |
| 15958 | */ |
| 15959 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 15960 | { |
| 15961 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 15962 | 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] | 15963 | u16 gmch_ctrl; |
| 15964 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15965 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15966 | DRM_ERROR("failed to read control word\n"); |
| 15967 | return -EIO; |
| 15968 | } |
| 15969 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15970 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15971 | return 0; |
| 15972 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15973 | if (state) |
| 15974 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15975 | else |
| 15976 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15977 | |
| 15978 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15979 | DRM_ERROR("failed to write control word\n"); |
| 15980 | return -EIO; |
| 15981 | } |
| 15982 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15983 | return 0; |
| 15984 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15985 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15986 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15987 | |
| 15988 | u32 power_well_driver; |
| 15989 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15990 | int num_transcoders; |
| 15991 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15992 | struct intel_cursor_error_state { |
| 15993 | u32 control; |
| 15994 | u32 position; |
| 15995 | u32 base; |
| 15996 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15997 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15998 | |
| 15999 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16000 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16001 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16002 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16003 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16004 | |
| 16005 | struct intel_plane_error_state { |
| 16006 | u32 control; |
| 16007 | u32 stride; |
| 16008 | u32 size; |
| 16009 | u32 pos; |
| 16010 | u32 addr; |
| 16011 | u32 surface; |
| 16012 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16013 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16014 | |
| 16015 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16016 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16017 | enum transcoder cpu_transcoder; |
| 16018 | |
| 16019 | u32 conf; |
| 16020 | |
| 16021 | u32 htotal; |
| 16022 | u32 hblank; |
| 16023 | u32 hsync; |
| 16024 | u32 vtotal; |
| 16025 | u32 vblank; |
| 16026 | u32 vsync; |
| 16027 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16028 | }; |
| 16029 | |
| 16030 | struct intel_display_error_state * |
| 16031 | intel_display_capture_error_state(struct drm_device *dev) |
| 16032 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 16033 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16034 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16035 | int transcoders[] = { |
| 16036 | TRANSCODER_A, |
| 16037 | TRANSCODER_B, |
| 16038 | TRANSCODER_C, |
| 16039 | TRANSCODER_EDP, |
| 16040 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16041 | int i; |
| 16042 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16043 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 16044 | return NULL; |
| 16045 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16046 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16047 | if (error == NULL) |
| 16048 | return NULL; |
| 16049 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 16050 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16051 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 16052 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16053 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16054 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16055 | __intel_display_power_is_enabled(dev_priv, |
| 16056 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16057 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16058 | continue; |
| 16059 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16060 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16061 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16062 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16063 | |
| 16064 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16065 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16066 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16067 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16068 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16069 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16070 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 16071 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16072 | if (INTEL_INFO(dev)->gen >= 4) { |
| 16073 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16074 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16075 | } |
| 16076 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16077 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16078 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 16079 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16080 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16081 | } |
| 16082 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16083 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16084 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 16085 | if (HAS_DDI(dev_priv->dev)) |
| 16086 | error->num_transcoders++; /* Account for eDP. */ |
| 16087 | |
| 16088 | for (i = 0; i < error->num_transcoders; i++) { |
| 16089 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16090 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16091 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16092 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16093 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16094 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16095 | continue; |
| 16096 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16097 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16098 | |
| 16099 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16100 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16101 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16102 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16103 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16104 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16105 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16106 | } |
| 16107 | |
| 16108 | return error; |
| 16109 | } |
| 16110 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16111 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16112 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16113 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16114 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16115 | struct drm_device *dev, |
| 16116 | struct intel_display_error_state *error) |
| 16117 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16118 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16119 | int i; |
| 16120 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16121 | if (!error) |
| 16122 | return; |
| 16123 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16124 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 16125 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16126 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16127 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16128 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16129 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16130 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16131 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16132 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16133 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16134 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16135 | err_printf(m, "Plane [%d]:\n", i); |
| 16136 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16137 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16138 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16139 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16140 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16141 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 16142 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16143 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16144 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16145 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16146 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16147 | } |
| 16148 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16149 | err_printf(m, "Cursor [%d]:\n", i); |
| 16150 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16151 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16152 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16153 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16154 | |
| 16155 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16156 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16157 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16158 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16159 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16160 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16161 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16162 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16163 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16164 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16165 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16166 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16167 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16168 | } |