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" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 39 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 40 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 42 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 43 | #include <drm/drm_dp_helper.h> |
| 44 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 45 | #include <drm/drm_plane_helper.h> |
| 46 | #include <drm/drm_rect.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 47 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 48 | #include <linux/reservation.h> |
| 49 | #include <linux/dma-buf.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 50 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 51 | static bool is_mmio_work(struct intel_flip_work *work) |
| 52 | { |
| 53 | return work->mmio_work.func; |
| 54 | } |
| 55 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 56 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 57 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 58 | DRM_FORMAT_C8, |
| 59 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 60 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 61 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 65 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 66 | DRM_FORMAT_C8, |
| 67 | DRM_FORMAT_RGB565, |
| 68 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 69 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 70 | DRM_FORMAT_XRGB2101010, |
| 71 | DRM_FORMAT_XBGR2101010, |
| 72 | }; |
| 73 | |
| 74 | static const uint32_t skl_primary_formats[] = { |
| 75 | DRM_FORMAT_C8, |
| 76 | DRM_FORMAT_RGB565, |
| 77 | DRM_FORMAT_XRGB8888, |
| 78 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 79 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 80 | DRM_FORMAT_ABGR8888, |
| 81 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 82 | DRM_FORMAT_XBGR2101010, |
Kumar, Mahesh | ea916ea | 2015-09-03 16:17:09 +0530 | [diff] [blame] | 83 | DRM_FORMAT_YUYV, |
| 84 | DRM_FORMAT_YVYU, |
| 85 | DRM_FORMAT_UYVY, |
| 86 | DRM_FORMAT_VYUY, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 89 | /* Cursor formats */ |
| 90 | static const uint32_t intel_cursor_formats[] = { |
| 91 | DRM_FORMAT_ARGB8888, |
| 92 | }; |
| 93 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 94 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 95 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 96 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 97 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 98 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 99 | static int intel_framebuffer_init(struct drm_device *dev, |
| 100 | struct intel_framebuffer *ifb, |
| 101 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 102 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 103 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 104 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 105 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 106 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 107 | struct intel_link_m_n *m_n, |
| 108 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 109 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 110 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 111 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 112 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 113 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 114 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 115 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 116 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 117 | 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] | 118 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 119 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 120 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
| 121 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); |
| 122 | static void ironlake_pfit_enable(struct intel_crtc *crtc); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 123 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 124 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Ville Syrjälä | 4e5ca60 | 2016-05-11 22:44:44 +0300 | [diff] [blame] | 125 | static int ilk_max_pixel_rate(struct drm_atomic_state *state); |
Ville Syrjälä | d1b32c3 | 2016-05-13 23:41:40 +0300 | [diff] [blame] | 126 | static int broxton_calc_cdclk(int max_pixclk); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 127 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 128 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 129 | struct { |
| 130 | int min, max; |
| 131 | } dot, vco, n, m, m1, m2, p, p1; |
| 132 | |
| 133 | struct { |
| 134 | int dot_limit; |
| 135 | int p2_slow, p2_fast; |
| 136 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 137 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 138 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 139 | /* returns HPLL frequency in kHz */ |
| 140 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
| 141 | { |
| 142 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 143 | |
| 144 | /* Obtain SKU information */ |
| 145 | mutex_lock(&dev_priv->sb_lock); |
| 146 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 147 | CCK_FUSE_HPLL_FREQ_MASK; |
| 148 | mutex_unlock(&dev_priv->sb_lock); |
| 149 | |
| 150 | return vco_freq[hpll_freq] * 1000; |
| 151 | } |
| 152 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 153 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 154 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 155 | { |
| 156 | u32 val; |
| 157 | int divider; |
| 158 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 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 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 169 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 170 | } |
| 171 | |
| 172 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 173 | const char *name, u32 reg) |
| 174 | { |
| 175 | if (dev_priv->hpll_freq == 0) |
| 176 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 177 | |
| 178 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 179 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 180 | } |
| 181 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 182 | static int |
| 183 | intel_pch_rawclk(struct drm_i915_private *dev_priv) |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 184 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 185 | return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000; |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 188 | static int |
| 189 | intel_vlv_hrawclk(struct drm_i915_private *dev_priv) |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 190 | { |
Ville Syrjälä | 19ab4ed | 2016-04-27 17:43:22 +0300 | [diff] [blame] | 191 | /* RAWCLK_FREQ_VLV register updated from power well code */ |
Ville Syrjälä | 35d38d1 | 2016-03-02 17:22:16 +0200 | [diff] [blame] | 192 | return vlv_get_cck_clock_hpll(dev_priv, "hrawclk", |
| 193 | CCK_DISPLAY_REF_CLOCK_CONTROL); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int |
| 197 | intel_g4x_hrawclk(struct drm_i915_private *dev_priv) |
| 198 | { |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 199 | uint32_t clkcfg; |
| 200 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 201 | /* hrawclock is 1/4 the FSB frequency */ |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 202 | clkcfg = I915_READ(CLKCFG); |
| 203 | switch (clkcfg & CLKCFG_FSB_MASK) { |
| 204 | case CLKCFG_FSB_400: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 205 | return 100000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 206 | case CLKCFG_FSB_533: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 207 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 208 | case CLKCFG_FSB_667: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 209 | return 166667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 210 | case CLKCFG_FSB_800: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 211 | return 200000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 212 | case CLKCFG_FSB_1067: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 213 | return 266667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 214 | case CLKCFG_FSB_1333: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 215 | return 333333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 216 | /* these two are just a guess; one of them might be right */ |
| 217 | case CLKCFG_FSB_1600: |
| 218 | case CLKCFG_FSB_1600_ALT: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 219 | return 400000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 220 | default: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 221 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
Ville Syrjälä | 19ab4ed | 2016-04-27 17:43:22 +0300 | [diff] [blame] | 225 | void intel_update_rawclk(struct drm_i915_private *dev_priv) |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 226 | { |
| 227 | if (HAS_PCH_SPLIT(dev_priv)) |
| 228 | dev_priv->rawclk_freq = intel_pch_rawclk(dev_priv); |
| 229 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 230 | dev_priv->rawclk_freq = intel_vlv_hrawclk(dev_priv); |
| 231 | else if (IS_G4X(dev_priv) || IS_PINEVIEW(dev_priv)) |
| 232 | dev_priv->rawclk_freq = intel_g4x_hrawclk(dev_priv); |
| 233 | else |
| 234 | return; /* no rawclk on other platforms, or no need to know it */ |
| 235 | |
| 236 | DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv->rawclk_freq); |
| 237 | } |
| 238 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 239 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 240 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 241 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 242 | return; |
| 243 | |
| 244 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 245 | CCK_CZ_CLOCK_CONTROL); |
| 246 | |
| 247 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 248 | } |
| 249 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 250 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 251 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 252 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 253 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 254 | if (HAS_DDI(dev_priv)) |
| 255 | return pipe_config->port_clock; /* SPLL */ |
| 256 | else if (IS_GEN5(dev_priv)) |
| 257 | 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] | 258 | else |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 259 | return 270000; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 262 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 263 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 264 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 265 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 266 | .m = { .min = 96, .max = 140 }, |
| 267 | .m1 = { .min = 18, .max = 26 }, |
| 268 | .m2 = { .min = 6, .max = 16 }, |
| 269 | .p = { .min = 4, .max = 128 }, |
| 270 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 271 | .p2 = { .dot_limit = 165000, |
| 272 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 275 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 276 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 277 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 278 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 279 | .m = { .min = 96, .max = 140 }, |
| 280 | .m1 = { .min = 18, .max = 26 }, |
| 281 | .m2 = { .min = 6, .max = 16 }, |
| 282 | .p = { .min = 4, .max = 128 }, |
| 283 | .p1 = { .min = 2, .max = 33 }, |
| 284 | .p2 = { .dot_limit = 165000, |
| 285 | .p2_slow = 4, .p2_fast = 4 }, |
| 286 | }; |
| 287 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 288 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 289 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 290 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 291 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 292 | .m = { .min = 96, .max = 140 }, |
| 293 | .m1 = { .min = 18, .max = 26 }, |
| 294 | .m2 = { .min = 6, .max = 16 }, |
| 295 | .p = { .min = 4, .max = 128 }, |
| 296 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 297 | .p2 = { .dot_limit = 165000, |
| 298 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 299 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 300 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 301 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 302 | .dot = { .min = 20000, .max = 400000 }, |
| 303 | .vco = { .min = 1400000, .max = 2800000 }, |
| 304 | .n = { .min = 1, .max = 6 }, |
| 305 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 306 | .m1 = { .min = 8, .max = 18 }, |
| 307 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 308 | .p = { .min = 5, .max = 80 }, |
| 309 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 310 | .p2 = { .dot_limit = 200000, |
| 311 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 314 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 315 | .dot = { .min = 20000, .max = 400000 }, |
| 316 | .vco = { .min = 1400000, .max = 2800000 }, |
| 317 | .n = { .min = 1, .max = 6 }, |
| 318 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 319 | .m1 = { .min = 8, .max = 18 }, |
| 320 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 321 | .p = { .min = 7, .max = 98 }, |
| 322 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 323 | .p2 = { .dot_limit = 112000, |
| 324 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 327 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 328 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 329 | .dot = { .min = 25000, .max = 270000 }, |
| 330 | .vco = { .min = 1750000, .max = 3500000}, |
| 331 | .n = { .min = 1, .max = 4 }, |
| 332 | .m = { .min = 104, .max = 138 }, |
| 333 | .m1 = { .min = 17, .max = 23 }, |
| 334 | .m2 = { .min = 5, .max = 11 }, |
| 335 | .p = { .min = 10, .max = 30 }, |
| 336 | .p1 = { .min = 1, .max = 3}, |
| 337 | .p2 = { .dot_limit = 270000, |
| 338 | .p2_slow = 10, |
| 339 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 340 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 341 | }; |
| 342 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 343 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 344 | .dot = { .min = 22000, .max = 400000 }, |
| 345 | .vco = { .min = 1750000, .max = 3500000}, |
| 346 | .n = { .min = 1, .max = 4 }, |
| 347 | .m = { .min = 104, .max = 138 }, |
| 348 | .m1 = { .min = 16, .max = 23 }, |
| 349 | .m2 = { .min = 5, .max = 11 }, |
| 350 | .p = { .min = 5, .max = 80 }, |
| 351 | .p1 = { .min = 1, .max = 8}, |
| 352 | .p2 = { .dot_limit = 165000, |
| 353 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 354 | }; |
| 355 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 356 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 357 | .dot = { .min = 20000, .max = 115000 }, |
| 358 | .vco = { .min = 1750000, .max = 3500000 }, |
| 359 | .n = { .min = 1, .max = 3 }, |
| 360 | .m = { .min = 104, .max = 138 }, |
| 361 | .m1 = { .min = 17, .max = 23 }, |
| 362 | .m2 = { .min = 5, .max = 11 }, |
| 363 | .p = { .min = 28, .max = 112 }, |
| 364 | .p1 = { .min = 2, .max = 8 }, |
| 365 | .p2 = { .dot_limit = 0, |
| 366 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 367 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 368 | }; |
| 369 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 370 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 371 | .dot = { .min = 80000, .max = 224000 }, |
| 372 | .vco = { .min = 1750000, .max = 3500000 }, |
| 373 | .n = { .min = 1, .max = 3 }, |
| 374 | .m = { .min = 104, .max = 138 }, |
| 375 | .m1 = { .min = 17, .max = 23 }, |
| 376 | .m2 = { .min = 5, .max = 11 }, |
| 377 | .p = { .min = 14, .max = 42 }, |
| 378 | .p1 = { .min = 2, .max = 6 }, |
| 379 | .p2 = { .dot_limit = 0, |
| 380 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 381 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 382 | }; |
| 383 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 384 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 385 | .dot = { .min = 20000, .max = 400000}, |
| 386 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 387 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 388 | .n = { .min = 3, .max = 6 }, |
| 389 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 390 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 391 | .m1 = { .min = 0, .max = 0 }, |
| 392 | .m2 = { .min = 0, .max = 254 }, |
| 393 | .p = { .min = 5, .max = 80 }, |
| 394 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 395 | .p2 = { .dot_limit = 200000, |
| 396 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 399 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 400 | .dot = { .min = 20000, .max = 400000 }, |
| 401 | .vco = { .min = 1700000, .max = 3500000 }, |
| 402 | .n = { .min = 3, .max = 6 }, |
| 403 | .m = { .min = 2, .max = 256 }, |
| 404 | .m1 = { .min = 0, .max = 0 }, |
| 405 | .m2 = { .min = 0, .max = 254 }, |
| 406 | .p = { .min = 7, .max = 112 }, |
| 407 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 408 | .p2 = { .dot_limit = 112000, |
| 409 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 412 | /* Ironlake / Sandybridge |
| 413 | * |
| 414 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 415 | * the range value for them is (actual_value - 2). |
| 416 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 417 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 418 | .dot = { .min = 25000, .max = 350000 }, |
| 419 | .vco = { .min = 1760000, .max = 3510000 }, |
| 420 | .n = { .min = 1, .max = 5 }, |
| 421 | .m = { .min = 79, .max = 127 }, |
| 422 | .m1 = { .min = 12, .max = 22 }, |
| 423 | .m2 = { .min = 5, .max = 9 }, |
| 424 | .p = { .min = 5, .max = 80 }, |
| 425 | .p1 = { .min = 1, .max = 8 }, |
| 426 | .p2 = { .dot_limit = 225000, |
| 427 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 430 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 431 | .dot = { .min = 25000, .max = 350000 }, |
| 432 | .vco = { .min = 1760000, .max = 3510000 }, |
| 433 | .n = { .min = 1, .max = 3 }, |
| 434 | .m = { .min = 79, .max = 118 }, |
| 435 | .m1 = { .min = 12, .max = 22 }, |
| 436 | .m2 = { .min = 5, .max = 9 }, |
| 437 | .p = { .min = 28, .max = 112 }, |
| 438 | .p1 = { .min = 2, .max = 8 }, |
| 439 | .p2 = { .dot_limit = 225000, |
| 440 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 441 | }; |
| 442 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 443 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 444 | .dot = { .min = 25000, .max = 350000 }, |
| 445 | .vco = { .min = 1760000, .max = 3510000 }, |
| 446 | .n = { .min = 1, .max = 3 }, |
| 447 | .m = { .min = 79, .max = 127 }, |
| 448 | .m1 = { .min = 12, .max = 22 }, |
| 449 | .m2 = { .min = 5, .max = 9 }, |
| 450 | .p = { .min = 14, .max = 56 }, |
| 451 | .p1 = { .min = 2, .max = 8 }, |
| 452 | .p2 = { .dot_limit = 225000, |
| 453 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 454 | }; |
| 455 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 456 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 457 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 458 | .dot = { .min = 25000, .max = 350000 }, |
| 459 | .vco = { .min = 1760000, .max = 3510000 }, |
| 460 | .n = { .min = 1, .max = 2 }, |
| 461 | .m = { .min = 79, .max = 126 }, |
| 462 | .m1 = { .min = 12, .max = 22 }, |
| 463 | .m2 = { .min = 5, .max = 9 }, |
| 464 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 465 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 466 | .p2 = { .dot_limit = 225000, |
| 467 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 468 | }; |
| 469 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 470 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 471 | .dot = { .min = 25000, .max = 350000 }, |
| 472 | .vco = { .min = 1760000, .max = 3510000 }, |
| 473 | .n = { .min = 1, .max = 3 }, |
| 474 | .m = { .min = 79, .max = 126 }, |
| 475 | .m1 = { .min = 12, .max = 22 }, |
| 476 | .m2 = { .min = 5, .max = 9 }, |
| 477 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 478 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 479 | .p2 = { .dot_limit = 225000, |
| 480 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 481 | }; |
| 482 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 483 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 484 | /* |
| 485 | * These are the data rate limits (measured in fast clocks) |
| 486 | * since those are the strictest limits we have. The fast |
| 487 | * clock and actual rate limits are more relaxed, so checking |
| 488 | * them would make no difference. |
| 489 | */ |
| 490 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 491 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 492 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 493 | .m1 = { .min = 2, .max = 3 }, |
| 494 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 495 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 496 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 497 | }; |
| 498 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 499 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 500 | /* |
| 501 | * These are the data rate limits (measured in fast clocks) |
| 502 | * since those are the strictest limits we have. The fast |
| 503 | * clock and actual rate limits are more relaxed, so checking |
| 504 | * them would make no difference. |
| 505 | */ |
| 506 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 507 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 508 | .n = { .min = 1, .max = 1 }, |
| 509 | .m1 = { .min = 2, .max = 2 }, |
| 510 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 511 | .p1 = { .min = 2, .max = 4 }, |
| 512 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 513 | }; |
| 514 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 515 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 516 | /* FIXME: find real dot limits */ |
| 517 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 518 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 519 | .n = { .min = 1, .max = 1 }, |
| 520 | .m1 = { .min = 2, .max = 2 }, |
| 521 | /* FIXME: find real m2 limits */ |
| 522 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 523 | .p1 = { .min = 2, .max = 4 }, |
| 524 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 525 | }; |
| 526 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 527 | static bool |
| 528 | needs_modeset(struct drm_crtc_state *state) |
| 529 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 530 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 533 | /** |
| 534 | * Returns whether any output on the specified pipe is of the specified type |
| 535 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 536 | 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] | 537 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 538 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 539 | struct intel_encoder *encoder; |
| 540 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 541 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 542 | if (encoder->type == type) |
| 543 | return true; |
| 544 | |
| 545 | return false; |
| 546 | } |
| 547 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 548 | /** |
| 549 | * Returns whether any output on the specified pipe will have the specified |
| 550 | * type after a staged modeset is complete, i.e., the same as |
| 551 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 552 | * encoder->crtc. |
| 553 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 554 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 555 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 556 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 557 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 558 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 559 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 560 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 561 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 562 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 563 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 564 | if (connector_state->crtc != crtc_state->base.crtc) |
| 565 | continue; |
| 566 | |
| 567 | num_connectors++; |
| 568 | |
| 569 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 570 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 571 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 575 | |
| 576 | return false; |
| 577 | } |
| 578 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 579 | /* |
| 580 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 581 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 582 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 583 | * The helpers' return value is the rate of the clock that is fed to the |
| 584 | * display engine's pipe which can be the above fast dot clock rate or a |
| 585 | * divided-down version of it. |
| 586 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 587 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 588 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 590 | clock->m = clock->m2 + 2; |
| 591 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 592 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 593 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 594 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 595 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 596 | |
| 597 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 598 | } |
| 599 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 600 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 601 | { |
| 602 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 603 | } |
| 604 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 605 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 606 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 607 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 608 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 609 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 610 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 611 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 612 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 613 | |
| 614 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 615 | } |
| 616 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 617 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 618 | { |
| 619 | clock->m = clock->m1 * clock->m2; |
| 620 | clock->p = clock->p1 * clock->p2; |
| 621 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 622 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 623 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 624 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 625 | |
| 626 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 627 | } |
| 628 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 629 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 630 | { |
| 631 | clock->m = clock->m1 * clock->m2; |
| 632 | clock->p = clock->p1 * clock->p2; |
| 633 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 634 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 635 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 636 | clock->n << 22); |
| 637 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 638 | |
| 639 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 640 | } |
| 641 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 642 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | /** |
| 644 | * Returns whether the given set of divisors are valid for a given refclk with |
| 645 | * the given connectors. |
| 646 | */ |
| 647 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 648 | static bool intel_PLL_is_valid(struct drm_device *dev, |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 649 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 650 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 651 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 652 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 653 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 654 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 655 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 656 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 657 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 659 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 660 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 661 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && |
| 662 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 663 | if (clock->m1 <= clock->m2) |
| 664 | INTELPllInvalid("m1 <= m2\n"); |
| 665 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 666 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 667 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 668 | INTELPllInvalid("p out of range\n"); |
| 669 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 670 | INTELPllInvalid("m out of range\n"); |
| 671 | } |
| 672 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 673 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 674 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 675 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 676 | * connector, etc., rather than just a single range. |
| 677 | */ |
| 678 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 679 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 680 | |
| 681 | return true; |
| 682 | } |
| 683 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 684 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 685 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 686 | const struct intel_crtc_state *crtc_state, |
| 687 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 688 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 689 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 690 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 691 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 692 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 693 | * For LVDS just rely on its current settings for dual-channel. |
| 694 | * We haven't figured out how to reliably set up different |
| 695 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 696 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 697 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 698 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 699 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 700 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 701 | } else { |
| 702 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 703 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 704 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 705 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 706 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 707 | } |
| 708 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 709 | /* |
| 710 | * Returns a set of divisors for the desired target clock with the given |
| 711 | * refclk, or FALSE. The returned values represent the clock equation: |
| 712 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 713 | * |
| 714 | * Target and reference clocks are specified in kHz. |
| 715 | * |
| 716 | * If match_clock is provided, then best_clock P divider must match the P |
| 717 | * divider from @match_clock used for LVDS downclocking. |
| 718 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 719 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 720 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 721 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 722 | int target, int refclk, struct dpll *match_clock, |
| 723 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 724 | { |
| 725 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 726 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 727 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 728 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 729 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 730 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 731 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 732 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 733 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 734 | clock.m1++) { |
| 735 | for (clock.m2 = limit->m2.min; |
| 736 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 737 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 738 | break; |
| 739 | for (clock.n = limit->n.min; |
| 740 | clock.n <= limit->n.max; clock.n++) { |
| 741 | for (clock.p1 = limit->p1.min; |
| 742 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 743 | int this_err; |
| 744 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 745 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 746 | if (!intel_PLL_is_valid(dev, limit, |
| 747 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 748 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 749 | if (match_clock && |
| 750 | clock.p != match_clock->p) |
| 751 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 752 | |
| 753 | this_err = abs(clock.dot - target); |
| 754 | if (this_err < err) { |
| 755 | *best_clock = clock; |
| 756 | err = this_err; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | return (err != target); |
| 764 | } |
| 765 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 766 | /* |
| 767 | * Returns a set of divisors for the desired target clock with the given |
| 768 | * refclk, or FALSE. The returned values represent the clock equation: |
| 769 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 770 | * |
| 771 | * Target and reference clocks are specified in kHz. |
| 772 | * |
| 773 | * If match_clock is provided, then best_clock P divider must match the P |
| 774 | * divider from @match_clock used for LVDS downclocking. |
| 775 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 776 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 777 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 778 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 779 | int target, int refclk, struct dpll *match_clock, |
| 780 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 781 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 782 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 783 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 784 | int err = target; |
| 785 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 786 | memset(best_clock, 0, sizeof(*best_clock)); |
| 787 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 788 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 789 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 790 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 791 | clock.m1++) { |
| 792 | for (clock.m2 = limit->m2.min; |
| 793 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 794 | for (clock.n = limit->n.min; |
| 795 | clock.n <= limit->n.max; clock.n++) { |
| 796 | for (clock.p1 = limit->p1.min; |
| 797 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 798 | int this_err; |
| 799 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 800 | pnv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 801 | if (!intel_PLL_is_valid(dev, limit, |
| 802 | &clock)) |
| 803 | continue; |
| 804 | if (match_clock && |
| 805 | clock.p != match_clock->p) |
| 806 | continue; |
| 807 | |
| 808 | this_err = abs(clock.dot - target); |
| 809 | if (this_err < err) { |
| 810 | *best_clock = clock; |
| 811 | err = this_err; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return (err != target); |
| 819 | } |
| 820 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 821 | /* |
| 822 | * Returns a set of divisors for the desired target clock with the given |
| 823 | * refclk, or FALSE. The returned values represent the clock equation: |
| 824 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 825 | * |
| 826 | * Target and reference clocks are specified in kHz. |
| 827 | * |
| 828 | * If match_clock is provided, then best_clock P divider must match the P |
| 829 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 830 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 831 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 832 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 833 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 834 | int target, int refclk, struct dpll *match_clock, |
| 835 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 836 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 837 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 838 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 839 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 840 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 841 | /* approximately equals target * 0.00585 */ |
| 842 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 843 | |
| 844 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 845 | |
| 846 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 847 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 848 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 849 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 850 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 851 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 852 | for (clock.m1 = limit->m1.max; |
| 853 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 854 | for (clock.m2 = limit->m2.max; |
| 855 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 856 | for (clock.p1 = limit->p1.max; |
| 857 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 858 | int this_err; |
| 859 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 860 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 861 | if (!intel_PLL_is_valid(dev, limit, |
| 862 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 863 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 864 | |
| 865 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 866 | if (this_err < err_most) { |
| 867 | *best_clock = clock; |
| 868 | err_most = this_err; |
| 869 | max_n = clock.n; |
| 870 | found = true; |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 876 | return found; |
| 877 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 878 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 879 | /* |
| 880 | * Check if the calculated PLL configuration is more optimal compared to the |
| 881 | * best configuration and error found so far. Return the calculated error. |
| 882 | */ |
| 883 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 884 | const struct dpll *calculated_clock, |
| 885 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 886 | unsigned int best_error_ppm, |
| 887 | unsigned int *error_ppm) |
| 888 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 889 | /* |
| 890 | * For CHV ignore the error and consider only the P value. |
| 891 | * Prefer a bigger P value based on HW requirements. |
| 892 | */ |
| 893 | if (IS_CHERRYVIEW(dev)) { |
| 894 | *error_ppm = 0; |
| 895 | |
| 896 | return calculated_clock->p > best_clock->p; |
| 897 | } |
| 898 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 899 | if (WARN_ON_ONCE(!target_freq)) |
| 900 | return false; |
| 901 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 902 | *error_ppm = div_u64(1000000ULL * |
| 903 | abs(target_freq - calculated_clock->dot), |
| 904 | target_freq); |
| 905 | /* |
| 906 | * Prefer a better P value over a better (smaller) error if the error |
| 907 | * is small. Ensure this preference for future configurations too by |
| 908 | * setting the error to 0. |
| 909 | */ |
| 910 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 911 | *error_ppm = 0; |
| 912 | |
| 913 | return true; |
| 914 | } |
| 915 | |
| 916 | return *error_ppm + 10 < best_error_ppm; |
| 917 | } |
| 918 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 919 | /* |
| 920 | * Returns a set of divisors for the desired target clock with the given |
| 921 | * refclk, or FALSE. The returned values represent the clock equation: |
| 922 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 923 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 924 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 925 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 926 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 927 | int target, int refclk, struct dpll *match_clock, |
| 928 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 929 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 930 | 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] | 931 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 932 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 933 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 934 | /* min update 19.2 MHz */ |
| 935 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 936 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 937 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 938 | target *= 5; /* fast clock */ |
| 939 | |
| 940 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 941 | |
| 942 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 943 | 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] | 944 | 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] | 945 | 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] | 946 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 947 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 948 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 949 | 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] | 950 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 951 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 952 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 953 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 954 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 955 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 956 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 957 | if (!intel_PLL_is_valid(dev, limit, |
| 958 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 959 | continue; |
| 960 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 961 | if (!vlv_PLL_is_optimal(dev, target, |
| 962 | &clock, |
| 963 | best_clock, |
| 964 | bestppm, &ppm)) |
| 965 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 966 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 967 | *best_clock = clock; |
| 968 | bestppm = ppm; |
| 969 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | } |
| 973 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 974 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 975 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 976 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 977 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 978 | /* |
| 979 | * Returns a set of divisors for the desired target clock with the given |
| 980 | * refclk, or FALSE. The returned values represent the clock equation: |
| 981 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 982 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 983 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 984 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 985 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 986 | int target, int refclk, struct dpll *match_clock, |
| 987 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 988 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 989 | 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] | 990 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 991 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 992 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 993 | uint64_t m2; |
| 994 | int found = false; |
| 995 | |
| 996 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 997 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 998 | |
| 999 | /* |
| 1000 | * Based on hardware doc, the n always set to 1, and m1 always |
| 1001 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 1002 | * revisit this because n may not 1 anymore. |
| 1003 | */ |
| 1004 | clock.n = 1, clock.m1 = 2; |
| 1005 | target *= 5; /* fast clock */ |
| 1006 | |
| 1007 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 1008 | for (clock.p2 = limit->p2.p2_fast; |
| 1009 | clock.p2 >= limit->p2.p2_slow; |
| 1010 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1011 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1012 | |
| 1013 | clock.p = clock.p1 * clock.p2; |
| 1014 | |
| 1015 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 1016 | clock.n) << 22, refclk * clock.m1); |
| 1017 | |
| 1018 | if (m2 > INT_MAX/clock.m1) |
| 1019 | continue; |
| 1020 | |
| 1021 | clock.m2 = m2; |
| 1022 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 1023 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1024 | |
| 1025 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 1026 | continue; |
| 1027 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1028 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 1029 | best_error_ppm, &error_ppm)) |
| 1030 | continue; |
| 1031 | |
| 1032 | *best_clock = clock; |
| 1033 | best_error_ppm = error_ppm; |
| 1034 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | return found; |
| 1039 | } |
| 1040 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1041 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 1042 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1043 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1044 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 1045 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1046 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1047 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1048 | target_clock, refclk, NULL, best_clock); |
| 1049 | } |
| 1050 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1051 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 1052 | { |
| 1053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1054 | |
| 1055 | /* Be paranoid as we can arrive here with only partial |
| 1056 | * state retrieved from the hardware during setup. |
| 1057 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1058 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1059 | * as Haswell has gained clock readout/fastboot support. |
| 1060 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 1061 | * 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] | 1062 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1063 | * |
| 1064 | * FIXME: The intel_crtc->active here should be switched to |
| 1065 | * crtc->state->active once we have proper CRTC states wired up |
| 1066 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1067 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1068 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1069 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1070 | } |
| 1071 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1072 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1073 | enum pipe pipe) |
| 1074 | { |
| 1075 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1076 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1077 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1078 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1079 | } |
| 1080 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1081 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 1082 | { |
| 1083 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1084 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1085 | u32 line1, line2; |
| 1086 | u32 line_mask; |
| 1087 | |
| 1088 | if (IS_GEN2(dev)) |
| 1089 | line_mask = DSL_LINEMASK_GEN2; |
| 1090 | else |
| 1091 | line_mask = DSL_LINEMASK_GEN3; |
| 1092 | |
| 1093 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1094 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1095 | line2 = I915_READ(reg) & line_mask; |
| 1096 | |
| 1097 | return line1 == line2; |
| 1098 | } |
| 1099 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1100 | /* |
| 1101 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1102 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1103 | * |
| 1104 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1105 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1106 | * see an interrupt when the pipe is disabled. |
| 1107 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1108 | * On Gen4 and above: |
| 1109 | * wait for the pipe register state bit to turn off |
| 1110 | * |
| 1111 | * Otherwise: |
| 1112 | * wait for the display line value to settle (it usually |
| 1113 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1114 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1115 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1116 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1117 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1118 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1119 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1120 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1121 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1122 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1123 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1124 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1125 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1126 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1127 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1128 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1129 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1130 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1131 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1132 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1133 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1134 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1137 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1138 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1139 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1140 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1141 | u32 val; |
| 1142 | bool cur_state; |
| 1143 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1144 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1145 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1146 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1147 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1148 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1149 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1150 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1151 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1152 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1153 | { |
| 1154 | u32 val; |
| 1155 | bool cur_state; |
| 1156 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1157 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1158 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1159 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1160 | |
| 1161 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1162 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1163 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1164 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1165 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1166 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1167 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1168 | enum pipe pipe, bool state) |
| 1169 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1170 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1171 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1172 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1173 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1174 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1175 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1176 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1177 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1178 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1179 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1180 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1181 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1182 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1183 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1184 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1185 | } |
| 1186 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1187 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1188 | |
| 1189 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1190 | enum pipe pipe, bool state) |
| 1191 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1192 | u32 val; |
| 1193 | bool cur_state; |
| 1194 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1195 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1196 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1197 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1198 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1199 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1200 | } |
| 1201 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1202 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1203 | |
| 1204 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1205 | enum pipe pipe) |
| 1206 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1207 | u32 val; |
| 1208 | |
| 1209 | /* ILK FDI PLL is always enabled */ |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 1210 | if (IS_GEN5(dev_priv)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1211 | return; |
| 1212 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1213 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1214 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1215 | return; |
| 1216 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1217 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1218 | 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] | 1219 | } |
| 1220 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1221 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1222 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1223 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1224 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1225 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1226 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1227 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1228 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1229 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1230 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1231 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1234 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1235 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1236 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1237 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1238 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1239 | u32 val; |
| 1240 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1241 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1242 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1243 | if (WARN_ON(HAS_DDI(dev))) |
| 1244 | return; |
| 1245 | |
| 1246 | if (HAS_PCH_SPLIT(dev)) { |
| 1247 | u32 port_sel; |
| 1248 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1249 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1250 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1251 | |
| 1252 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1253 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1254 | panel_pipe = PIPE_B; |
| 1255 | /* XXX: else fix for eDP */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1256 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1257 | /* presumably write lock depends on pipe, not port select */ |
| 1258 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1259 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1260 | } else { |
| 1261 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1262 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1263 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | val = I915_READ(pp_reg); |
| 1267 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1268 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1269 | locked = false; |
| 1270 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1271 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1272 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1273 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1276 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1277 | enum pipe pipe, bool state) |
| 1278 | { |
| 1279 | struct drm_device *dev = dev_priv->dev; |
| 1280 | bool cur_state; |
| 1281 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1282 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 1283 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1284 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1285 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1286 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1287 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1288 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1289 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1290 | } |
| 1291 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1292 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1293 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1294 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1295 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1296 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1297 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1298 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1299 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1300 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1301 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1302 | /* if we need the pipe quirk it must be always on */ |
| 1303 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1304 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1305 | state = true; |
| 1306 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1307 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1308 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1309 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1310 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1311 | |
| 1312 | intel_display_power_put(dev_priv, power_domain); |
| 1313 | } else { |
| 1314 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1315 | } |
| 1316 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1317 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1318 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1319 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1322 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1323 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1324 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1325 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1326 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1327 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1328 | val = I915_READ(DSPCNTR(plane)); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1329 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1330 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1331 | "plane %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1332 | plane_name(plane), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1335 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1336 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1337 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1338 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1339 | enum pipe pipe) |
| 1340 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1341 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1342 | int i; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1343 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1344 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1345 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1346 | u32 val = I915_READ(DSPCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1347 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1348 | "plane %c assertion failure, should be disabled but not\n", |
| 1349 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1350 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1351 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1352 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1353 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1354 | for_each_pipe(dev_priv, i) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1355 | u32 val = I915_READ(DSPCNTR(i)); |
| 1356 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1357 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1358 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1359 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1360 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1364 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1365 | enum pipe pipe) |
| 1366 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1367 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1368 | int sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1369 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1370 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1371 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1372 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1373 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1374 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1375 | sprite, pipe_name(pipe)); |
| 1376 | } |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1377 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
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(SPCNTR(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1380 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1381 | "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] | 1382 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1383 | } |
| 1384 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1385 | u32 val = I915_READ(SPRCTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1386 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1387 | "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] | 1388 | plane_name(pipe), pipe_name(pipe)); |
| 1389 | } else if (INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1390 | u32 val = I915_READ(DVSCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1391 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1392 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1393 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1397 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1398 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1399 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1400 | drm_crtc_vblank_put(crtc); |
| 1401 | } |
| 1402 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1403 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1404 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1405 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1406 | u32 val; |
| 1407 | bool enabled; |
| 1408 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1409 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1410 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1411 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1412 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1413 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1416 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1417 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1418 | { |
| 1419 | if ((val & DP_PORT_EN) == 0) |
| 1420 | return false; |
| 1421 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1422 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1423 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1424 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1425 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1426 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1427 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1428 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1429 | } else { |
| 1430 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1431 | return false; |
| 1432 | } |
| 1433 | return true; |
| 1434 | } |
| 1435 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1436 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1437 | enum pipe pipe, u32 val) |
| 1438 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1439 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1440 | return false; |
| 1441 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1442 | if (HAS_PCH_CPT(dev_priv)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1443 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1444 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1445 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1446 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1447 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1448 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1449 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | return true; |
| 1453 | } |
| 1454 | |
| 1455 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1456 | enum pipe pipe, u32 val) |
| 1457 | { |
| 1458 | if ((val & LVDS_PORT_EN) == 0) |
| 1459 | return false; |
| 1460 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1461 | if (HAS_PCH_CPT(dev_priv)) { |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1462 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1463 | return false; |
| 1464 | } else { |
| 1465 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1466 | return false; |
| 1467 | } |
| 1468 | return true; |
| 1469 | } |
| 1470 | |
| 1471 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1472 | enum pipe pipe, u32 val) |
| 1473 | { |
| 1474 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1475 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1476 | if (HAS_PCH_CPT(dev_priv)) { |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1477 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1478 | return false; |
| 1479 | } else { |
| 1480 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1481 | return false; |
| 1482 | } |
| 1483 | return true; |
| 1484 | } |
| 1485 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1486 | 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] | 1487 | enum pipe pipe, i915_reg_t reg, |
| 1488 | u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1489 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1490 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1491 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1492 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1493 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1494 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1495 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1496 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1497 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1501 | enum pipe pipe, i915_reg_t reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1502 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1503 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1504 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1505 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1506 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1507 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1508 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1509 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1510 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1514 | enum pipe pipe) |
| 1515 | { |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1516 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1517 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1518 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1519 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1520 | 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] | 1521 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1522 | val = I915_READ(PCH_ADPA); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1523 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1524 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1525 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1526 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1527 | val = I915_READ(PCH_LVDS); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1528 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1529 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1530 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1531 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1532 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1533 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1534 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1537 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1538 | const struct intel_crtc_state *pipe_config) |
| 1539 | { |
| 1540 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1541 | enum pipe pipe = crtc->pipe; |
| 1542 | |
| 1543 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1544 | POSTING_READ(DPLL(pipe)); |
| 1545 | udelay(150); |
| 1546 | |
| 1547 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1548 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1549 | } |
| 1550 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1551 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1552 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1553 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1554 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1555 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1556 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1557 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1558 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1559 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1560 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1561 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1562 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1563 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1564 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1565 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1566 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1567 | } |
| 1568 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1569 | |
| 1570 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1571 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1572 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1573 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1574 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1575 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1576 | u32 tmp; |
| 1577 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1578 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1579 | |
| 1580 | /* Enable back the 10bit clock to display controller */ |
| 1581 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1582 | tmp |= DPIO_DCLKP_EN; |
| 1583 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1584 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1585 | mutex_unlock(&dev_priv->sb_lock); |
| 1586 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1587 | /* |
| 1588 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1589 | */ |
| 1590 | udelay(1); |
| 1591 | |
| 1592 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1593 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1594 | |
| 1595 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1596 | 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] | 1597 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1601 | const struct intel_crtc_state *pipe_config) |
| 1602 | { |
| 1603 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1604 | enum pipe pipe = crtc->pipe; |
| 1605 | |
| 1606 | assert_pipe_disabled(dev_priv, pipe); |
| 1607 | |
| 1608 | /* PLL is protected by panel, make sure we can write it */ |
| 1609 | assert_panel_unlocked(dev_priv, pipe); |
| 1610 | |
| 1611 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1612 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1613 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1614 | if (pipe != PIPE_A) { |
| 1615 | /* |
| 1616 | * WaPixelRepeatModeFixForC0:chv |
| 1617 | * |
| 1618 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1619 | * the value from DPLLBMD to either pipe B or C. |
| 1620 | */ |
| 1621 | I915_WRITE(CBR4_VLV, pipe == PIPE_B ? CBR_DPLLBMD_PIPE_B : CBR_DPLLBMD_PIPE_C); |
| 1622 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1623 | I915_WRITE(CBR4_VLV, 0); |
| 1624 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1625 | |
| 1626 | /* |
| 1627 | * DPLLB VGA mode also seems to cause problems. |
| 1628 | * We should always have it disabled. |
| 1629 | */ |
| 1630 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1631 | } else { |
| 1632 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1633 | POSTING_READ(DPLL_MD(pipe)); |
| 1634 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1635 | } |
| 1636 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1637 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1638 | { |
| 1639 | struct intel_crtc *crtc; |
| 1640 | int count = 0; |
| 1641 | |
| 1642 | for_each_intel_crtc(dev, crtc) |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1643 | count += crtc->base.state->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1644 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1645 | |
| 1646 | return count; |
| 1647 | } |
| 1648 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1649 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1650 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1651 | struct drm_device *dev = crtc->base.dev; |
| 1652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1653 | i915_reg_t reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1654 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1655 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1656 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1657 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1658 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1659 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1660 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1661 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1662 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1663 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1664 | /* |
| 1665 | * It appears to be important that we don't enable this |
| 1666 | * for the current pipe before otherwise configuring the |
| 1667 | * PLL. No idea how this should be handled if multiple |
| 1668 | * DVO outputs are enabled simultaneosly. |
| 1669 | */ |
| 1670 | dpll |= DPLL_DVO_2X_MODE; |
| 1671 | I915_WRITE(DPLL(!crtc->pipe), |
| 1672 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1673 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1674 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1675 | /* |
| 1676 | * Apparently we need to have VGA mode enabled prior to changing |
| 1677 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1678 | * dividers, even though the register value does change. |
| 1679 | */ |
| 1680 | I915_WRITE(reg, 0); |
| 1681 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1682 | I915_WRITE(reg, dpll); |
| 1683 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1684 | /* Wait for the clocks to stabilize. */ |
| 1685 | POSTING_READ(reg); |
| 1686 | udelay(150); |
| 1687 | |
| 1688 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1689 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1690 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1691 | } else { |
| 1692 | /* The pixel multiplier can only be updated once the |
| 1693 | * DPLL is enabled and the clocks are stable. |
| 1694 | * |
| 1695 | * So write it again. |
| 1696 | */ |
| 1697 | I915_WRITE(reg, dpll); |
| 1698 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1699 | |
| 1700 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1701 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1702 | POSTING_READ(reg); |
| 1703 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1704 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1705 | POSTING_READ(reg); |
| 1706 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1707 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1708 | POSTING_READ(reg); |
| 1709 | udelay(150); /* wait for warmup */ |
| 1710 | } |
| 1711 | |
| 1712 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1713 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1714 | * @dev_priv: i915 private structure |
| 1715 | * @pipe: pipe PLL to disable |
| 1716 | * |
| 1717 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1718 | * |
| 1719 | * Note! This is for pre-ILK only. |
| 1720 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1721 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1722 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1723 | struct drm_device *dev = crtc->base.dev; |
| 1724 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1725 | enum pipe pipe = crtc->pipe; |
| 1726 | |
| 1727 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1728 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1729 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1730 | !intel_num_dvo_pipes(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1731 | I915_WRITE(DPLL(PIPE_B), |
| 1732 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1733 | I915_WRITE(DPLL(PIPE_A), |
| 1734 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1735 | } |
| 1736 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1737 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1738 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1739 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1740 | return; |
| 1741 | |
| 1742 | /* Make sure the pipe isn't still relying on us */ |
| 1743 | assert_pipe_disabled(dev_priv, pipe); |
| 1744 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1745 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1746 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1749 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1750 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1751 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1752 | |
| 1753 | /* Make sure the pipe isn't still relying on us */ |
| 1754 | assert_pipe_disabled(dev_priv, pipe); |
| 1755 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1756 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1757 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1758 | if (pipe != PIPE_A) |
| 1759 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1760 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1761 | I915_WRITE(DPLL(pipe), val); |
| 1762 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1766 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1767 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1768 | u32 val; |
| 1769 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1770 | /* Make sure the pipe isn't still relying on us */ |
| 1771 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1772 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1773 | val = DPLL_SSC_REF_CLK_CHV | |
| 1774 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1775 | if (pipe != PIPE_A) |
| 1776 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1777 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1778 | I915_WRITE(DPLL(pipe), val); |
| 1779 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1780 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1781 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1782 | |
| 1783 | /* Disable 10bit clock to display controller */ |
| 1784 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1785 | val &= ~DPIO_DCLKP_EN; |
| 1786 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1787 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1788 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1791 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1792 | struct intel_digital_port *dport, |
| 1793 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1794 | { |
| 1795 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1796 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1797 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1798 | switch (dport->port) { |
| 1799 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1800 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1801 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1802 | break; |
| 1803 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1804 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1805 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1806 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1807 | break; |
| 1808 | case PORT_D: |
| 1809 | port_mask = DPLL_PORTD_READY_MASK; |
| 1810 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1811 | break; |
| 1812 | default: |
| 1813 | BUG(); |
| 1814 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1815 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1816 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
| 1817 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
| 1818 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1821 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1822 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1823 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1824 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1825 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1826 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1827 | i915_reg_t reg; |
| 1828 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1829 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1830 | /* Make sure PCH DPLL is enabled */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 1831 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1832 | |
| 1833 | /* FDI must be feeding us bits for PCH ports */ |
| 1834 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1835 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1836 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1837 | if (HAS_PCH_CPT(dev)) { |
| 1838 | /* Workaround: Set the timing override bit before enabling the |
| 1839 | * pch transcoder. */ |
| 1840 | reg = TRANS_CHICKEN2(pipe); |
| 1841 | val = I915_READ(reg); |
| 1842 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1843 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1844 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1845 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1846 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1847 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1848 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1849 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1850 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1851 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1852 | * Make the BPC in transcoder be consistent with |
| 1853 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1854 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1855 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1856 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1857 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
| 1858 | val |= PIPECONF_8BPC; |
| 1859 | else |
| 1860 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1861 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1862 | |
| 1863 | val &= ~TRANS_INTERLACE_MASK; |
| 1864 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1865 | if (HAS_PCH_IBX(dev_priv) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1866 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1867 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1868 | else |
| 1869 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1870 | else |
| 1871 | val |= TRANS_PROGRESSIVE; |
| 1872 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1873 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1874 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1875 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1876 | } |
| 1877 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1878 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1879 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1880 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1881 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1882 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1883 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1884 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1885 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1886 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1887 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1888 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1889 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1890 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1891 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1892 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1893 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1894 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1895 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1896 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1897 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1898 | else |
| 1899 | val |= TRANS_PROGRESSIVE; |
| 1900 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1901 | I915_WRITE(LPT_TRANSCONF, val); |
| 1902 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1903 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1904 | } |
| 1905 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1906 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1907 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1908 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1909 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1910 | i915_reg_t reg; |
| 1911 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1912 | |
| 1913 | /* FDI relies on the transcoder */ |
| 1914 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1915 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1916 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1917 | /* Ports must be off as well */ |
| 1918 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1919 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1920 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1921 | val = I915_READ(reg); |
| 1922 | val &= ~TRANS_ENABLE; |
| 1923 | I915_WRITE(reg, val); |
| 1924 | /* wait for PCH transcoder off, transcoder state */ |
| 1925 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1926 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1927 | |
Ville Syrjälä | c465613 | 2015-10-29 21:25:56 +0200 | [diff] [blame] | 1928 | if (HAS_PCH_CPT(dev)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1929 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1930 | reg = TRANS_CHICKEN2(pipe); |
| 1931 | val = I915_READ(reg); |
| 1932 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1933 | I915_WRITE(reg, val); |
| 1934 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1935 | } |
| 1936 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1937 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1938 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1939 | u32 val; |
| 1940 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1941 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1942 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1943 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1944 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1945 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1946 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1947 | |
| 1948 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1949 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1950 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1951 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1955 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1956 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1957 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1958 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1959 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1960 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1961 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1962 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1963 | struct drm_device *dev = crtc->base.dev; |
| 1964 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1965 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 1a70a728 | 2015-10-29 21:25:50 +0200 | [diff] [blame] | 1966 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1967 | enum pipe pch_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1968 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1969 | u32 val; |
| 1970 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1971 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1972 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1973 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1974 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1975 | assert_sprites_disabled(dev_priv, pipe); |
| 1976 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1977 | if (HAS_PCH_LPT(dev_priv)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1978 | pch_transcoder = TRANSCODER_A; |
| 1979 | else |
| 1980 | pch_transcoder = pipe; |
| 1981 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1982 | /* |
| 1983 | * A pipe without a PLL won't actually be able to drive bits from |
| 1984 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1985 | * need the check. |
| 1986 | */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1987 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 1988 | if (crtc->config->has_dsi_encoder) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1989 | assert_dsi_pll_enabled(dev_priv); |
| 1990 | else |
| 1991 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1992 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1993 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1994 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1995 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1996 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1997 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1998 | } |
| 1999 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2000 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2001 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2002 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2003 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2004 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2005 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2006 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2007 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2008 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2009 | |
| 2010 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2011 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 2012 | |
| 2013 | /* |
| 2014 | * Until the pipe starts DSL will read as 0, which would cause |
| 2015 | * an apparent vblank timestamp jump, which messes up also the |
| 2016 | * frame count when it's derived from the timestamps. So let's |
| 2017 | * wait for the pipe to start properly before we call |
| 2018 | * drm_crtc_vblank_on() |
| 2019 | */ |
| 2020 | if (dev->max_vblank_count == 0 && |
| 2021 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) |
| 2022 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2026 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2027 | * @crtc: crtc whose pipes is to be disabled |
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 | * Disable the pipe of @crtc, making sure that various hardware |
| 2030 | * specific requirements are met, if applicable, e.g. plane |
| 2031 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2032 | * |
| 2033 | * Will wait until the pipe has shut down before returning. |
| 2034 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2035 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2036 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2037 | 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] | 2038 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2039 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2040 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2041 | u32 val; |
| 2042 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2043 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 2044 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2045 | /* |
| 2046 | * Make sure planes won't keep trying to pump pixels to us, |
| 2047 | * or we might hang the display. |
| 2048 | */ |
| 2049 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2050 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2051 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2052 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2053 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2054 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2055 | if ((val & PIPECONF_ENABLE) == 0) |
| 2056 | return; |
| 2057 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2058 | /* |
| 2059 | * Double wide has implications for planes |
| 2060 | * so best keep it disabled when not needed. |
| 2061 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2062 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2063 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2064 | |
| 2065 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2066 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2067 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2068 | val &= ~PIPECONF_ENABLE; |
| 2069 | |
| 2070 | I915_WRITE(reg, val); |
| 2071 | if ((val & PIPECONF_ENABLE) == 0) |
| 2072 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2073 | } |
| 2074 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2075 | static bool need_vtd_wa(struct drm_device *dev) |
| 2076 | { |
| 2077 | #ifdef CONFIG_INTEL_IOMMU |
| 2078 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2079 | return true; |
| 2080 | #endif |
| 2081 | return false; |
| 2082 | } |
| 2083 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2084 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 2085 | { |
| 2086 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 2087 | } |
| 2088 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2089 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
| 2090 | uint64_t fb_modifier, unsigned int cpp) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2091 | { |
| 2092 | switch (fb_modifier) { |
| 2093 | case DRM_FORMAT_MOD_NONE: |
| 2094 | return cpp; |
| 2095 | case I915_FORMAT_MOD_X_TILED: |
| 2096 | if (IS_GEN2(dev_priv)) |
| 2097 | return 128; |
| 2098 | else |
| 2099 | return 512; |
| 2100 | case I915_FORMAT_MOD_Y_TILED: |
| 2101 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 2102 | return 128; |
| 2103 | else |
| 2104 | return 512; |
| 2105 | case I915_FORMAT_MOD_Yf_TILED: |
| 2106 | switch (cpp) { |
| 2107 | case 1: |
| 2108 | return 64; |
| 2109 | case 2: |
| 2110 | case 4: |
| 2111 | return 128; |
| 2112 | case 8: |
| 2113 | case 16: |
| 2114 | return 256; |
| 2115 | default: |
| 2116 | MISSING_CASE(cpp); |
| 2117 | return cpp; |
| 2118 | } |
| 2119 | break; |
| 2120 | default: |
| 2121 | MISSING_CASE(fb_modifier); |
| 2122 | return cpp; |
| 2123 | } |
| 2124 | } |
| 2125 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2126 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
| 2127 | uint64_t fb_modifier, unsigned int cpp) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2128 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2129 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
| 2130 | return 1; |
| 2131 | else |
| 2132 | return intel_tile_size(dev_priv) / |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2133 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2136 | /* Return the tile dimensions in pixel units */ |
| 2137 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, |
| 2138 | unsigned int *tile_width, |
| 2139 | unsigned int *tile_height, |
| 2140 | uint64_t fb_modifier, |
| 2141 | unsigned int cpp) |
| 2142 | { |
| 2143 | unsigned int tile_width_bytes = |
| 2144 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
| 2145 | |
| 2146 | *tile_width = tile_width_bytes / cpp; |
| 2147 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; |
| 2148 | } |
| 2149 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2150 | unsigned int |
| 2151 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2152 | uint32_t pixel_format, uint64_t fb_modifier) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2153 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2154 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 2155 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); |
| 2156 | |
| 2157 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2160 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 2161 | { |
| 2162 | unsigned int size = 0; |
| 2163 | int i; |
| 2164 | |
| 2165 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 2166 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2167 | |
| 2168 | return size; |
| 2169 | } |
| 2170 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 2171 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2172 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 2173 | const struct drm_framebuffer *fb, |
| 2174 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2175 | { |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2176 | if (intel_rotation_90_or_270(rotation)) { |
| 2177 | *view = i915_ggtt_view_rotated; |
| 2178 | view->params.rotated = to_intel_framebuffer(fb)->rot_info; |
| 2179 | } else { |
| 2180 | *view = i915_ggtt_view_normal; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | static void |
| 2185 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2186 | struct drm_framebuffer *fb) |
| 2187 | { |
| 2188 | struct intel_rotation_info *info = &to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2189 | unsigned int tile_size, tile_width, tile_height, cpp; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2190 | |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2191 | tile_size = intel_tile_size(dev_priv); |
| 2192 | |
| 2193 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
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[0], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2196 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2197 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); |
| 2198 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 2199 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2200 | if (info->pixel_format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2201 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2202 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2203 | fb->modifier[1], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2204 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2205 | info->uv_offset = fb->offsets[1]; |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2206 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); |
| 2207 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2208 | } |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2211 | 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] | 2212 | { |
| 2213 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2214 | return 256 * 1024; |
Ville Syrjälä | 985b8bb | 2015-06-11 16:31:15 +0300 | [diff] [blame] | 2215 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2216 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2217 | return 128 * 1024; |
| 2218 | else if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2219 | return 4 * 1024; |
| 2220 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2221 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2222 | } |
| 2223 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2224 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
| 2225 | uint64_t fb_modifier) |
| 2226 | { |
| 2227 | switch (fb_modifier) { |
| 2228 | case DRM_FORMAT_MOD_NONE: |
| 2229 | return intel_linear_alignment(dev_priv); |
| 2230 | case I915_FORMAT_MOD_X_TILED: |
| 2231 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2232 | return 256 * 1024; |
| 2233 | return 0; |
| 2234 | case I915_FORMAT_MOD_Y_TILED: |
| 2235 | case I915_FORMAT_MOD_Yf_TILED: |
| 2236 | return 1 * 1024 * 1024; |
| 2237 | default: |
| 2238 | MISSING_CASE(fb_modifier); |
| 2239 | return 0; |
| 2240 | } |
| 2241 | } |
| 2242 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2243 | int |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2244 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
| 2245 | unsigned int rotation) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2246 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2247 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2248 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2249 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2250 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2251 | u32 alignment; |
| 2252 | int ret; |
| 2253 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2254 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2255 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2256 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2257 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2258 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2259 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2260 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2261 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2262 | * we should always have valid PTE following the scanout preventing |
| 2263 | * the VT-d warning. |
| 2264 | */ |
| 2265 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2266 | alignment = 256 * 1024; |
| 2267 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2268 | /* |
| 2269 | * Global gtt pte registers are special registers which actually forward |
| 2270 | * writes to a chunk of system memory. Which means that there is no risk |
| 2271 | * that the register values disappear as soon as we call |
| 2272 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2273 | * pin/unpin/fence and not more. |
| 2274 | */ |
| 2275 | intel_runtime_pm_get(dev_priv); |
| 2276 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 2277 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
| 2278 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2279 | if (ret) |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2280 | goto err_pm; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2281 | |
| 2282 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2283 | * fence, whereas 965+ only requires a fence if using |
| 2284 | * framebuffer compression. For simplicity, we always install |
| 2285 | * a fence as the cost is not that onerous. |
| 2286 | */ |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2287 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
| 2288 | ret = i915_gem_object_get_fence(obj); |
| 2289 | if (ret == -EDEADLK) { |
| 2290 | /* |
| 2291 | * -EDEADLK means there are no free fences |
| 2292 | * no pending flips. |
| 2293 | * |
| 2294 | * This is propagated to atomic, but it uses |
| 2295 | * -EDEADLK to force a locking recovery, so |
| 2296 | * change the returned error to -EBUSY. |
| 2297 | */ |
| 2298 | ret = -EBUSY; |
| 2299 | goto err_unpin; |
| 2300 | } else if (ret) |
| 2301 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2302 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2303 | i915_gem_object_pin_fence(obj); |
| 2304 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2305 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2306 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2307 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2308 | |
| 2309 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2310 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2311 | err_pm: |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2312 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2313 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2314 | } |
| 2315 | |
Chris Wilson | fb4b8ce | 2016-04-28 09:56:35 +0100 | [diff] [blame] | 2316 | void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2317 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2318 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2319 | struct i915_ggtt_view view; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2320 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2321 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2322 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2323 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2324 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2325 | if (view.type == I915_GGTT_VIEW_NORMAL) |
| 2326 | i915_gem_object_unpin_fence(obj); |
| 2327 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2328 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2331 | /* |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2332 | * Adjust the tile offset by moving the difference into |
| 2333 | * the x/y offsets. |
| 2334 | * |
| 2335 | * Input tile dimensions and pitch must already be |
| 2336 | * rotated to match x and y, and in pixel units. |
| 2337 | */ |
| 2338 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2339 | unsigned int tile_width, |
| 2340 | unsigned int tile_height, |
| 2341 | unsigned int tile_size, |
| 2342 | unsigned int pitch_tiles, |
| 2343 | u32 old_offset, |
| 2344 | u32 new_offset) |
| 2345 | { |
| 2346 | unsigned int tiles; |
| 2347 | |
| 2348 | WARN_ON(old_offset & (tile_size - 1)); |
| 2349 | WARN_ON(new_offset & (tile_size - 1)); |
| 2350 | WARN_ON(new_offset > old_offset); |
| 2351 | |
| 2352 | tiles = (old_offset - new_offset) / tile_size; |
| 2353 | |
| 2354 | *y += tiles / pitch_tiles * tile_height; |
| 2355 | *x += tiles % pitch_tiles * tile_width; |
| 2356 | |
| 2357 | return new_offset; |
| 2358 | } |
| 2359 | |
| 2360 | /* |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2361 | * Computes the linear offset to the base tile and adjusts |
| 2362 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2363 | * |
| 2364 | * In the 90/270 rotated case, x and y are assumed |
| 2365 | * to be already rotated to match the rotated GTT view, and |
| 2366 | * pitch is the tile_height aligned framebuffer height. |
| 2367 | */ |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2368 | u32 intel_compute_tile_offset(int *x, int *y, |
| 2369 | const struct drm_framebuffer *fb, int plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2370 | unsigned int pitch, |
| 2371 | unsigned int rotation) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2372 | { |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2373 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2374 | uint64_t fb_modifier = fb->modifier[plane]; |
| 2375 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2376 | u32 offset, offset_aligned, alignment; |
| 2377 | |
| 2378 | alignment = intel_surf_alignment(dev_priv, fb_modifier); |
| 2379 | if (alignment) |
| 2380 | alignment--; |
| 2381 | |
Ville Syrjälä | b5c6533 | 2016-01-12 21:08:31 +0200 | [diff] [blame] | 2382 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2383 | unsigned int tile_size, tile_width, tile_height; |
| 2384 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2385 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2386 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2387 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2388 | fb_modifier, cpp); |
| 2389 | |
| 2390 | if (intel_rotation_90_or_270(rotation)) { |
| 2391 | pitch_tiles = pitch / tile_height; |
| 2392 | swap(tile_width, tile_height); |
| 2393 | } else { |
| 2394 | pitch_tiles = pitch / (tile_width * cpp); |
| 2395 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2396 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2397 | tile_rows = *y / tile_height; |
| 2398 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2399 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2400 | tiles = *x / tile_width; |
| 2401 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2402 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2403 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2404 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2405 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2406 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2407 | tile_size, pitch_tiles, |
| 2408 | offset, offset_aligned); |
| 2409 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2410 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2411 | offset_aligned = offset & ~alignment; |
| 2412 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2413 | *y = (offset & alignment) / pitch; |
| 2414 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2415 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2416 | |
| 2417 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2418 | } |
| 2419 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2420 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2421 | { |
| 2422 | switch (format) { |
| 2423 | case DISPPLANE_8BPP: |
| 2424 | return DRM_FORMAT_C8; |
| 2425 | case DISPPLANE_BGRX555: |
| 2426 | return DRM_FORMAT_XRGB1555; |
| 2427 | case DISPPLANE_BGRX565: |
| 2428 | return DRM_FORMAT_RGB565; |
| 2429 | default: |
| 2430 | case DISPPLANE_BGRX888: |
| 2431 | return DRM_FORMAT_XRGB8888; |
| 2432 | case DISPPLANE_RGBX888: |
| 2433 | return DRM_FORMAT_XBGR8888; |
| 2434 | case DISPPLANE_BGRX101010: |
| 2435 | return DRM_FORMAT_XRGB2101010; |
| 2436 | case DISPPLANE_RGBX101010: |
| 2437 | return DRM_FORMAT_XBGR2101010; |
| 2438 | } |
| 2439 | } |
| 2440 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2441 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2442 | { |
| 2443 | switch (format) { |
| 2444 | case PLANE_CTL_FORMAT_RGB_565: |
| 2445 | return DRM_FORMAT_RGB565; |
| 2446 | default: |
| 2447 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2448 | if (rgb_order) { |
| 2449 | if (alpha) |
| 2450 | return DRM_FORMAT_ABGR8888; |
| 2451 | else |
| 2452 | return DRM_FORMAT_XBGR8888; |
| 2453 | } else { |
| 2454 | if (alpha) |
| 2455 | return DRM_FORMAT_ARGB8888; |
| 2456 | else |
| 2457 | return DRM_FORMAT_XRGB8888; |
| 2458 | } |
| 2459 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2460 | if (rgb_order) |
| 2461 | return DRM_FORMAT_XBGR2101010; |
| 2462 | else |
| 2463 | return DRM_FORMAT_XRGB2101010; |
| 2464 | } |
| 2465 | } |
| 2466 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2467 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2468 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2469 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2470 | { |
| 2471 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2472 | struct drm_i915_private *dev_priv = to_i915(dev); |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2473 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2474 | struct drm_i915_gem_object *obj = NULL; |
| 2475 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2476 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2477 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2478 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2479 | PAGE_SIZE); |
| 2480 | |
| 2481 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2482 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2483 | if (plane_config->size == 0) |
| 2484 | return false; |
| 2485 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2486 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2487 | * important and we should probably use that space with FBC or other |
| 2488 | * features. */ |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2489 | if (size_aligned * 2 > ggtt->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2490 | return false; |
| 2491 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2492 | mutex_lock(&dev->struct_mutex); |
| 2493 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2494 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2495 | base_aligned, |
| 2496 | base_aligned, |
| 2497 | size_aligned); |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2498 | if (!obj) { |
| 2499 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2500 | return false; |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2501 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2502 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2503 | obj->tiling_mode = plane_config->tiling; |
| 2504 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2505 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2506 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2507 | mode_cmd.pixel_format = fb->pixel_format; |
| 2508 | mode_cmd.width = fb->width; |
| 2509 | mode_cmd.height = fb->height; |
| 2510 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2511 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2512 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2513 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2514 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2515 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2516 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2517 | goto out_unref_obj; |
| 2518 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2519 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2520 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2521 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2522 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2523 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2524 | |
| 2525 | out_unref_obj: |
| 2526 | drm_gem_object_unreference(&obj->base); |
| 2527 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2528 | return false; |
| 2529 | } |
| 2530 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 2531 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2532 | static void |
| 2533 | update_state_fb(struct drm_plane *plane) |
| 2534 | { |
| 2535 | if (plane->fb == plane->state->fb) |
| 2536 | return; |
| 2537 | |
| 2538 | if (plane->state->fb) |
| 2539 | drm_framebuffer_unreference(plane->state->fb); |
| 2540 | plane->state->fb = plane->fb; |
| 2541 | if (plane->state->fb) |
| 2542 | drm_framebuffer_reference(plane->state->fb); |
| 2543 | } |
| 2544 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2545 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2546 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2547 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2548 | { |
| 2549 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2550 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2551 | struct drm_crtc *c; |
| 2552 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2553 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2554 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2555 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2556 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
| 2557 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2558 | struct intel_plane_state *intel_state = |
| 2559 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2560 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2561 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2562 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2563 | return; |
| 2564 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2565 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2566 | fb = &plane_config->fb->base; |
| 2567 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2568 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2569 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2570 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2571 | |
| 2572 | /* |
| 2573 | * Failed to alloc the obj, check to see if we should share |
| 2574 | * an fb with another CRTC instead |
| 2575 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2576 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2577 | i = to_intel_crtc(c); |
| 2578 | |
| 2579 | if (c == &intel_crtc->base) |
| 2580 | continue; |
| 2581 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2582 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2583 | continue; |
| 2584 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2585 | fb = c->primary->fb; |
| 2586 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2587 | continue; |
| 2588 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2589 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2590 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2591 | drm_framebuffer_reference(fb); |
| 2592 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2593 | } |
| 2594 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2595 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2596 | /* |
| 2597 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2598 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2599 | * which will lead to problems later if we don't fix it up. The |
| 2600 | * simplest solution is to just disable the primary plane now and |
| 2601 | * pretend the BIOS never had it enabled. |
| 2602 | */ |
| 2603 | to_intel_plane_state(plane_state)->visible = false; |
| 2604 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 2605 | intel_pre_disable_primary_noatomic(&intel_crtc->base); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2606 | intel_plane->disable_plane(primary, &intel_crtc->base); |
| 2607 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2608 | return; |
| 2609 | |
| 2610 | valid_fb: |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2611 | plane_state->src_x = 0; |
| 2612 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2613 | plane_state->src_w = fb->width << 16; |
| 2614 | plane_state->src_h = fb->height << 16; |
| 2615 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2616 | plane_state->crtc_x = 0; |
| 2617 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2618 | plane_state->crtc_w = fb->width; |
| 2619 | plane_state->crtc_h = fb->height; |
| 2620 | |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2621 | intel_state->src.x1 = plane_state->src_x; |
| 2622 | intel_state->src.y1 = plane_state->src_y; |
| 2623 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; |
| 2624 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; |
| 2625 | intel_state->dst.x1 = plane_state->crtc_x; |
| 2626 | intel_state->dst.y1 = plane_state->crtc_y; |
| 2627 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; |
| 2628 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; |
| 2629 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2630 | obj = intel_fb_obj(fb); |
| 2631 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2632 | dev_priv->preserve_bios_swizzle = true; |
| 2633 | |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2634 | drm_framebuffer_reference(fb); |
| 2635 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2636 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2637 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 2638 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2639 | } |
| 2640 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2641 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
| 2642 | const struct intel_crtc_state *crtc_state, |
| 2643 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2644 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2645 | struct drm_device *dev = primary->dev; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2646 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2647 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2648 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2649 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2650 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2651 | u32 linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2652 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2653 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2654 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2655 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2656 | int x = plane_state->src.x1 >> 16; |
| 2657 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2658 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2659 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2660 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2661 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2662 | |
| 2663 | if (INTEL_INFO(dev)->gen < 4) { |
| 2664 | if (intel_crtc->pipe == PIPE_B) |
| 2665 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2666 | |
| 2667 | /* pipesrc and dspsize control the size that is scaled from, |
| 2668 | * which should always be the user's requested size. |
| 2669 | */ |
| 2670 | I915_WRITE(DSPSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2671 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2672 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2673 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2674 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2675 | I915_WRITE(PRIMSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2676 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2677 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2678 | I915_WRITE(PRIMPOS(plane), 0); |
| 2679 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2680 | } |
| 2681 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2682 | switch (fb->pixel_format) { |
| 2683 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2684 | dspcntr |= DISPPLANE_8BPP; |
| 2685 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2686 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2687 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2688 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2689 | case DRM_FORMAT_RGB565: |
| 2690 | dspcntr |= DISPPLANE_BGRX565; |
| 2691 | break; |
| 2692 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2693 | dspcntr |= DISPPLANE_BGRX888; |
| 2694 | break; |
| 2695 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2696 | dspcntr |= DISPPLANE_RGBX888; |
| 2697 | break; |
| 2698 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2699 | dspcntr |= DISPPLANE_BGRX101010; |
| 2700 | break; |
| 2701 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2702 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2703 | break; |
| 2704 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2705 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2706 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2707 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2708 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2709 | obj->tiling_mode != I915_TILING_NONE) |
| 2710 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2711 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2712 | if (IS_G4X(dev)) |
| 2713 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2714 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2715 | linear_offset = y * fb->pitches[0] + x * cpp; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2716 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2717 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2718 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2719 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2720 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2721 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2722 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2723 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2724 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2725 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2726 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2727 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2728 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2729 | x += (crtc_state->pipe_src_w - 1); |
| 2730 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2731 | |
| 2732 | /* Finding the last pixel of the last line of the display |
| 2733 | data and adding to linear_offset*/ |
| 2734 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2735 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2736 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2737 | } |
| 2738 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2739 | intel_crtc->adjusted_x = x; |
| 2740 | intel_crtc->adjusted_y = y; |
| 2741 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2742 | I915_WRITE(reg, dspcntr); |
| 2743 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2744 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2745 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2746 | I915_WRITE(DSPSURF(plane), |
| 2747 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2748 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2749 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2750 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2751 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2752 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2755 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
| 2756 | struct drm_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2757 | { |
| 2758 | struct drm_device *dev = crtc->dev; |
| 2759 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2760 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2761 | int plane = intel_crtc->plane; |
| 2762 | |
| 2763 | I915_WRITE(DSPCNTR(plane), 0); |
| 2764 | if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2765 | I915_WRITE(DSPSURF(plane), 0); |
| 2766 | else |
| 2767 | I915_WRITE(DSPADDR(plane), 0); |
| 2768 | POSTING_READ(DSPCNTR(plane)); |
| 2769 | } |
| 2770 | |
| 2771 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
| 2772 | const struct intel_crtc_state *crtc_state, |
| 2773 | const struct intel_plane_state *plane_state) |
| 2774 | { |
| 2775 | struct drm_device *dev = primary->dev; |
| 2776 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2777 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2778 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2779 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2780 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2781 | u32 linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2782 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2783 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2784 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2785 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2786 | int x = plane_state->src.x1 >> 16; |
| 2787 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2788 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2789 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2790 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2791 | |
| 2792 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2793 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2794 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2795 | switch (fb->pixel_format) { |
| 2796 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2797 | dspcntr |= DISPPLANE_8BPP; |
| 2798 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2799 | case DRM_FORMAT_RGB565: |
| 2800 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2801 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2802 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2803 | dspcntr |= DISPPLANE_BGRX888; |
| 2804 | break; |
| 2805 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2806 | dspcntr |= DISPPLANE_RGBX888; |
| 2807 | break; |
| 2808 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2809 | dspcntr |= DISPPLANE_BGRX101010; |
| 2810 | break; |
| 2811 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2812 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2813 | break; |
| 2814 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2815 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2819 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2820 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2821 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2822 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2823 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2824 | linear_offset = y * fb->pitches[0] + x * cpp; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2825 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2826 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2827 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2828 | linear_offset -= intel_crtc->dspaddr_offset; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2829 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2830 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2831 | |
| 2832 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2833 | x += (crtc_state->pipe_src_w - 1); |
| 2834 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2835 | |
| 2836 | /* Finding the last pixel of the last line of the display |
| 2837 | data and adding to linear_offset*/ |
| 2838 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2839 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2840 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2844 | intel_crtc->adjusted_x = x; |
| 2845 | intel_crtc->adjusted_y = y; |
| 2846 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2847 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2848 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2849 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2850 | I915_WRITE(DSPSURF(plane), |
| 2851 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2852 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2853 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2854 | } else { |
| 2855 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2856 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2857 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2858 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2861 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
| 2862 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2863 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2864 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
| 2865 | return 64; |
| 2866 | } else { |
| 2867 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2868 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2869 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2870 | } |
| 2871 | } |
| 2872 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2873 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2874 | struct drm_i915_gem_object *obj, |
| 2875 | unsigned int plane) |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2876 | { |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2877 | struct i915_ggtt_view view; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2878 | struct i915_vma *vma; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2879 | u64 offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2880 | |
Ville Syrjälä | e794129 | 2016-01-19 18:23:17 +0200 | [diff] [blame] | 2881 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2882 | intel_plane->base.state->rotation); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2883 | |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2884 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2885 | 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] | 2886 | view.type)) |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2887 | return -1; |
| 2888 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2889 | offset = vma->node.start; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2890 | |
| 2891 | if (plane == 1) { |
Ville Syrjälä | 7723f47d | 2016-01-20 21:05:22 +0200 | [diff] [blame] | 2892 | offset += vma->ggtt_view.params.rotated.uv_start_page * |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2893 | PAGE_SIZE; |
| 2894 | } |
| 2895 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2896 | WARN_ON(upper_32_bits(offset)); |
| 2897 | |
| 2898 | return lower_32_bits(offset); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2901 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 2902 | { |
| 2903 | struct drm_device *dev = intel_crtc->base.dev; |
| 2904 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2905 | |
| 2906 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 2907 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 2908 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2909 | } |
| 2910 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2911 | /* |
| 2912 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 2913 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 2914 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2915 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2916 | struct intel_crtc_scaler_state *scaler_state; |
| 2917 | int i; |
| 2918 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2919 | scaler_state = &intel_crtc->config->scaler_state; |
| 2920 | |
| 2921 | /* loop through and disable scalers that aren't in use */ |
| 2922 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2923 | if (!scaler_state->scalers[i].in_use) |
| 2924 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2928 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 2929 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2930 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 2931 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2932 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2933 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2934 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2935 | case DRM_FORMAT_XBGR8888: |
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 | case DRM_FORMAT_XRGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2938 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2939 | /* |
| 2940 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 2941 | * to be already pre-multiplied. We need to add a knob (or a different |
| 2942 | * DRM_FORMAT) for user-space to configure that. |
| 2943 | */ |
| 2944 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2945 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2946 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2947 | case DRM_FORMAT_ARGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2948 | return PLANE_CTL_FORMAT_XRGB_8888 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2949 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2950 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2951 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2952 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2953 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2954 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2955 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2956 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2957 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2958 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2959 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2960 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2961 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2962 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 2963 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2964 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2965 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2966 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 2970 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2971 | switch (fb_modifier) { |
| 2972 | case DRM_FORMAT_MOD_NONE: |
| 2973 | break; |
| 2974 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2975 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2976 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2977 | return PLANE_CTL_TILED_Y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2978 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2979 | return PLANE_CTL_TILED_YF; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2980 | default: |
| 2981 | MISSING_CASE(fb_modifier); |
| 2982 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2983 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2984 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 2988 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2989 | switch (rotation) { |
| 2990 | case BIT(DRM_ROTATE_0): |
| 2991 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2992 | /* |
| 2993 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 2994 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 2995 | */ |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2996 | case BIT(DRM_ROTATE_90): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2997 | return PLANE_CTL_ROTATE_270; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2998 | case BIT(DRM_ROTATE_180): |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2999 | return PLANE_CTL_ROTATE_180; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3000 | case BIT(DRM_ROTATE_270): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3001 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3002 | default: |
| 3003 | MISSING_CASE(rotation); |
| 3004 | } |
| 3005 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3006 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3009 | static void skylake_update_primary_plane(struct drm_plane *plane, |
| 3010 | const struct intel_crtc_state *crtc_state, |
| 3011 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3012 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3013 | struct drm_device *dev = plane->dev; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3014 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3016 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 3017 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3018 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3019 | u32 plane_ctl, stride_div, stride; |
| 3020 | u32 tile_height, plane_offset, plane_size; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3021 | unsigned int rotation = plane_state->base.rotation; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3022 | int x_offset, y_offset; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 3023 | u32 surf_addr; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3024 | int scaler_id = plane_state->scaler_id; |
| 3025 | int src_x = plane_state->src.x1 >> 16; |
| 3026 | int src_y = plane_state->src.y1 >> 16; |
| 3027 | int src_w = drm_rect_width(&plane_state->src) >> 16; |
| 3028 | int src_h = drm_rect_height(&plane_state->src) >> 16; |
| 3029 | int dst_x = plane_state->dst.x1; |
| 3030 | int dst_y = plane_state->dst.y1; |
| 3031 | int dst_w = drm_rect_width(&plane_state->dst); |
| 3032 | int dst_h = drm_rect_height(&plane_state->dst); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3033 | |
| 3034 | plane_ctl = PLANE_CTL_ENABLE | |
| 3035 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3036 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 3037 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3038 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
| 3039 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3040 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3041 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3042 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3043 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3044 | fb->pixel_format); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 3045 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3046 | |
Paulo Zanoni | a42e5a2 | 2015-09-30 17:05:43 -0300 | [diff] [blame] | 3047 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3048 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3049 | if (intel_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3050 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
| 3051 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3052 | /* stride = Surface height in tiles */ |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3053 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3054 | stride = DIV_ROUND_UP(fb->height, tile_height); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3055 | x_offset = stride * tile_height - src_y - src_h; |
| 3056 | y_offset = src_x; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3057 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3058 | } else { |
| 3059 | stride = fb->pitches[0] / stride_div; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3060 | x_offset = src_x; |
| 3061 | y_offset = src_y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3062 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3063 | } |
| 3064 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3065 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3066 | intel_crtc->adjusted_x = x_offset; |
| 3067 | intel_crtc->adjusted_y = y_offset; |
| 3068 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3069 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3070 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3071 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3072 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3073 | |
| 3074 | if (scaler_id >= 0) { |
| 3075 | uint32_t ps_ctrl = 0; |
| 3076 | |
| 3077 | WARN_ON(!dst_w || !dst_h); |
| 3078 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | |
| 3079 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3080 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3081 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3082 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3083 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
| 3084 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3085 | } else { |
| 3086 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); |
| 3087 | } |
| 3088 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3089 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3090 | |
| 3091 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3092 | } |
| 3093 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3094 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
| 3095 | struct drm_crtc *crtc) |
| 3096 | { |
| 3097 | struct drm_device *dev = crtc->dev; |
| 3098 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3099 | int pipe = to_intel_crtc(crtc)->pipe; |
| 3100 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3101 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 3102 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 3103 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3104 | } |
| 3105 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3106 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3107 | static int |
| 3108 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3109 | int x, int y, enum mode_set_atomic state) |
| 3110 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3111 | /* Support for kgdboc is disabled, this needs a major rework. */ |
| 3112 | DRM_ERROR("legacy panic handler not supported any more.\n"); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3113 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3114 | return -ENODEV; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3117 | static void intel_complete_page_flips(struct drm_i915_private *dev_priv) |
| 3118 | { |
| 3119 | struct intel_crtc *crtc; |
| 3120 | |
| 3121 | for_each_intel_crtc(dev_priv->dev, crtc) |
| 3122 | intel_finish_page_flip_cs(dev_priv, crtc->pipe); |
| 3123 | } |
| 3124 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3125 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3126 | { |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3127 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3128 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3129 | for_each_crtc(dev, crtc) { |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3130 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
| 3131 | struct intel_plane_state *plane_state; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3132 | |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3133 | drm_modeset_lock_crtc(crtc, &plane->base); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3134 | plane_state = to_intel_plane_state(plane->base.state); |
| 3135 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3136 | if (plane_state->visible) |
| 3137 | plane->update_plane(&plane->base, |
| 3138 | to_intel_crtc_state(crtc->state), |
| 3139 | plane_state); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3140 | |
| 3141 | drm_modeset_unlock_crtc(crtc); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3145 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3146 | { |
| 3147 | /* no reset support for gen2 */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3148 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3149 | return; |
| 3150 | |
| 3151 | /* reset doesn't touch the display */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3152 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3153 | return; |
| 3154 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3155 | drm_modeset_lock_all(dev_priv->dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3156 | /* |
| 3157 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3158 | * g33 docs say we should at least disable all the planes. |
| 3159 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3160 | intel_display_suspend(dev_priv->dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3161 | } |
| 3162 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3163 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3164 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3165 | /* |
| 3166 | * Flips in the rings will be nuked by the reset, |
| 3167 | * so complete all pending flips so that user space |
| 3168 | * will get its events and not get stuck. |
| 3169 | */ |
| 3170 | intel_complete_page_flips(dev_priv); |
| 3171 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3172 | /* no reset support for gen2 */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3173 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3174 | return; |
| 3175 | |
| 3176 | /* reset doesn't touch the display */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3177 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) { |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3178 | /* |
| 3179 | * Flips in the rings have been nuked by the reset, |
| 3180 | * so update the base address of all primary |
| 3181 | * planes to the the last fb to make sure we're |
| 3182 | * showing the correct fb after a reset. |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3183 | * |
| 3184 | * FIXME: Atomic will make this obsolete since we won't schedule |
| 3185 | * 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] | 3186 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3187 | intel_update_primary_planes(dev_priv->dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3188 | return; |
| 3189 | } |
| 3190 | |
| 3191 | /* |
| 3192 | * The display has been reset as well, |
| 3193 | * so need a full re-initialization. |
| 3194 | */ |
| 3195 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3196 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3197 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3198 | intel_modeset_init_hw(dev_priv->dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3199 | |
| 3200 | spin_lock_irq(&dev_priv->irq_lock); |
| 3201 | if (dev_priv->display.hpd_irq_setup) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 3202 | dev_priv->display.hpd_irq_setup(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3203 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3204 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3205 | intel_display_resume(dev_priv->dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3206 | |
| 3207 | intel_hpd_init(dev_priv); |
| 3208 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3209 | drm_modeset_unlock_all(dev_priv->dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3212 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3213 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3214 | struct drm_device *dev = crtc->dev; |
| 3215 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3216 | unsigned reset_counter; |
| 3217 | bool pending; |
| 3218 | |
| 3219 | reset_counter = i915_reset_counter(&to_i915(dev)->gpu_error); |
| 3220 | if (intel_crtc->reset_counter != reset_counter) |
| 3221 | return false; |
| 3222 | |
| 3223 | spin_lock_irq(&dev->event_lock); |
| 3224 | pending = to_intel_crtc(crtc)->flip_work != NULL; |
| 3225 | spin_unlock_irq(&dev->event_lock); |
| 3226 | |
| 3227 | return pending; |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3230 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
| 3231 | struct intel_crtc_state *old_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3232 | { |
| 3233 | struct drm_device *dev = crtc->base.dev; |
| 3234 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3235 | struct intel_crtc_state *pipe_config = |
| 3236 | to_intel_crtc_state(crtc->base.state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3237 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3238 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
| 3239 | crtc->base.mode = crtc->base.state->mode; |
| 3240 | |
| 3241 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", |
| 3242 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, |
| 3243 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3244 | |
| 3245 | /* |
| 3246 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3247 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3248 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3249 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3250 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3251 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3252 | */ |
| 3253 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3254 | I915_WRITE(PIPESRC(crtc->pipe), |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3255 | ((pipe_config->pipe_src_w - 1) << 16) | |
| 3256 | (pipe_config->pipe_src_h - 1)); |
| 3257 | |
| 3258 | /* on skylake this is done by detaching scalers */ |
| 3259 | if (INTEL_INFO(dev)->gen >= 9) { |
| 3260 | skl_detach_scalers(crtc); |
| 3261 | |
| 3262 | if (pipe_config->pch_pfit.enabled) |
| 3263 | skylake_pfit_enable(crtc); |
| 3264 | } else if (HAS_PCH_SPLIT(dev)) { |
| 3265 | if (pipe_config->pch_pfit.enabled) |
| 3266 | ironlake_pfit_enable(crtc); |
| 3267 | else if (old_crtc_state->pch_pfit.enabled) |
| 3268 | ironlake_pfit_disable(crtc, true); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3269 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3270 | } |
| 3271 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3272 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3273 | { |
| 3274 | struct drm_device *dev = crtc->dev; |
| 3275 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3276 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3277 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3278 | i915_reg_t reg; |
| 3279 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3280 | |
| 3281 | /* enable normal train */ |
| 3282 | reg = FDI_TX_CTL(pipe); |
| 3283 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3284 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3285 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3286 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3287 | } else { |
| 3288 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3289 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3290 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3291 | I915_WRITE(reg, temp); |
| 3292 | |
| 3293 | reg = FDI_RX_CTL(pipe); |
| 3294 | temp = I915_READ(reg); |
| 3295 | if (HAS_PCH_CPT(dev)) { |
| 3296 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3297 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3298 | } else { |
| 3299 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3300 | temp |= FDI_LINK_TRAIN_NONE; |
| 3301 | } |
| 3302 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3303 | |
| 3304 | /* wait one idle pattern time */ |
| 3305 | POSTING_READ(reg); |
| 3306 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3307 | |
| 3308 | /* IVB wants error correction enabled */ |
| 3309 | if (IS_IVYBRIDGE(dev)) |
| 3310 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3311 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3312 | } |
| 3313 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3314 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3315 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3316 | { |
| 3317 | struct drm_device *dev = crtc->dev; |
| 3318 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3319 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3320 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3321 | i915_reg_t reg; |
| 3322 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3323 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3324 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3325 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3326 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3327 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3328 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3329 | reg = FDI_RX_IMR(pipe); |
| 3330 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3331 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3332 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3333 | I915_WRITE(reg, temp); |
| 3334 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3335 | udelay(150); |
| 3336 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3337 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3338 | reg = FDI_TX_CTL(pipe); |
| 3339 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3340 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3341 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3342 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3343 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3344 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3345 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3346 | reg = FDI_RX_CTL(pipe); |
| 3347 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3348 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3349 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3350 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3351 | |
| 3352 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3353 | udelay(150); |
| 3354 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3355 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3356 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3357 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3358 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3359 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3360 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3361 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3362 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3363 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3364 | |
| 3365 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3366 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3367 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3368 | break; |
| 3369 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3370 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3371 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3372 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3373 | |
| 3374 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3375 | reg = FDI_TX_CTL(pipe); |
| 3376 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3377 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3378 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3379 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3380 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3381 | reg = FDI_RX_CTL(pipe); |
| 3382 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3383 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3384 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3385 | I915_WRITE(reg, temp); |
| 3386 | |
| 3387 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3388 | udelay(150); |
| 3389 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3390 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3391 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3392 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3393 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3394 | |
| 3395 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3396 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3397 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3398 | break; |
| 3399 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3400 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3401 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3402 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3403 | |
| 3404 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3405 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3406 | } |
| 3407 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3408 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3409 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3410 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3411 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3412 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3413 | }; |
| 3414 | |
| 3415 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3416 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3417 | { |
| 3418 | struct drm_device *dev = crtc->dev; |
| 3419 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3420 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3421 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3422 | i915_reg_t reg; |
| 3423 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3424 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3425 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3426 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3427 | reg = FDI_RX_IMR(pipe); |
| 3428 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3429 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3430 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3431 | I915_WRITE(reg, temp); |
| 3432 | |
| 3433 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3434 | udelay(150); |
| 3435 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3436 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3437 | reg = FDI_TX_CTL(pipe); |
| 3438 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3439 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3440 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3441 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3442 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3443 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3444 | /* SNB-B */ |
| 3445 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3446 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3447 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3448 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3449 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3450 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3451 | reg = FDI_RX_CTL(pipe); |
| 3452 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3453 | if (HAS_PCH_CPT(dev)) { |
| 3454 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3455 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3456 | } else { |
| 3457 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3458 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3459 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3460 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3461 | |
| 3462 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3463 | udelay(150); |
| 3464 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3465 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3466 | reg = FDI_TX_CTL(pipe); |
| 3467 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3468 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3469 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3470 | I915_WRITE(reg, temp); |
| 3471 | |
| 3472 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3473 | udelay(500); |
| 3474 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3475 | for (retry = 0; retry < 5; retry++) { |
| 3476 | reg = FDI_RX_IIR(pipe); |
| 3477 | temp = I915_READ(reg); |
| 3478 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3479 | if (temp & FDI_RX_BIT_LOCK) { |
| 3480 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3481 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3482 | break; |
| 3483 | } |
| 3484 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3485 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3486 | if (retry < 5) |
| 3487 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3488 | } |
| 3489 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3490 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3491 | |
| 3492 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3493 | reg = FDI_TX_CTL(pipe); |
| 3494 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3495 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3496 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3497 | if (IS_GEN6(dev)) { |
| 3498 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3499 | /* SNB-B */ |
| 3500 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3501 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3502 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3503 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3504 | reg = FDI_RX_CTL(pipe); |
| 3505 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3506 | if (HAS_PCH_CPT(dev)) { |
| 3507 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3508 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3509 | } else { |
| 3510 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3511 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3512 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3513 | I915_WRITE(reg, temp); |
| 3514 | |
| 3515 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3516 | udelay(150); |
| 3517 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3518 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3519 | reg = FDI_TX_CTL(pipe); |
| 3520 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3521 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3522 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3523 | I915_WRITE(reg, temp); |
| 3524 | |
| 3525 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3526 | udelay(500); |
| 3527 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3528 | for (retry = 0; retry < 5; retry++) { |
| 3529 | reg = FDI_RX_IIR(pipe); |
| 3530 | temp = I915_READ(reg); |
| 3531 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3532 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3533 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3534 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3535 | break; |
| 3536 | } |
| 3537 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3538 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3539 | if (retry < 5) |
| 3540 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3541 | } |
| 3542 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3543 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3544 | |
| 3545 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3546 | } |
| 3547 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3548 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3549 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3550 | { |
| 3551 | struct drm_device *dev = crtc->dev; |
| 3552 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3553 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3554 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3555 | i915_reg_t reg; |
| 3556 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3557 | |
| 3558 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3559 | for train result */ |
| 3560 | reg = FDI_RX_IMR(pipe); |
| 3561 | temp = I915_READ(reg); |
| 3562 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3563 | temp &= ~FDI_RX_BIT_LOCK; |
| 3564 | I915_WRITE(reg, temp); |
| 3565 | |
| 3566 | POSTING_READ(reg); |
| 3567 | udelay(150); |
| 3568 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3569 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3570 | I915_READ(FDI_RX_IIR(pipe))); |
| 3571 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3572 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3573 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3574 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3575 | reg = FDI_TX_CTL(pipe); |
| 3576 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3577 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3578 | temp &= ~FDI_TX_ENABLE; |
| 3579 | I915_WRITE(reg, temp); |
| 3580 | |
| 3581 | reg = FDI_RX_CTL(pipe); |
| 3582 | temp = I915_READ(reg); |
| 3583 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3584 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3585 | temp &= ~FDI_RX_ENABLE; |
| 3586 | I915_WRITE(reg, temp); |
| 3587 | |
| 3588 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3589 | reg = FDI_TX_CTL(pipe); |
| 3590 | temp = I915_READ(reg); |
| 3591 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3592 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3593 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3594 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3595 | temp |= snb_b_fdi_train_param[j/2]; |
| 3596 | temp |= FDI_COMPOSITE_SYNC; |
| 3597 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3598 | |
| 3599 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3600 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3601 | |
| 3602 | reg = FDI_RX_CTL(pipe); |
| 3603 | temp = I915_READ(reg); |
| 3604 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3605 | temp |= FDI_COMPOSITE_SYNC; |
| 3606 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3607 | |
| 3608 | POSTING_READ(reg); |
| 3609 | udelay(1); /* should be 0.5us */ |
| 3610 | |
| 3611 | for (i = 0; i < 4; i++) { |
| 3612 | reg = FDI_RX_IIR(pipe); |
| 3613 | temp = I915_READ(reg); |
| 3614 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3615 | |
| 3616 | if (temp & FDI_RX_BIT_LOCK || |
| 3617 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3618 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3619 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3620 | i); |
| 3621 | break; |
| 3622 | } |
| 3623 | udelay(1); /* should be 0.5us */ |
| 3624 | } |
| 3625 | if (i == 4) { |
| 3626 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3627 | continue; |
| 3628 | } |
| 3629 | |
| 3630 | /* Train 2 */ |
| 3631 | reg = FDI_TX_CTL(pipe); |
| 3632 | temp = I915_READ(reg); |
| 3633 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3634 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3635 | I915_WRITE(reg, temp); |
| 3636 | |
| 3637 | reg = FDI_RX_CTL(pipe); |
| 3638 | temp = I915_READ(reg); |
| 3639 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3640 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3641 | I915_WRITE(reg, temp); |
| 3642 | |
| 3643 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3644 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3645 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3646 | for (i = 0; i < 4; i++) { |
| 3647 | reg = FDI_RX_IIR(pipe); |
| 3648 | temp = I915_READ(reg); |
| 3649 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3650 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3651 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3652 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3653 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3654 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3655 | i); |
| 3656 | goto train_done; |
| 3657 | } |
| 3658 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3659 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3660 | if (i == 4) |
| 3661 | 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] | 3662 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3663 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3664 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3665 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3666 | } |
| 3667 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3668 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3669 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3670 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3671 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3672 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3673 | i915_reg_t reg; |
| 3674 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3675 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3676 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3677 | reg = FDI_RX_CTL(pipe); |
| 3678 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3679 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3680 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3681 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3682 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3683 | |
| 3684 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3685 | udelay(200); |
| 3686 | |
| 3687 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3688 | temp = I915_READ(reg); |
| 3689 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3690 | |
| 3691 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3692 | udelay(200); |
| 3693 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3694 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3695 | reg = FDI_TX_CTL(pipe); |
| 3696 | temp = I915_READ(reg); |
| 3697 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3698 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3699 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3700 | POSTING_READ(reg); |
| 3701 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3705 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3706 | { |
| 3707 | struct drm_device *dev = intel_crtc->base.dev; |
| 3708 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3709 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3710 | i915_reg_t reg; |
| 3711 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3712 | |
| 3713 | /* Switch from PCDclk to Rawclk */ |
| 3714 | reg = FDI_RX_CTL(pipe); |
| 3715 | temp = I915_READ(reg); |
| 3716 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3717 | |
| 3718 | /* Disable CPU FDI TX PLL */ |
| 3719 | reg = FDI_TX_CTL(pipe); |
| 3720 | temp = I915_READ(reg); |
| 3721 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3722 | |
| 3723 | POSTING_READ(reg); |
| 3724 | udelay(100); |
| 3725 | |
| 3726 | reg = FDI_RX_CTL(pipe); |
| 3727 | temp = I915_READ(reg); |
| 3728 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3729 | |
| 3730 | /* Wait for the clocks to turn off. */ |
| 3731 | POSTING_READ(reg); |
| 3732 | udelay(100); |
| 3733 | } |
| 3734 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3735 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3736 | { |
| 3737 | struct drm_device *dev = crtc->dev; |
| 3738 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3739 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3740 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3741 | i915_reg_t reg; |
| 3742 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3743 | |
| 3744 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3745 | reg = FDI_TX_CTL(pipe); |
| 3746 | temp = I915_READ(reg); |
| 3747 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3748 | POSTING_READ(reg); |
| 3749 | |
| 3750 | reg = FDI_RX_CTL(pipe); |
| 3751 | temp = I915_READ(reg); |
| 3752 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3753 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3754 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3755 | |
| 3756 | POSTING_READ(reg); |
| 3757 | udelay(100); |
| 3758 | |
| 3759 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3760 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3761 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3762 | |
| 3763 | /* still set train pattern 1 */ |
| 3764 | reg = FDI_TX_CTL(pipe); |
| 3765 | temp = I915_READ(reg); |
| 3766 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3767 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3768 | I915_WRITE(reg, temp); |
| 3769 | |
| 3770 | reg = FDI_RX_CTL(pipe); |
| 3771 | temp = I915_READ(reg); |
| 3772 | if (HAS_PCH_CPT(dev)) { |
| 3773 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3774 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3775 | } else { |
| 3776 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3777 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3778 | } |
| 3779 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3780 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3781 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3782 | I915_WRITE(reg, temp); |
| 3783 | |
| 3784 | POSTING_READ(reg); |
| 3785 | udelay(100); |
| 3786 | } |
| 3787 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3788 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3789 | { |
| 3790 | struct intel_crtc *crtc; |
| 3791 | |
| 3792 | /* Note that we don't need to be called with mode_config.lock here |
| 3793 | * as our list of CRTC objects is static for the lifetime of the |
| 3794 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3795 | * happily treat the predicates as racy, atomic checks as userspace |
| 3796 | * cannot claim and pin a new fb without at least acquring the |
| 3797 | * struct_mutex and so serialising with us. |
| 3798 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3799 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3800 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3801 | continue; |
| 3802 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3803 | if (crtc->flip_work) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3804 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3805 | |
| 3806 | return true; |
| 3807 | } |
| 3808 | |
| 3809 | return false; |
| 3810 | } |
| 3811 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3812 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3813 | { |
| 3814 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3815 | struct intel_flip_work *work = intel_crtc->flip_work; |
| 3816 | |
| 3817 | intel_crtc->flip_work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3818 | |
| 3819 | if (work->event) |
Gustavo Padovan | 560ce1d | 2016-04-14 10:48:15 -0700 | [diff] [blame] | 3820 | drm_crtc_send_vblank_event(&intel_crtc->base, work->event); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3821 | |
| 3822 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3823 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3824 | wake_up_all(&dev_priv->pending_flip_queue); |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 3825 | queue_work(dev_priv->wq, &work->unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3826 | |
| 3827 | trace_i915_flip_complete(intel_crtc->plane, |
| 3828 | work->pending_flip_obj); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3829 | } |
| 3830 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3831 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3832 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3833 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3834 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3835 | long ret; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3836 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3837 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3838 | |
| 3839 | ret = wait_event_interruptible_timeout( |
| 3840 | dev_priv->pending_flip_queue, |
| 3841 | !intel_crtc_has_pending_flip(crtc), |
| 3842 | 60*HZ); |
| 3843 | |
| 3844 | if (ret < 0) |
| 3845 | return ret; |
| 3846 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3847 | if (ret == 0) { |
| 3848 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3849 | struct intel_flip_work *work; |
| 3850 | |
| 3851 | spin_lock_irq(&dev->event_lock); |
| 3852 | work = intel_crtc->flip_work; |
| 3853 | if (work && !is_mmio_work(work)) { |
| 3854 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3855 | page_flip_completed(intel_crtc); |
| 3856 | } |
| 3857 | spin_unlock_irq(&dev->event_lock); |
| 3858 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3859 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3860 | return 0; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3861 | } |
| 3862 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3863 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
| 3864 | { |
| 3865 | u32 temp; |
| 3866 | |
| 3867 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3868 | |
| 3869 | mutex_lock(&dev_priv->sb_lock); |
| 3870 | |
| 3871 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3872 | temp |= SBI_SSCCTL_DISABLE; |
| 3873 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 3874 | |
| 3875 | mutex_unlock(&dev_priv->sb_lock); |
| 3876 | } |
| 3877 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3878 | /* Program iCLKIP clock to the desired frequency */ |
| 3879 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3880 | { |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3881 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3882 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3883 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3884 | u32 temp; |
| 3885 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3886 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3887 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3888 | /* The iCLK virtual clock root frequency is in MHz, |
| 3889 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3890 | * divisors, it is necessary to divide one by another, so we |
| 3891 | * convert the virtual clock precision to KHz here for higher |
| 3892 | * precision. |
| 3893 | */ |
| 3894 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3895 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3896 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3897 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3898 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3899 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3900 | clock << auxdiv); |
| 3901 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 3902 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3903 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3904 | /* |
| 3905 | * Near 20MHz is a corner case which is |
| 3906 | * out of range for the 7-bit divisor |
| 3907 | */ |
| 3908 | if (divsel <= 0x7f) |
| 3909 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | /* This should not happen with any sane values */ |
| 3913 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3914 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3915 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3916 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3917 | |
| 3918 | 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] | 3919 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3920 | auxdiv, |
| 3921 | divsel, |
| 3922 | phasedir, |
| 3923 | phaseinc); |
| 3924 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3925 | mutex_lock(&dev_priv->sb_lock); |
| 3926 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3927 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3928 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3929 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3930 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3931 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3932 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3933 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3934 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3935 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3936 | |
| 3937 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3938 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3939 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3940 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3941 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3942 | |
| 3943 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3944 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3945 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3946 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3947 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3948 | mutex_unlock(&dev_priv->sb_lock); |
| 3949 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3950 | /* Wait for initialization time */ |
| 3951 | udelay(24); |
| 3952 | |
| 3953 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 3954 | } |
| 3955 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 3956 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 3957 | { |
| 3958 | u32 divsel, phaseinc, auxdiv; |
| 3959 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3960 | u32 iclk_pi_range = 64; |
| 3961 | u32 desired_divisor; |
| 3962 | u32 temp; |
| 3963 | |
| 3964 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 3965 | return 0; |
| 3966 | |
| 3967 | mutex_lock(&dev_priv->sb_lock); |
| 3968 | |
| 3969 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3970 | if (temp & SBI_SSCCTL_DISABLE) { |
| 3971 | mutex_unlock(&dev_priv->sb_lock); |
| 3972 | return 0; |
| 3973 | } |
| 3974 | |
| 3975 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 3976 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 3977 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 3978 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 3979 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 3980 | |
| 3981 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 3982 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 3983 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 3984 | |
| 3985 | mutex_unlock(&dev_priv->sb_lock); |
| 3986 | |
| 3987 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 3988 | |
| 3989 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3990 | desired_divisor << auxdiv); |
| 3991 | } |
| 3992 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3993 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3994 | enum pipe pch_transcoder) |
| 3995 | { |
| 3996 | struct drm_device *dev = crtc->base.dev; |
| 3997 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3998 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3999 | |
| 4000 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4001 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4002 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4003 | I915_READ(HBLANK(cpu_transcoder))); |
| 4004 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4005 | I915_READ(HSYNC(cpu_transcoder))); |
| 4006 | |
| 4007 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4008 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4009 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4010 | I915_READ(VBLANK(cpu_transcoder))); |
| 4011 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4012 | I915_READ(VSYNC(cpu_transcoder))); |
| 4013 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4014 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4015 | } |
| 4016 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4017 | 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] | 4018 | { |
| 4019 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4020 | uint32_t temp; |
| 4021 | |
| 4022 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4023 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4024 | return; |
| 4025 | |
| 4026 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4027 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4028 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4029 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4030 | if (enable) |
| 4031 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4032 | |
| 4033 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4034 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4035 | POSTING_READ(SOUTH_CHICKEN1); |
| 4036 | } |
| 4037 | |
| 4038 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4039 | { |
| 4040 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4041 | |
| 4042 | switch (intel_crtc->pipe) { |
| 4043 | case PIPE_A: |
| 4044 | break; |
| 4045 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4046 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4047 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4048 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4049 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4050 | |
| 4051 | break; |
| 4052 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4053 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4054 | |
| 4055 | break; |
| 4056 | default: |
| 4057 | BUG(); |
| 4058 | } |
| 4059 | } |
| 4060 | |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4061 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 4062 | static enum port |
| 4063 | intel_trans_dp_port_sel(struct drm_crtc *crtc) |
| 4064 | { |
| 4065 | struct drm_device *dev = crtc->dev; |
| 4066 | struct intel_encoder *encoder; |
| 4067 | |
| 4068 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4069 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || |
| 4070 | encoder->type == INTEL_OUTPUT_EDP) |
| 4071 | return enc_to_dig_port(&encoder->base)->port; |
| 4072 | } |
| 4073 | |
| 4074 | return -1; |
| 4075 | } |
| 4076 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4077 | /* |
| 4078 | * Enable PCH resources required for PCH ports: |
| 4079 | * - PCH PLLs |
| 4080 | * - FDI training & RX/TX |
| 4081 | * - update transcoder timings |
| 4082 | * - DP transcoding bits |
| 4083 | * - transcoder |
| 4084 | */ |
| 4085 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4086 | { |
| 4087 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4088 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4089 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4090 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4091 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4092 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4093 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4094 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4095 | if (IS_IVYBRIDGE(dev)) |
| 4096 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4097 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4098 | /* Write the TU size bits before fdi link training, so that error |
| 4099 | * detection works. */ |
| 4100 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4101 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4102 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4103 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4104 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4105 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4106 | /* We need to program the right clock selection before writing the pixel |
| 4107 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4108 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4109 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4110 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4111 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4112 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4113 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4114 | if (intel_crtc->config->shared_dpll == |
| 4115 | 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] | 4116 | temp |= sel; |
| 4117 | else |
| 4118 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4119 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4120 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4121 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4122 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4123 | * transcoder, and we actually should do this to not upset any PCH |
| 4124 | * transcoder that already use the clock when we share it. |
| 4125 | * |
| 4126 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4127 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4128 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4129 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4130 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4131 | /* set transcoder timing, panel must allow it */ |
| 4132 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4133 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4134 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4135 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4136 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4137 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4138 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4139 | const struct drm_display_mode *adjusted_mode = |
| 4140 | &intel_crtc->config->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4141 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4142 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4143 | temp = I915_READ(reg); |
| 4144 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4145 | TRANS_DP_SYNC_MASK | |
| 4146 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4147 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4148 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4149 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4150 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4151 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4152 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4153 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4154 | |
| 4155 | switch (intel_trans_dp_port_sel(crtc)) { |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4156 | case PORT_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4157 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4158 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4159 | case PORT_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4160 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4161 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4162 | case PORT_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4163 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4164 | break; |
| 4165 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4166 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4169 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4172 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4175 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4176 | { |
| 4177 | struct drm_device *dev = crtc->dev; |
| 4178 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4180 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4181 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4182 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4183 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4184 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4185 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4186 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4187 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4188 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4189 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4192 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4193 | { |
| 4194 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4195 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4196 | u32 temp; |
| 4197 | |
| 4198 | temp = I915_READ(dslreg); |
| 4199 | udelay(500); |
| 4200 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4201 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4202 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4206 | static int |
| 4207 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
| 4208 | unsigned scaler_user, int *scaler_id, unsigned int rotation, |
| 4209 | int src_w, int src_h, int dst_w, int dst_h) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4210 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4211 | struct intel_crtc_scaler_state *scaler_state = |
| 4212 | &crtc_state->scaler_state; |
| 4213 | struct intel_crtc *intel_crtc = |
| 4214 | to_intel_crtc(crtc_state->base.crtc); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4215 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4216 | |
| 4217 | need_scaling = intel_rotation_90_or_270(rotation) ? |
| 4218 | (src_h != dst_w || src_w != dst_h): |
| 4219 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4220 | |
| 4221 | /* |
| 4222 | * if plane is being disabled or scaler is no more required or force detach |
| 4223 | * - free scaler binded to this plane/crtc |
| 4224 | * - in order to do this, update crtc->scaler_usage |
| 4225 | * |
| 4226 | * Here scaler state in crtc_state is set free so that |
| 4227 | * scaler can be assigned to other user. Actual register |
| 4228 | * update to free the scaler is done in plane/panel-fit programming. |
| 4229 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4230 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4231 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4232 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4233 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4234 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4235 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4236 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4237 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4238 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4239 | scaler_state->scaler_users); |
| 4240 | *scaler_id = -1; |
| 4241 | } |
| 4242 | return 0; |
| 4243 | } |
| 4244 | |
| 4245 | /* range checks */ |
| 4246 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4247 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4248 | |
| 4249 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4250 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4251 | 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] | 4252 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4253 | 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] | 4254 | return -EINVAL; |
| 4255 | } |
| 4256 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4257 | /* mark this plane as a scaler user in crtc_state */ |
| 4258 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4259 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4260 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4261 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4262 | scaler_state->scaler_users); |
| 4263 | |
| 4264 | return 0; |
| 4265 | } |
| 4266 | |
| 4267 | /** |
| 4268 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4269 | * |
| 4270 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4271 | * |
| 4272 | * Return |
| 4273 | * 0 - scaler_usage updated successfully |
| 4274 | * error - requested scaling cannot be supported or other error condition |
| 4275 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4276 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4277 | { |
| 4278 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4279 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4280 | |
| 4281 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", |
| 4282 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); |
| 4283 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4284 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Ville Syrjälä | fa5a797 | 2015-10-15 17:01:58 +0300 | [diff] [blame] | 4285 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4286 | state->pipe_src_w, state->pipe_src_h, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 4287 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
| 4292 | * |
| 4293 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4294 | * @plane_state: atomic plane state to update |
| 4295 | * |
| 4296 | * Return |
| 4297 | * 0 - scaler_usage updated successfully |
| 4298 | * error - requested scaling cannot be supported or other error condition |
| 4299 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4300 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4301 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4302 | { |
| 4303 | |
| 4304 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4305 | struct intel_plane *intel_plane = |
| 4306 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4307 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4308 | int ret; |
| 4309 | |
| 4310 | bool force_detach = !fb || !plane_state->visible; |
| 4311 | |
| 4312 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", |
| 4313 | intel_plane->base.base.id, intel_crtc->pipe, |
| 4314 | drm_plane_index(&intel_plane->base)); |
| 4315 | |
| 4316 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4317 | drm_plane_index(&intel_plane->base), |
| 4318 | &plane_state->scaler_id, |
| 4319 | plane_state->base.rotation, |
| 4320 | drm_rect_width(&plane_state->src) >> 16, |
| 4321 | drm_rect_height(&plane_state->src) >> 16, |
| 4322 | drm_rect_width(&plane_state->dst), |
| 4323 | drm_rect_height(&plane_state->dst)); |
| 4324 | |
| 4325 | if (ret || plane_state->scaler_id < 0) |
| 4326 | return ret; |
| 4327 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4328 | /* check colorkey */ |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4329 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4330 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4331 | intel_plane->base.base.id); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4332 | return -EINVAL; |
| 4333 | } |
| 4334 | |
| 4335 | /* Check src format */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4336 | switch (fb->pixel_format) { |
| 4337 | case DRM_FORMAT_RGB565: |
| 4338 | case DRM_FORMAT_XBGR8888: |
| 4339 | case DRM_FORMAT_XRGB8888: |
| 4340 | case DRM_FORMAT_ABGR8888: |
| 4341 | case DRM_FORMAT_ARGB8888: |
| 4342 | case DRM_FORMAT_XRGB2101010: |
| 4343 | case DRM_FORMAT_XBGR2101010: |
| 4344 | case DRM_FORMAT_YUYV: |
| 4345 | case DRM_FORMAT_YVYU: |
| 4346 | case DRM_FORMAT_UYVY: |
| 4347 | case DRM_FORMAT_VYUY: |
| 4348 | break; |
| 4349 | default: |
| 4350 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", |
| 4351 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); |
| 4352 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4353 | } |
| 4354 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4355 | return 0; |
| 4356 | } |
| 4357 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4358 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4359 | { |
| 4360 | int i; |
| 4361 | |
| 4362 | for (i = 0; i < crtc->num_scalers; i++) |
| 4363 | skl_detach_scaler(crtc, i); |
| 4364 | } |
| 4365 | |
| 4366 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4367 | { |
| 4368 | struct drm_device *dev = crtc->base.dev; |
| 4369 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4370 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4371 | struct intel_crtc_scaler_state *scaler_state = |
| 4372 | &crtc->config->scaler_state; |
| 4373 | |
| 4374 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4375 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4376 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4377 | int id; |
| 4378 | |
| 4379 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4380 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4381 | return; |
| 4382 | } |
| 4383 | |
| 4384 | id = scaler_state->scaler_id; |
| 4385 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4386 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4387 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4388 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4389 | |
| 4390 | 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] | 4391 | } |
| 4392 | } |
| 4393 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4394 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4395 | { |
| 4396 | struct drm_device *dev = crtc->base.dev; |
| 4397 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4398 | int pipe = crtc->pipe; |
| 4399 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4400 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4401 | /* Force use of hard-coded filter coefficients |
| 4402 | * as some pre-programmed values are broken, |
| 4403 | * e.g. x201. |
| 4404 | */ |
| 4405 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4406 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4407 | PF_PIPE_SEL_IVB(pipe)); |
| 4408 | else |
| 4409 | 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] | 4410 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4411 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4412 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4413 | } |
| 4414 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4415 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4416 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4417 | struct drm_device *dev = crtc->base.dev; |
| 4418 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4419 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4420 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4421 | return; |
| 4422 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 4423 | /* |
| 4424 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 4425 | * This function is called from post_plane_update, which is run after |
| 4426 | * a vblank wait. |
| 4427 | */ |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4428 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4429 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4430 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4431 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4432 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4433 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4434 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4435 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4436 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4437 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4438 | */ |
| 4439 | } else { |
| 4440 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4441 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4442 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4443 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4444 | * the HW state readout code will complain that the expected |
| 4445 | * IPS_CTL value is not the one we read. */ |
| 4446 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4447 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4448 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4449 | } |
| 4450 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4451 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4452 | { |
| 4453 | struct drm_device *dev = crtc->base.dev; |
| 4454 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4455 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4456 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4457 | return; |
| 4458 | |
| 4459 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4460 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4461 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4462 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4463 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4464 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4465 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4466 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4467 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4468 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4469 | POSTING_READ(IPS_CTL); |
| 4470 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4471 | |
| 4472 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4473 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4474 | } |
| 4475 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4476 | 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] | 4477 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4478 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4479 | struct drm_device *dev = intel_crtc->base.dev; |
| 4480 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4481 | |
| 4482 | mutex_lock(&dev->struct_mutex); |
| 4483 | dev_priv->mm.interruptible = false; |
| 4484 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4485 | dev_priv->mm.interruptible = true; |
| 4486 | mutex_unlock(&dev->struct_mutex); |
| 4487 | } |
| 4488 | |
| 4489 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4490 | * has to recompute where to put it anyway. |
| 4491 | */ |
| 4492 | } |
| 4493 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4494 | /** |
| 4495 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4496 | * @crtc: the CRTC whose primary plane was just enabled |
| 4497 | * |
| 4498 | * Performs potentially sleeping operations that must be done after the primary |
| 4499 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4500 | * called due to an explicit primary plane update, or due to an implicit |
| 4501 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4502 | * completely hide the primary plane. |
| 4503 | */ |
| 4504 | static void |
| 4505 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4506 | { |
| 4507 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4508 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4509 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4510 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4511 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4512 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4513 | * FIXME IPS should be fine as long as one plane is |
| 4514 | * enabled, but in practice it seems to have problems |
| 4515 | * when going from primary only to sprite only and vice |
| 4516 | * versa. |
| 4517 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4518 | hsw_enable_ips(intel_crtc); |
| 4519 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4520 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4521 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4522 | * So don't enable underrun reporting before at least some planes |
| 4523 | * are enabled. |
| 4524 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4525 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4526 | */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4527 | if (IS_GEN2(dev)) |
| 4528 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4529 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 4530 | /* Underruns don't always raise interrupts, so check manually. */ |
| 4531 | intel_check_cpu_fifo_underruns(dev_priv); |
| 4532 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4533 | } |
| 4534 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4535 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4536 | static void |
| 4537 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4538 | { |
| 4539 | struct drm_device *dev = crtc->dev; |
| 4540 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4541 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4542 | int pipe = intel_crtc->pipe; |
| 4543 | |
| 4544 | /* |
| 4545 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4546 | * So diasble underrun reporting before all the planes get disabled. |
| 4547 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4548 | * but leave the pipe running. |
| 4549 | */ |
| 4550 | if (IS_GEN2(dev)) |
| 4551 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4552 | |
| 4553 | /* |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4554 | * FIXME IPS should be fine as long as one plane is |
| 4555 | * enabled, but in practice it seems to have problems |
| 4556 | * when going from primary only to sprite only and vice |
| 4557 | * versa. |
| 4558 | */ |
| 4559 | hsw_disable_ips(intel_crtc); |
| 4560 | } |
| 4561 | |
| 4562 | /* FIXME get rid of this and use pre_plane_update */ |
| 4563 | static void |
| 4564 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 4565 | { |
| 4566 | struct drm_device *dev = crtc->dev; |
| 4567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4568 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4569 | int pipe = intel_crtc->pipe; |
| 4570 | |
| 4571 | intel_pre_disable_primary(crtc); |
| 4572 | |
| 4573 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4574 | * Vblank time updates from the shadow to live plane control register |
| 4575 | * are blocked if the memory self-refresh mode is active at that |
| 4576 | * moment. So to make sure the plane gets truly disabled, disable |
| 4577 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4578 | * will be checked/applied by the HW only at the next frame start |
| 4579 | * event which is after the vblank start event, so we need to have a |
| 4580 | * wait-for-vblank between disabling the plane and the pipe. |
| 4581 | */ |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4582 | if (HAS_GMCH_DISPLAY(dev)) { |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4583 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4584 | dev_priv->wm.vlv.cxsr = false; |
| 4585 | intel_wait_for_vblank(dev, pipe); |
| 4586 | } |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4587 | } |
| 4588 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4589 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 4590 | { |
| 4591 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 4592 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 4593 | struct intel_crtc_state *pipe_config = |
| 4594 | to_intel_crtc_state(crtc->base.state); |
| 4595 | struct drm_device *dev = crtc->base.dev; |
| 4596 | struct drm_plane *primary = crtc->base.primary; |
| 4597 | struct drm_plane_state *old_pri_state = |
| 4598 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 4599 | |
| 4600 | intel_frontbuffer_flip(dev, pipe_config->fb_bits); |
| 4601 | |
| 4602 | crtc->wm.cxsr_allowed = true; |
| 4603 | |
| 4604 | if (pipe_config->update_wm_post && pipe_config->base.active) |
| 4605 | intel_update_watermarks(&crtc->base); |
| 4606 | |
| 4607 | if (old_pri_state) { |
| 4608 | struct intel_plane_state *primary_state = |
| 4609 | to_intel_plane_state(primary->state); |
| 4610 | struct intel_plane_state *old_primary_state = |
| 4611 | to_intel_plane_state(old_pri_state); |
| 4612 | |
| 4613 | intel_fbc_post_update(crtc); |
| 4614 | |
| 4615 | if (primary_state->visible && |
| 4616 | (needs_modeset(&pipe_config->base) || |
| 4617 | !old_primary_state->visible)) |
| 4618 | intel_post_enable_primary(&crtc->base); |
| 4619 | } |
| 4620 | } |
| 4621 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4622 | 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] | 4623 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4624 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4625 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 4626 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4627 | struct intel_crtc_state *pipe_config = |
| 4628 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4629 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 4630 | struct drm_plane *primary = crtc->base.primary; |
| 4631 | struct drm_plane_state *old_pri_state = |
| 4632 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 4633 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4634 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4635 | if (old_pri_state) { |
| 4636 | struct intel_plane_state *primary_state = |
| 4637 | to_intel_plane_state(primary->state); |
| 4638 | struct intel_plane_state *old_primary_state = |
| 4639 | to_intel_plane_state(old_pri_state); |
| 4640 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4641 | intel_fbc_pre_update(crtc); |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 4642 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4643 | if (old_primary_state->visible && |
| 4644 | (modeset || !primary_state->visible)) |
| 4645 | intel_pre_disable_primary(&crtc->base); |
| 4646 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4647 | |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4648 | if (pipe_config->disable_cxsr) { |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4649 | crtc->wm.cxsr_allowed = false; |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4650 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4651 | /* |
| 4652 | * Vblank time updates from the shadow to live plane control register |
| 4653 | * are blocked if the memory self-refresh mode is active at that |
| 4654 | * moment. So to make sure the plane gets truly disabled, disable |
| 4655 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4656 | * will be checked/applied by the HW only at the next frame start |
| 4657 | * event which is after the vblank start event, so we need to have a |
| 4658 | * wait-for-vblank between disabling the plane and the pipe. |
| 4659 | */ |
| 4660 | if (old_crtc_state->base.active) { |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4661 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4662 | dev_priv->wm.vlv.cxsr = false; |
| 4663 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4664 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4665 | } |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4666 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4667 | /* |
| 4668 | * IVB workaround: must disable low power watermarks for at least |
| 4669 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 4670 | * when scaling is disabled. |
| 4671 | * |
| 4672 | * WaCxSRDisabledForSpriteScaling:ivb |
| 4673 | */ |
| 4674 | if (pipe_config->disable_lp_wm) { |
| 4675 | ilk_disable_lp_wm(dev); |
| 4676 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4677 | } |
| 4678 | |
| 4679 | /* |
| 4680 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 4681 | * watermark programming here. |
| 4682 | */ |
| 4683 | if (needs_modeset(&pipe_config->base)) |
| 4684 | return; |
| 4685 | |
| 4686 | /* |
| 4687 | * For platforms that support atomic watermarks, program the |
| 4688 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 4689 | * will be the intermediate values that are safe for both pre- and |
| 4690 | * post- vblank; when vblank happens, the 'active' values will be set |
| 4691 | * to the final 'target' values and we'll do this again to get the |
| 4692 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 4693 | * will be the final target values which will get automatically latched |
| 4694 | * at vblank time; no further programming will be necessary. |
| 4695 | * |
| 4696 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 4697 | * we'll continue to update watermarks the old way, if flags tell |
| 4698 | * us to. |
| 4699 | */ |
| 4700 | if (dev_priv->display.initial_watermarks != NULL) |
| 4701 | dev_priv->display.initial_watermarks(pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 4702 | else if (pipe_config->update_wm_pre) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4703 | intel_update_watermarks(&crtc->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4704 | } |
| 4705 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4706 | 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] | 4707 | { |
| 4708 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4709 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4710 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4711 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4712 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4713 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4714 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4715 | drm_for_each_plane_mask(p, dev, plane_mask) |
| 4716 | to_intel_plane(p)->disable_plane(p, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4717 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4718 | /* |
| 4719 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4720 | * to compute the mask of flip planes precisely. For the time being |
| 4721 | * consider this a flip to a NULL plane. |
| 4722 | */ |
| 4723 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4724 | } |
| 4725 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4726 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4727 | { |
| 4728 | struct drm_device *dev = crtc->dev; |
| 4729 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4730 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4731 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4732 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4733 | struct intel_crtc_state *pipe_config = |
| 4734 | to_intel_crtc_state(crtc->state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4735 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4736 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4737 | return; |
| 4738 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 4739 | /* |
| 4740 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 4741 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 4742 | * |
| 4743 | * On ILK we get an occasional spurious CPU pipe underruns |
| 4744 | * between eDP port A enable and vdd enable. Also PCH port |
| 4745 | * enable seems to result in the occasional CPU pipe underrun. |
| 4746 | * |
| 4747 | * Spurious PCH underruns also occur during PCH enabling. |
| 4748 | */ |
| 4749 | if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv)) |
| 4750 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4751 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4752 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4753 | |
| 4754 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4755 | intel_prepare_shared_dpll(intel_crtc); |
| 4756 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4757 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4758 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4759 | |
| 4760 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4761 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4762 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4763 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4764 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4765 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | ironlake_set_pipeconf(crtc); |
| 4769 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4770 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4771 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4772 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4773 | if (encoder->pre_enable) |
| 4774 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4775 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4776 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4777 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4778 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4779 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4780 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4781 | } else { |
| 4782 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4783 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4784 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4785 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4786 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4787 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4788 | /* |
| 4789 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4790 | * clocks enabled |
| 4791 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4792 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4793 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4794 | if (dev_priv->display.initial_watermarks != NULL) |
| 4795 | dev_priv->display.initial_watermarks(intel_crtc->config); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4796 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4797 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4798 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4799 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4800 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4801 | assert_vblank_disabled(crtc); |
| 4802 | drm_crtc_vblank_on(crtc); |
| 4803 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4804 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4805 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4806 | |
| 4807 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4808 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4809 | |
| 4810 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ |
| 4811 | if (intel_crtc->config->has_pch_encoder) |
| 4812 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 4813 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4814 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4815 | } |
| 4816 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4817 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4818 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4819 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4820 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4821 | } |
| 4822 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4823 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4824 | { |
| 4825 | struct drm_device *dev = crtc->dev; |
| 4826 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4827 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4828 | struct intel_encoder *encoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4829 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4830 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4831 | struct intel_crtc_state *pipe_config = |
| 4832 | to_intel_crtc_state(crtc->state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4833 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4834 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4835 | return; |
| 4836 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4837 | if (intel_crtc->config->has_pch_encoder) |
| 4838 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4839 | false); |
| 4840 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4841 | if (intel_crtc->config->shared_dpll) |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4842 | intel_enable_shared_dpll(intel_crtc); |
| 4843 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4844 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4845 | intel_dp_set_m_n(intel_crtc, M1_N1); |
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 (!intel_crtc->config->has_dsi_encoder) |
| 4848 | intel_set_pipe_timings(intel_crtc); |
| 4849 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4850 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4851 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4852 | if (cpu_transcoder != TRANSCODER_EDP && |
| 4853 | !transcoder_is_dsi(cpu_transcoder)) { |
| 4854 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4855 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4858 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4859 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4860 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4861 | } |
| 4862 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4863 | if (!intel_crtc->config->has_dsi_encoder) |
| 4864 | haswell_set_pipeconf(crtc); |
| 4865 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 4866 | haswell_set_pipemisc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4867 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4868 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4869 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4870 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4871 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4872 | if (intel_crtc->config->has_pch_encoder) |
| 4873 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4874 | else |
| 4875 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4876 | |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4877 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4878 | if (encoder->pre_enable) |
| 4879 | encoder->pre_enable(encoder); |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4880 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4881 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4882 | if (intel_crtc->config->has_pch_encoder) |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4883 | dev_priv->display.fdi_link_train(crtc); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4884 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4885 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4886 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4887 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4888 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4889 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4890 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4891 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4892 | |
| 4893 | /* |
| 4894 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4895 | * clocks enabled |
| 4896 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4897 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4898 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4899 | intel_ddi_set_pipe_settings(crtc); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4900 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4901 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4902 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4903 | if (dev_priv->display.initial_watermarks != NULL) |
| 4904 | dev_priv->display.initial_watermarks(pipe_config); |
| 4905 | else |
| 4906 | intel_update_watermarks(crtc); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4907 | |
| 4908 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 4909 | if (!intel_crtc->config->has_dsi_encoder) |
| 4910 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4911 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4912 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4913 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4914 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4915 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4916 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4917 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4918 | assert_vblank_disabled(crtc); |
| 4919 | drm_crtc_vblank_on(crtc); |
| 4920 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4921 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4922 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4923 | intel_opregion_notify_encoder(encoder, true); |
| 4924 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4925 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4926 | if (intel_crtc->config->has_pch_encoder) { |
| 4927 | intel_wait_for_vblank(dev, pipe); |
| 4928 | intel_wait_for_vblank(dev, pipe); |
| 4929 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4930 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4931 | true); |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4932 | } |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4933 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4934 | /* If we change the relative order between pipe/planes enabling, we need |
| 4935 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4936 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
| 4937 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { |
| 4938 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4939 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4940 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4941 | } |
| 4942 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4943 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4944 | { |
| 4945 | struct drm_device *dev = crtc->base.dev; |
| 4946 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4947 | int pipe = crtc->pipe; |
| 4948 | |
| 4949 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4950 | * 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] | 4951 | if (force || crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4952 | I915_WRITE(PF_CTL(pipe), 0); |
| 4953 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4954 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4955 | } |
| 4956 | } |
| 4957 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4958 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4959 | { |
| 4960 | struct drm_device *dev = crtc->dev; |
| 4961 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4962 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4963 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4964 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4965 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 4966 | /* |
| 4967 | * Sometimes spurious CPU pipe underruns happen when the |
| 4968 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 4969 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 4970 | */ |
| 4971 | if (intel_crtc->config->has_pch_encoder) { |
| 4972 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4973 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 4974 | } |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4975 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4976 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4977 | encoder->disable(encoder); |
| 4978 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4979 | drm_crtc_vblank_off(crtc); |
| 4980 | assert_vblank_disabled(crtc); |
| 4981 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4982 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4983 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4984 | ironlake_pfit_disable(intel_crtc, false); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4985 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 4986 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4987 | ironlake_fdi_disable(crtc); |
| 4988 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4989 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4990 | if (encoder->post_disable) |
| 4991 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4992 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4993 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4994 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4995 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4996 | if (HAS_PCH_CPT(dev)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4997 | i915_reg_t reg; |
| 4998 | u32 temp; |
| 4999 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5000 | /* disable TRANS_DP_CTL */ |
| 5001 | reg = TRANS_DP_CTL(pipe); |
| 5002 | temp = I915_READ(reg); |
| 5003 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5004 | TRANS_DP_PORT_SEL_MASK); |
| 5005 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5006 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5007 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5008 | /* disable DPLL_SEL */ |
| 5009 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5010 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5011 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5012 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5013 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5014 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5015 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5016 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5017 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5018 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5021 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 5022 | { |
| 5023 | struct drm_device *dev = crtc->dev; |
| 5024 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5025 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5026 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5027 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5028 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5029 | if (intel_crtc->config->has_pch_encoder) |
| 5030 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5031 | false); |
| 5032 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5033 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5034 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5035 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5036 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5037 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5038 | drm_crtc_vblank_off(crtc); |
| 5039 | assert_vblank_disabled(crtc); |
| 5040 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5041 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 5042 | if (!intel_crtc->config->has_dsi_encoder) |
| 5043 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5044 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5045 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5046 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5047 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5048 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5049 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5050 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 5051 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5052 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5053 | else |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5054 | ironlake_pfit_disable(intel_crtc, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5055 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5056 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5057 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5058 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 5059 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5060 | if (encoder->post_disable) |
| 5061 | encoder->post_disable(encoder); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5062 | |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5063 | if (intel_crtc->config->has_pch_encoder) { |
| 5064 | lpt_disable_pch_transcoder(dev_priv); |
Ville Syrjälä | 503a74e | 2015-12-04 22:22:14 +0200 | [diff] [blame] | 5065 | lpt_disable_iclkip(dev_priv); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5066 | intel_ddi_fdi_disable(crtc); |
| 5067 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5068 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5069 | true); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5070 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5071 | } |
| 5072 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5073 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5074 | { |
| 5075 | struct drm_device *dev = crtc->base.dev; |
| 5076 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5077 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5078 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5079 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5080 | return; |
| 5081 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5082 | /* |
| 5083 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5084 | * according to register description and PRM. |
| 5085 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5086 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5087 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5088 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5089 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5090 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5091 | |
| 5092 | /* Border color in case we don't scale up to the full screen. Black by |
| 5093 | * default, change to something else for debugging. */ |
| 5094 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5097 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5098 | { |
| 5099 | switch (port) { |
| 5100 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5101 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5102 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5103 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5104 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5105 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5106 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5107 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5108 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5109 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5110 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5111 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5112 | return POWER_DOMAIN_PORT_OTHER; |
| 5113 | } |
| 5114 | } |
| 5115 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5116 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
| 5117 | { |
| 5118 | switch (port) { |
| 5119 | case PORT_A: |
| 5120 | return POWER_DOMAIN_AUX_A; |
| 5121 | case PORT_B: |
| 5122 | return POWER_DOMAIN_AUX_B; |
| 5123 | case PORT_C: |
| 5124 | return POWER_DOMAIN_AUX_C; |
| 5125 | case PORT_D: |
| 5126 | return POWER_DOMAIN_AUX_D; |
| 5127 | case PORT_E: |
| 5128 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5129 | return POWER_DOMAIN_AUX_D; |
| 5130 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5131 | MISSING_CASE(port); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5132 | return POWER_DOMAIN_AUX_A; |
| 5133 | } |
| 5134 | } |
| 5135 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5136 | enum intel_display_power_domain |
| 5137 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5138 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5139 | struct drm_device *dev = intel_encoder->base.dev; |
| 5140 | struct intel_digital_port *intel_dig_port; |
| 5141 | |
| 5142 | switch (intel_encoder->type) { |
| 5143 | case INTEL_OUTPUT_UNKNOWN: |
| 5144 | /* Only DDI platforms should ever use this output type */ |
| 5145 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5146 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5147 | case INTEL_OUTPUT_HDMI: |
| 5148 | case INTEL_OUTPUT_EDP: |
| 5149 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5150 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5151 | case INTEL_OUTPUT_DP_MST: |
| 5152 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5153 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5154 | case INTEL_OUTPUT_ANALOG: |
| 5155 | return POWER_DOMAIN_PORT_CRT; |
| 5156 | case INTEL_OUTPUT_DSI: |
| 5157 | return POWER_DOMAIN_PORT_DSI; |
| 5158 | default: |
| 5159 | return POWER_DOMAIN_PORT_OTHER; |
| 5160 | } |
| 5161 | } |
| 5162 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5163 | enum intel_display_power_domain |
| 5164 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) |
| 5165 | { |
| 5166 | struct drm_device *dev = intel_encoder->base.dev; |
| 5167 | struct intel_digital_port *intel_dig_port; |
| 5168 | |
| 5169 | switch (intel_encoder->type) { |
| 5170 | case INTEL_OUTPUT_UNKNOWN: |
Imre Deak | 651174a | 2015-11-18 15:57:24 +0200 | [diff] [blame] | 5171 | case INTEL_OUTPUT_HDMI: |
| 5172 | /* |
| 5173 | * Only DDI platforms should ever use these output types. |
| 5174 | * We can get here after the HDMI detect code has already set |
| 5175 | * the type of the shared encoder. Since we can't be sure |
| 5176 | * what's the status of the given connectors, play safe and |
| 5177 | * run the DP detection too. |
| 5178 | */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5179 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5180 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5181 | case INTEL_OUTPUT_EDP: |
| 5182 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 5183 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5184 | case INTEL_OUTPUT_DP_MST: |
| 5185 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5186 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5187 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5188 | MISSING_CASE(intel_encoder->type); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5189 | return POWER_DOMAIN_AUX_A; |
| 5190 | } |
| 5191 | } |
| 5192 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5193 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
| 5194 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5195 | { |
| 5196 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5197 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5198 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5199 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5200 | unsigned long mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5201 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5202 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5203 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5204 | return 0; |
| 5205 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5206 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5207 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5208 | if (crtc_state->pch_pfit.enabled || |
| 5209 | crtc_state->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5210 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5211 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5212 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5213 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5214 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5215 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5216 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5217 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5218 | if (crtc_state->shared_dpll) |
| 5219 | mask |= BIT(POWER_DOMAIN_PLLS); |
| 5220 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5221 | return mask; |
| 5222 | } |
| 5223 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5224 | static unsigned long |
| 5225 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5226 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5227 | { |
| 5228 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5229 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5230 | enum intel_display_power_domain domain; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5231 | unsigned long domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5232 | |
| 5233 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5234 | intel_crtc->enabled_power_domains = new_domains = |
| 5235 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5236 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5237 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5238 | |
| 5239 | for_each_power_domain(domain, domains) |
| 5240 | intel_display_power_get(dev_priv, domain); |
| 5241 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5242 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
| 5246 | unsigned long domains) |
| 5247 | { |
| 5248 | enum intel_display_power_domain domain; |
| 5249 | |
| 5250 | for_each_power_domain(domain, domains) |
| 5251 | intel_display_power_put(dev_priv, domain); |
| 5252 | } |
| 5253 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5254 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
| 5255 | { |
| 5256 | int max_cdclk_freq = dev_priv->max_cdclk_freq; |
| 5257 | |
| 5258 | if (INTEL_INFO(dev_priv)->gen >= 9 || |
| 5259 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 5260 | return max_cdclk_freq; |
| 5261 | else if (IS_CHERRYVIEW(dev_priv)) |
| 5262 | return max_cdclk_freq*95/100; |
| 5263 | else if (INTEL_INFO(dev_priv)->gen < 4) |
| 5264 | return 2*max_cdclk_freq*90/100; |
| 5265 | else |
| 5266 | return max_cdclk_freq*90/100; |
| 5267 | } |
| 5268 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5269 | static int skl_calc_cdclk(int max_pixclk, int vco); |
| 5270 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5271 | static void intel_update_max_cdclk(struct drm_device *dev) |
| 5272 | { |
| 5273 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5274 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 5275 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5276 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5277 | int max_cdclk, vco; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5278 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5279 | vco = dev_priv->skl_preferred_vco_freq; |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5280 | WARN_ON(vco != 8100000 && vco != 8640000); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5281 | |
| 5282 | /* |
| 5283 | * Use the lower (vco 8640) cdclk values as a |
| 5284 | * first guess. skl_calc_cdclk() will correct it |
| 5285 | * if the preferred vco is 8100 instead. |
| 5286 | */ |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5287 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5288 | max_cdclk = 617143; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5289 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5290 | max_cdclk = 540000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5291 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5292 | max_cdclk = 432000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5293 | else |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5294 | max_cdclk = 308571; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5295 | |
| 5296 | dev_priv->max_cdclk_freq = skl_calc_cdclk(max_cdclk, vco); |
Matt Roper | 281c114 | 2016-04-05 14:37:19 -0700 | [diff] [blame] | 5297 | } else if (IS_BROXTON(dev)) { |
| 5298 | dev_priv->max_cdclk_freq = 624000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5299 | } else if (IS_BROADWELL(dev)) { |
| 5300 | /* |
| 5301 | * FIXME with extra cooling we can allow |
| 5302 | * 540 MHz for ULX and 675 Mhz for ULT. |
| 5303 | * How can we know if extra cooling is |
| 5304 | * available? PCI ID, VTB, something else? |
| 5305 | */ |
| 5306 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 5307 | dev_priv->max_cdclk_freq = 450000; |
| 5308 | else if (IS_BDW_ULX(dev)) |
| 5309 | dev_priv->max_cdclk_freq = 450000; |
| 5310 | else if (IS_BDW_ULT(dev)) |
| 5311 | dev_priv->max_cdclk_freq = 540000; |
| 5312 | else |
| 5313 | dev_priv->max_cdclk_freq = 675000; |
Mika Kahola | 0904dea | 2015-06-12 10:11:32 +0300 | [diff] [blame] | 5314 | } else if (IS_CHERRYVIEW(dev)) { |
| 5315 | dev_priv->max_cdclk_freq = 320000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5316 | } else if (IS_VALLEYVIEW(dev)) { |
| 5317 | dev_priv->max_cdclk_freq = 400000; |
| 5318 | } else { |
| 5319 | /* otherwise assume cdclk is fixed */ |
| 5320 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; |
| 5321 | } |
| 5322 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5323 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
| 5324 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5325 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
| 5326 | dev_priv->max_cdclk_freq); |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5327 | |
| 5328 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", |
| 5329 | dev_priv->max_dotclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | static void intel_update_cdclk(struct drm_device *dev) |
| 5333 | { |
| 5334 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5335 | |
| 5336 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
Ville Syrjälä | 2f2a121 | 2016-05-13 23:41:25 +0300 | [diff] [blame] | 5337 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5338 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 5339 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d kHz, ref: %d kHz\n", |
| 5340 | dev_priv->cdclk_freq, dev_priv->cdclk_pll.vco, |
| 5341 | dev_priv->cdclk_pll.ref); |
Ville Syrjälä | 2f2a121 | 2016-05-13 23:41:25 +0300 | [diff] [blame] | 5342 | else |
| 5343 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
| 5344 | dev_priv->cdclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5345 | |
| 5346 | /* |
Ville Syrjälä | b5d99ff | 2016-04-26 19:46:34 +0300 | [diff] [blame] | 5347 | * 9:0 CMBUS [sic] CDCLK frequency (cdfreq): |
| 5348 | * Programmng [sic] note: bit[9:2] should be programmed to the number |
| 5349 | * of cdclk that generates 4MHz reference clock freq which is used to |
| 5350 | * generate GMBus clock. This will vary with the cdclk freq. |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5351 | */ |
Ville Syrjälä | b5d99ff | 2016-04-26 19:46:34 +0300 | [diff] [blame] | 5352 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5353 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
Ville Syrjälä | 92891e4 | 2016-05-11 22:44:45 +0300 | [diff] [blame] | 5356 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5357 | static int skl_cdclk_decimal(int cdclk) |
| 5358 | { |
| 5359 | return DIV_ROUND_CLOSEST(cdclk - 1000, 500); |
| 5360 | } |
| 5361 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5362 | static int bxt_de_pll_vco(struct drm_i915_private *dev_priv, int cdclk) |
| 5363 | { |
| 5364 | int ratio; |
| 5365 | |
| 5366 | if (cdclk == dev_priv->cdclk_pll.ref) |
| 5367 | return 0; |
| 5368 | |
| 5369 | switch (cdclk) { |
| 5370 | default: |
| 5371 | MISSING_CASE(cdclk); |
| 5372 | case 144000: |
| 5373 | case 288000: |
| 5374 | case 384000: |
| 5375 | case 576000: |
| 5376 | ratio = 60; |
| 5377 | break; |
| 5378 | case 624000: |
| 5379 | ratio = 65; |
| 5380 | break; |
| 5381 | } |
| 5382 | |
| 5383 | return dev_priv->cdclk_pll.ref * ratio; |
| 5384 | } |
| 5385 | |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5386 | static void bxt_de_pll_disable(struct drm_i915_private *dev_priv) |
| 5387 | { |
| 5388 | I915_WRITE(BXT_DE_PLL_ENABLE, 0); |
| 5389 | |
| 5390 | /* Timeout 200us */ |
| 5391 | if (wait_for((I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK) == 0, 1)) |
| 5392 | DRM_ERROR("timeout waiting for DE PLL unlock\n"); |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5393 | |
| 5394 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5395 | } |
| 5396 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5397 | static void bxt_de_pll_enable(struct drm_i915_private *dev_priv, int vco) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5398 | { |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5399 | int ratio = DIV_ROUND_CLOSEST(vco, dev_priv->cdclk_pll.ref); |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5400 | u32 val; |
| 5401 | |
| 5402 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5403 | val &= ~BXT_DE_PLL_RATIO_MASK; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5404 | val |= BXT_DE_PLL_RATIO(ratio); |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5405 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5406 | |
| 5407 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5408 | |
| 5409 | /* Timeout 200us */ |
| 5410 | if (wait_for((I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK) != 0, 1)) |
| 5411 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5412 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5413 | dev_priv->cdclk_pll.vco = vco; |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5414 | } |
| 5415 | |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5416 | static void broxton_set_cdclk(struct drm_i915_private *dev_priv, int cdclk) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5417 | { |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5418 | u32 val, divider; |
| 5419 | int vco, ret; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5420 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5421 | vco = bxt_de_pll_vco(dev_priv, cdclk); |
| 5422 | |
| 5423 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); |
| 5424 | |
| 5425 | /* cdclk = vco / 2 / div{1,1.5,2,4} */ |
| 5426 | switch (DIV_ROUND_CLOSEST(vco, cdclk)) { |
| 5427 | case 8: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5428 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5429 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5430 | case 4: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5431 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5432 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5433 | case 3: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5434 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5435 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5436 | case 2: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5437 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5438 | break; |
| 5439 | default: |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5440 | WARN_ON(cdclk != dev_priv->cdclk_pll.ref); |
| 5441 | WARN_ON(vco != 0); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5442 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5443 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5444 | break; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5445 | } |
| 5446 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5447 | /* Inform power controller of upcoming frequency change */ |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5448 | mutex_lock(&dev_priv->rps.hw_lock); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5449 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5450 | 0x80000000); |
| 5451 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5452 | |
| 5453 | if (ret) { |
| 5454 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5455 | ret, cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5456 | return; |
| 5457 | } |
| 5458 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5459 | if (dev_priv->cdclk_pll.vco != 0 && |
| 5460 | dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5461 | bxt_de_pll_disable(dev_priv); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5462 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5463 | if (dev_priv->cdclk_pll.vco != vco) |
| 5464 | bxt_de_pll_enable(dev_priv, vco); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5465 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5466 | val = divider | skl_cdclk_decimal(cdclk); |
| 5467 | /* |
| 5468 | * FIXME if only the cd2x divider needs changing, it could be done |
| 5469 | * without shutting off the pipe (if only one pipe is active). |
| 5470 | */ |
| 5471 | val |= BXT_CDCLK_CD2X_PIPE_NONE; |
| 5472 | /* |
| 5473 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5474 | * enable otherwise. |
| 5475 | */ |
| 5476 | if (cdclk >= 500000) |
| 5477 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5478 | I915_WRITE(CDCLK_CTL, val); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5479 | |
| 5480 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5481 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5482 | DIV_ROUND_UP(cdclk, 25000)); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5483 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5484 | |
| 5485 | if (ret) { |
| 5486 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5487 | ret, cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5488 | return; |
| 5489 | } |
| 5490 | |
Imre Deak | c6c4696 | 2016-04-01 16:02:40 +0300 | [diff] [blame] | 5491 | intel_update_cdclk(dev_priv->dev); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5492 | } |
| 5493 | |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 5494 | static void bxt_sanitize_cdclk(struct drm_i915_private *dev_priv) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5495 | { |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 5496 | u32 cdctl, expected; |
| 5497 | |
Ville Syrjälä | 089c6fd | 2016-05-13 23:41:36 +0300 | [diff] [blame] | 5498 | intel_update_cdclk(dev_priv->dev); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5499 | |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 5500 | if (dev_priv->cdclk_pll.vco == 0 || |
| 5501 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) |
| 5502 | goto sanitize; |
| 5503 | |
| 5504 | /* DPLL okay; verify the cdclock |
| 5505 | * |
| 5506 | * Some BIOS versions leave an incorrect decimal frequency value and |
| 5507 | * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4, |
| 5508 | * so sanitize this register. |
| 5509 | */ |
| 5510 | cdctl = I915_READ(CDCLK_CTL); |
| 5511 | /* |
| 5512 | * Let's ignore the pipe field, since BIOS could have configured the |
| 5513 | * dividers both synching to an active pipe, or asynchronously |
| 5514 | * (PIPE_NONE). |
| 5515 | */ |
| 5516 | cdctl &= ~BXT_CDCLK_CD2X_PIPE_NONE; |
| 5517 | |
| 5518 | expected = (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) | |
| 5519 | skl_cdclk_decimal(dev_priv->cdclk_freq); |
| 5520 | /* |
| 5521 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5522 | * enable otherwise. |
| 5523 | */ |
| 5524 | if (dev_priv->cdclk_freq >= 500000) |
| 5525 | expected |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5526 | |
| 5527 | if (cdctl == expected) |
| 5528 | /* All well; nothing to sanitize */ |
| 5529 | return; |
| 5530 | |
| 5531 | sanitize: |
| 5532 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); |
| 5533 | |
| 5534 | /* force cdclk programming */ |
| 5535 | dev_priv->cdclk_freq = 0; |
| 5536 | |
| 5537 | /* force full PLL disable + enable */ |
| 5538 | dev_priv->cdclk_pll.vco = -1; |
| 5539 | } |
| 5540 | |
| 5541 | void broxton_init_cdclk(struct drm_i915_private *dev_priv) |
| 5542 | { |
| 5543 | bxt_sanitize_cdclk(dev_priv); |
| 5544 | |
| 5545 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) |
Ville Syrjälä | 089c6fd | 2016-05-13 23:41:36 +0300 | [diff] [blame] | 5546 | return; |
Imre Deak | c2e001e | 2016-04-01 16:02:43 +0300 | [diff] [blame] | 5547 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5548 | /* |
| 5549 | * FIXME: |
| 5550 | * - The initial CDCLK needs to be read from VBT. |
| 5551 | * Need to make this change after VBT has changes for BXT. |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5552 | */ |
Ville Syrjälä | d1b32c3 | 2016-05-13 23:41:40 +0300 | [diff] [blame] | 5553 | broxton_set_cdclk(dev_priv, broxton_calc_cdclk(0)); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5554 | } |
| 5555 | |
Imre Deak | c6c4696 | 2016-04-01 16:02:40 +0300 | [diff] [blame] | 5556 | void broxton_uninit_cdclk(struct drm_i915_private *dev_priv) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5557 | { |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5558 | broxton_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5559 | } |
| 5560 | |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5561 | static int skl_calc_cdclk(int max_pixclk, int vco) |
| 5562 | { |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5563 | if (vco == 8640000) { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5564 | if (max_pixclk > 540000) |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5565 | return 617143; |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5566 | else if (max_pixclk > 432000) |
| 5567 | return 540000; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5568 | else if (max_pixclk > 308571) |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5569 | return 432000; |
| 5570 | else |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5571 | return 308571; |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5572 | } else { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5573 | if (max_pixclk > 540000) |
| 5574 | return 675000; |
| 5575 | else if (max_pixclk > 450000) |
| 5576 | return 540000; |
| 5577 | else if (max_pixclk > 337500) |
| 5578 | return 450000; |
| 5579 | else |
| 5580 | return 337500; |
| 5581 | } |
| 5582 | } |
| 5583 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5584 | static void |
| 5585 | skl_dpll0_update(struct drm_i915_private *dev_priv) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5586 | { |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5587 | u32 val; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5588 | |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 5589 | dev_priv->cdclk_pll.ref = 24000; |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 5590 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 5591 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5592 | val = I915_READ(LCPLL1_CTL); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 5593 | if ((val & LCPLL_PLL_ENABLE) == 0) |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5594 | return; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5595 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 5596 | if (WARN_ON((val & LCPLL_PLL_LOCK) == 0)) |
| 5597 | return; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5598 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5599 | val = I915_READ(DPLL_CTRL1); |
| 5600 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 5601 | if (WARN_ON((val & (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | |
| 5602 | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 5603 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) != |
| 5604 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) |
| 5605 | return; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5606 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5607 | switch (val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) { |
| 5608 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, SKL_DPLL0): |
| 5609 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, SKL_DPLL0): |
| 5610 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, SKL_DPLL0): |
| 5611 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, SKL_DPLL0): |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5612 | dev_priv->cdclk_pll.vco = 8100000; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5613 | break; |
| 5614 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, SKL_DPLL0): |
| 5615 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160, SKL_DPLL0): |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5616 | dev_priv->cdclk_pll.vco = 8640000; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5617 | break; |
| 5618 | default: |
| 5619 | MISSING_CASE(val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 5620 | break; |
| 5621 | } |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5622 | } |
| 5623 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5624 | void skl_set_preferred_cdclk_vco(struct drm_i915_private *dev_priv, int vco) |
| 5625 | { |
| 5626 | bool changed = dev_priv->skl_preferred_vco_freq != vco; |
| 5627 | |
| 5628 | dev_priv->skl_preferred_vco_freq = vco; |
| 5629 | |
| 5630 | if (changed) |
| 5631 | intel_update_max_cdclk(dev_priv->dev); |
| 5632 | } |
| 5633 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5634 | static void |
Ville Syrjälä | 3861fc6 | 2016-05-11 22:44:50 +0300 | [diff] [blame] | 5635 | skl_dpll0_enable(struct drm_i915_private *dev_priv, int vco) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5636 | { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5637 | int min_cdclk = skl_calc_cdclk(0, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5638 | u32 val; |
| 5639 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5640 | WARN_ON(vco != 8100000 && vco != 8640000); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5641 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5642 | /* select the minimum CDCLK before enabling DPLL 0 */ |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5643 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_cdclk); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5644 | I915_WRITE(CDCLK_CTL, val); |
| 5645 | POSTING_READ(CDCLK_CTL); |
| 5646 | |
| 5647 | /* |
| 5648 | * We always enable DPLL0 with the lowest link rate possible, but still |
| 5649 | * taking into account the VCO required to operate the eDP panel at the |
| 5650 | * desired frequency. The usual DP link rates operate with a VCO of |
| 5651 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. |
| 5652 | * The modeset code is responsible for the selection of the exact link |
| 5653 | * rate later on, with the constraint of choosing a frequency that |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 5654 | * works with vco. |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5655 | */ |
| 5656 | val = I915_READ(DPLL_CTRL1); |
| 5657 | |
| 5658 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 5659 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
| 5660 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5661 | if (vco == 8640000) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5662 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
| 5663 | SKL_DPLL0); |
| 5664 | else |
| 5665 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
| 5666 | SKL_DPLL0); |
| 5667 | |
| 5668 | I915_WRITE(DPLL_CTRL1, val); |
| 5669 | POSTING_READ(DPLL_CTRL1); |
| 5670 | |
| 5671 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); |
| 5672 | |
| 5673 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) |
| 5674 | DRM_ERROR("DPLL0 not locked\n"); |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5675 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5676 | dev_priv->cdclk_pll.vco = vco; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5677 | |
| 5678 | /* We'll want to keep using the current vco from now on. */ |
| 5679 | skl_set_preferred_cdclk_vco(dev_priv, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
Ville Syrjälä | 430e05d | 2016-05-11 22:44:47 +0300 | [diff] [blame] | 5682 | static void |
| 5683 | skl_dpll0_disable(struct drm_i915_private *dev_priv) |
| 5684 | { |
| 5685 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); |
| 5686 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) |
| 5687 | DRM_ERROR("Couldn't disable DPLL0\n"); |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5688 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5689 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 430e05d | 2016-05-11 22:44:47 +0300 | [diff] [blame] | 5690 | } |
| 5691 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5692 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) |
| 5693 | { |
| 5694 | int ret; |
| 5695 | u32 val; |
| 5696 | |
| 5697 | /* inform PCU we want to change CDCLK */ |
| 5698 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; |
| 5699 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5700 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); |
| 5701 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5702 | |
| 5703 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); |
| 5704 | } |
| 5705 | |
| 5706 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) |
| 5707 | { |
| 5708 | unsigned int i; |
| 5709 | |
| 5710 | for (i = 0; i < 15; i++) { |
| 5711 | if (skl_cdclk_pcu_ready(dev_priv)) |
| 5712 | return true; |
| 5713 | udelay(10); |
| 5714 | } |
| 5715 | |
| 5716 | return false; |
| 5717 | } |
| 5718 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5719 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, int cdclk, int vco) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5720 | { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5721 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5722 | u32 freq_select, pcu_ack; |
| 5723 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5724 | WARN_ON((cdclk == 24000) != (vco == 0)); |
| 5725 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5726 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5727 | |
| 5728 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { |
| 5729 | DRM_ERROR("failed to inform PCU about cdclk change\n"); |
| 5730 | return; |
| 5731 | } |
| 5732 | |
| 5733 | /* set CDCLK_CTL */ |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5734 | switch (cdclk) { |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5735 | case 450000: |
| 5736 | case 432000: |
| 5737 | freq_select = CDCLK_FREQ_450_432; |
| 5738 | pcu_ack = 1; |
| 5739 | break; |
| 5740 | case 540000: |
| 5741 | freq_select = CDCLK_FREQ_540; |
| 5742 | pcu_ack = 2; |
| 5743 | break; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5744 | case 308571: |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5745 | case 337500: |
| 5746 | default: |
| 5747 | freq_select = CDCLK_FREQ_337_308; |
| 5748 | pcu_ack = 0; |
| 5749 | break; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5750 | case 617143: |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5751 | case 675000: |
| 5752 | freq_select = CDCLK_FREQ_675_617; |
| 5753 | pcu_ack = 3; |
| 5754 | break; |
| 5755 | } |
| 5756 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5757 | if (dev_priv->cdclk_pll.vco != 0 && |
| 5758 | dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5759 | skl_dpll0_disable(dev_priv); |
| 5760 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5761 | if (dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5762 | skl_dpll0_enable(dev_priv, vco); |
| 5763 | |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 5764 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(cdclk)); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5765 | POSTING_READ(CDCLK_CTL); |
| 5766 | |
| 5767 | /* inform PCU of the change */ |
| 5768 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5769 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); |
| 5770 | mutex_unlock(&dev_priv->rps.hw_lock); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5771 | |
| 5772 | intel_update_cdclk(dev); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5775 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv); |
| 5776 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5777 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
| 5778 | { |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 5779 | skl_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref, 0); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5780 | } |
| 5781 | |
| 5782 | void skl_init_cdclk(struct drm_i915_private *dev_priv) |
| 5783 | { |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5784 | int cdclk, vco; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5785 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5786 | skl_sanitize_cdclk(dev_priv); |
| 5787 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5788 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) { |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5789 | /* |
| 5790 | * Use the current vco as our initial |
| 5791 | * guess as to what the preferred vco is. |
| 5792 | */ |
| 5793 | if (dev_priv->skl_preferred_vco_freq == 0) |
| 5794 | skl_set_preferred_cdclk_vco(dev_priv, |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5795 | dev_priv->cdclk_pll.vco); |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 5796 | return; |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 5797 | } |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5798 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 5799 | vco = dev_priv->skl_preferred_vco_freq; |
| 5800 | if (vco == 0) |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5801 | vco = 8100000; |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 5802 | cdclk = skl_calc_cdclk(0, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5803 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 5804 | skl_set_cdclk(dev_priv, cdclk, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5805 | } |
| 5806 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5807 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5808 | { |
Ville Syrjälä | 0949249 | 2016-05-13 23:41:28 +0300 | [diff] [blame] | 5809 | uint32_t cdctl, expected; |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5810 | |
Shobhit Kumar | f1b391a | 2015-11-05 18:05:32 +0530 | [diff] [blame] | 5811 | /* |
| 5812 | * check if the pre-os intialized the display |
| 5813 | * There is SWF18 scratchpad register defined which is set by the |
| 5814 | * pre-os which can be used by the OS drivers to check the status |
| 5815 | */ |
| 5816 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) |
| 5817 | goto sanitize; |
| 5818 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5819 | intel_update_cdclk(dev_priv->dev); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 5820 | /* Is PLL enabled and locked ? */ |
| 5821 | if (dev_priv->cdclk_pll.vco == 0 || |
| 5822 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) |
| 5823 | goto sanitize; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5824 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5825 | /* DPLL okay; verify the cdclock |
| 5826 | * |
| 5827 | * Noticed in some instances that the freq selection is correct but |
| 5828 | * decimal part is programmed wrong from BIOS where pre-os does not |
| 5829 | * enable display. Verify the same as well. |
| 5830 | */ |
Ville Syrjälä | 0949249 | 2016-05-13 23:41:28 +0300 | [diff] [blame] | 5831 | cdctl = I915_READ(CDCLK_CTL); |
| 5832 | expected = (cdctl & CDCLK_FREQ_SEL_MASK) | |
| 5833 | skl_cdclk_decimal(dev_priv->cdclk_freq); |
| 5834 | if (cdctl == expected) |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5835 | /* All well; nothing to sanitize */ |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5836 | return; |
| 5837 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5838 | sanitize: |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5839 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 5840 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 5841 | /* force cdclk programming */ |
| 5842 | dev_priv->cdclk_freq = 0; |
| 5843 | /* force full PLL disable + enable */ |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5844 | dev_priv->cdclk_pll.vco = -1; |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5845 | } |
| 5846 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5847 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5848 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5849 | { |
| 5850 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5851 | u32 val, cmd; |
| 5852 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5853 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5854 | != dev_priv->cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5855 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5856 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5857 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5858 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5859 | cmd = 1; |
| 5860 | else |
| 5861 | cmd = 0; |
| 5862 | |
| 5863 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5864 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5865 | val &= ~DSPFREQGUAR_MASK; |
| 5866 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5867 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5868 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5869 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5870 | 50)) { |
| 5871 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5872 | } |
| 5873 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5874 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5875 | mutex_lock(&dev_priv->sb_lock); |
| 5876 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5877 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5878 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5879 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5880 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5881 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5882 | /* adjust cdclk divider */ |
| 5883 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5884 | val &= ~CCK_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5885 | val |= divider; |
| 5886 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5887 | |
| 5888 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5889 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5890 | 50)) |
| 5891 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5892 | } |
| 5893 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5894 | /* adjust self-refresh exit latency value */ |
| 5895 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5896 | val &= ~0x7f; |
| 5897 | |
| 5898 | /* |
| 5899 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5900 | * so that the core display fetch happens in time to avoid underruns. |
| 5901 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5902 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5903 | val |= 4500 / 250; /* 4.5 usec */ |
| 5904 | else |
| 5905 | val |= 3000 / 250; /* 3.0 usec */ |
| 5906 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5907 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5908 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5909 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5910 | intel_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5911 | } |
| 5912 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5913 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5914 | { |
| 5915 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5916 | u32 val, cmd; |
| 5917 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5918 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5919 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5920 | |
| 5921 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5922 | case 333333: |
| 5923 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5924 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5925 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5926 | break; |
| 5927 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5928 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5929 | return; |
| 5930 | } |
| 5931 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5932 | /* |
| 5933 | * Specs are full of misinformation, but testing on actual |
| 5934 | * hardware has shown that we just need to write the desired |
| 5935 | * CCK divider into the Punit register. |
| 5936 | */ |
| 5937 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5938 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5939 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5940 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5941 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5942 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5943 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5944 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5945 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5946 | 50)) { |
| 5947 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5948 | } |
| 5949 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5950 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5951 | intel_update_cdclk(dev); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5952 | } |
| 5953 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5954 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5955 | int max_pixclk) |
| 5956 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5957 | 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] | 5958 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5959 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5960 | /* |
| 5961 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5962 | * 200MHz |
| 5963 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5964 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5965 | * 400MHz (VLV only) |
| 5966 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5967 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5968 | * |
| 5969 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5970 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5971 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5972 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5973 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5974 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5975 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5976 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5977 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5978 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5979 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5980 | else |
| 5981 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5982 | } |
| 5983 | |
Ville Syrjälä | c44deb6 | 2016-05-11 22:44:43 +0300 | [diff] [blame] | 5984 | static int broxton_calc_cdclk(int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5985 | { |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 5986 | if (max_pixclk > 576000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5987 | return 624000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 5988 | else if (max_pixclk > 384000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5989 | return 576000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 5990 | else if (max_pixclk > 288000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5991 | return 384000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 5992 | else if (max_pixclk > 144000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5993 | return 288000; |
| 5994 | else |
| 5995 | return 144000; |
| 5996 | } |
| 5997 | |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 5998 | /* Compute the max pixel clock for new configuration. */ |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5999 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 6000 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6001 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6002 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 6003 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6004 | struct drm_crtc *crtc; |
| 6005 | struct drm_crtc_state *crtc_state; |
| 6006 | unsigned max_pixclk = 0, i; |
| 6007 | enum pipe pipe; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6008 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6009 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 6010 | sizeof(intel_state->min_pixclk)); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6011 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6012 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 6013 | int pixclk = 0; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6014 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6015 | if (crtc_state->enable) |
| 6016 | pixclk = crtc_state->adjusted_mode.crtc_clock; |
| 6017 | |
| 6018 | intel_state->min_pixclk[i] = pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6019 | } |
| 6020 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6021 | for_each_pipe(dev_priv, pipe) |
| 6022 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); |
| 6023 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6024 | return max_pixclk; |
| 6025 | } |
| 6026 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6027 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6028 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6029 | struct drm_device *dev = state->dev; |
| 6030 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6031 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6032 | struct intel_atomic_state *intel_state = |
| 6033 | to_intel_atomic_state(state); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6034 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6035 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6036 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6037 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6038 | if (!intel_state->active_crtcs) |
| 6039 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); |
| 6040 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6041 | return 0; |
| 6042 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6043 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6044 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 6045 | { |
Ville Syrjälä | 4e5ca60 | 2016-05-11 22:44:44 +0300 | [diff] [blame] | 6046 | int max_pixclk = ilk_max_pixel_rate(state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6047 | struct intel_atomic_state *intel_state = |
| 6048 | to_intel_atomic_state(state); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 6049 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6050 | intel_state->cdclk = intel_state->dev_cdclk = |
Ville Syrjälä | c44deb6 | 2016-05-11 22:44:43 +0300 | [diff] [blame] | 6051 | broxton_calc_cdclk(max_pixclk); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 6052 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6053 | if (!intel_state->active_crtcs) |
Ville Syrjälä | c44deb6 | 2016-05-11 22:44:43 +0300 | [diff] [blame] | 6054 | intel_state->dev_cdclk = broxton_calc_cdclk(0); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6055 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6056 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6057 | } |
| 6058 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6059 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 6060 | { |
| 6061 | unsigned int credits, default_credits; |
| 6062 | |
| 6063 | if (IS_CHERRYVIEW(dev_priv)) |
| 6064 | default_credits = PFI_CREDIT(12); |
| 6065 | else |
| 6066 | default_credits = PFI_CREDIT(8); |
| 6067 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6068 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6069 | /* CHV suggested value is 31 or 63 */ |
| 6070 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | fcc0008 | 2015-05-26 20:22:40 +0300 | [diff] [blame] | 6071 | credits = PFI_CREDIT_63; |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6072 | else |
| 6073 | credits = PFI_CREDIT(15); |
| 6074 | } else { |
| 6075 | credits = default_credits; |
| 6076 | } |
| 6077 | |
| 6078 | /* |
| 6079 | * WA - write default credits before re-programming |
| 6080 | * FIXME: should we also set the resend bit here? |
| 6081 | */ |
| 6082 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6083 | default_credits); |
| 6084 | |
| 6085 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6086 | credits | PFI_CREDIT_RESEND); |
| 6087 | |
| 6088 | /* |
| 6089 | * FIXME is this guaranteed to clear |
| 6090 | * immediately or should we poll for it? |
| 6091 | */ |
| 6092 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 6093 | } |
| 6094 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6095 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6096 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 6097 | struct drm_device *dev = old_state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6098 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6099 | struct intel_atomic_state *old_intel_state = |
| 6100 | to_intel_atomic_state(old_state); |
| 6101 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6102 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6103 | /* |
| 6104 | * FIXME: We can end up here with all power domains off, yet |
| 6105 | * with a CDCLK frequency other than the minimum. To account |
| 6106 | * for this take the PIPE-A power domain, which covers the HW |
| 6107 | * blocks needed for the following programming. This can be |
| 6108 | * removed once it's guaranteed that we get here either with |
| 6109 | * the minimum CDCLK set, or the required power domains |
| 6110 | * enabled. |
| 6111 | */ |
| 6112 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6113 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6114 | if (IS_CHERRYVIEW(dev)) |
| 6115 | cherryview_set_cdclk(dev, req_cdclk); |
| 6116 | else |
| 6117 | valleyview_set_cdclk(dev, req_cdclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6118 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6119 | vlv_program_pfi_credits(dev_priv); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 6120 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6121 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6122 | } |
| 6123 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6124 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 6125 | { |
| 6126 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6127 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6128 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6129 | struct intel_encoder *encoder; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6130 | struct intel_crtc_state *pipe_config = |
| 6131 | to_intel_crtc_state(crtc->state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6132 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6133 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6134 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6135 | return; |
| 6136 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6137 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6138 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6139 | |
| 6140 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6141 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6142 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6143 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 6144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6145 | |
| 6146 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6147 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6148 | } |
| 6149 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6150 | i9xx_set_pipeconf(intel_crtc); |
| 6151 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6152 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6153 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6154 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6155 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6156 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6157 | if (encoder->pre_pll_enable) |
| 6158 | encoder->pre_pll_enable(encoder); |
| 6159 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6160 | if (IS_CHERRYVIEW(dev)) { |
| 6161 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
| 6162 | chv_enable_pll(intel_crtc, intel_crtc->config); |
| 6163 | } else { |
| 6164 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
| 6165 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6166 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6167 | |
| 6168 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6169 | if (encoder->pre_enable) |
| 6170 | encoder->pre_enable(encoder); |
| 6171 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6172 | i9xx_pfit_enable(intel_crtc); |
| 6173 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6174 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6175 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 6176 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6177 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6178 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6179 | assert_vblank_disabled(crtc); |
| 6180 | drm_crtc_vblank_on(crtc); |
| 6181 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6182 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6183 | encoder->enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6184 | } |
| 6185 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6186 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 6187 | { |
| 6188 | struct drm_device *dev = crtc->base.dev; |
| 6189 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6190 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6191 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 6192 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6193 | } |
| 6194 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6195 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6196 | { |
| 6197 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6198 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6199 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6200 | struct intel_encoder *encoder; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6201 | struct intel_crtc_state *pipe_config = |
| 6202 | to_intel_crtc_state(crtc->state); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6203 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6204 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6205 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6206 | return; |
| 6207 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6208 | i9xx_set_pll_dividers(intel_crtc); |
| 6209 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6210 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6211 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6212 | |
| 6213 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6214 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6215 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6216 | i9xx_set_pipeconf(intel_crtc); |
| 6217 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6218 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6219 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6220 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6221 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6222 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 6223 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6224 | if (encoder->pre_enable) |
| 6225 | encoder->pre_enable(encoder); |
| 6226 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6227 | i9xx_enable_pll(intel_crtc); |
| 6228 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6229 | i9xx_pfit_enable(intel_crtc); |
| 6230 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6231 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6232 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 6233 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6234 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6235 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6236 | assert_vblank_disabled(crtc); |
| 6237 | drm_crtc_vblank_on(crtc); |
| 6238 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6239 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6240 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6241 | } |
| 6242 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6243 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6244 | { |
| 6245 | struct drm_device *dev = crtc->base.dev; |
| 6246 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6247 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6248 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6249 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6250 | |
| 6251 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6252 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6253 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6254 | I915_READ(PFIT_CONTROL)); |
| 6255 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6256 | } |
| 6257 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6258 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 6259 | { |
| 6260 | struct drm_device *dev = crtc->dev; |
| 6261 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6262 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6263 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6264 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6265 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6266 | /* |
| 6267 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6268 | * wait for planes to fully turn off before disabling the pipe. |
| 6269 | */ |
Ander Conselvan de Oliveira | 90e83e5 | 2016-03-22 10:11:24 +0200 | [diff] [blame] | 6270 | if (IS_GEN2(dev)) |
| 6271 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6272 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6273 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6274 | encoder->disable(encoder); |
| 6275 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6276 | drm_crtc_vblank_off(crtc); |
| 6277 | assert_vblank_disabled(crtc); |
| 6278 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6279 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6280 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6281 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6282 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6283 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6284 | if (encoder->post_disable) |
| 6285 | encoder->post_disable(encoder); |
| 6286 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 6287 | if (!intel_crtc->config->has_dsi_encoder) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6288 | if (IS_CHERRYVIEW(dev)) |
| 6289 | chv_disable_pll(dev_priv, pipe); |
| 6290 | else if (IS_VALLEYVIEW(dev)) |
| 6291 | vlv_disable_pll(dev_priv, pipe); |
| 6292 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6293 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6294 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6295 | |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6296 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6297 | if (encoder->post_pll_disable) |
| 6298 | encoder->post_pll_disable(encoder); |
| 6299 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6300 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6301 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6302 | } |
| 6303 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6304 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6305 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6306 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6307 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6308 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6309 | enum intel_display_power_domain domain; |
| 6310 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6311 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6312 | if (!intel_crtc->active) |
| 6313 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6314 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6315 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6316 | WARN_ON(intel_crtc->flip_work); |
Maarten Lankhorst | fc32b1f | 2015-10-19 17:09:23 +0200 | [diff] [blame] | 6317 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 6318 | intel_pre_disable_primary_noatomic(crtc); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6319 | |
| 6320 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); |
| 6321 | to_intel_plane_state(crtc->primary->state)->visible = false; |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6322 | } |
| 6323 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6324 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6325 | |
| 6326 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was enabled, now disabled\n", |
| 6327 | crtc->base.id); |
| 6328 | |
| 6329 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6330 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6331 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6332 | crtc->enabled = false; |
| 6333 | crtc->state->connector_mask = 0; |
| 6334 | crtc->state->encoder_mask = 0; |
| 6335 | |
| 6336 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6337 | encoder->base.crtc = NULL; |
| 6338 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6339 | intel_fbc_disable(intel_crtc); |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6340 | intel_update_watermarks(crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6341 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6342 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6343 | domains = intel_crtc->enabled_power_domains; |
| 6344 | for_each_power_domain(domain, domains) |
| 6345 | intel_display_power_put(dev_priv, domain); |
| 6346 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6347 | |
| 6348 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
| 6349 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6350 | } |
| 6351 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6352 | /* |
| 6353 | * turn all crtc's off, but do not adjust state |
| 6354 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6355 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6356 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6357 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6358 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6359 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6360 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6361 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6362 | state = drm_atomic_helper_suspend(dev); |
| 6363 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6364 | if (ret) |
| 6365 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6366 | else |
| 6367 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6368 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6369 | } |
| 6370 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6371 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6372 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6373 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6374 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6375 | drm_encoder_cleanup(encoder); |
| 6376 | kfree(intel_encoder); |
| 6377 | } |
| 6378 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6379 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6380 | * internal consistency). */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6381 | static void intel_connector_verify_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6382 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6383 | struct drm_crtc *crtc = connector->base.state->crtc; |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6384 | |
| 6385 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6386 | connector->base.base.id, |
| 6387 | connector->base.name); |
| 6388 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6389 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6390 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6391 | struct drm_connector_state *conn_state = connector->base.state; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6392 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6393 | I915_STATE_WARN(!crtc, |
| 6394 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6395 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6396 | if (!crtc) |
| 6397 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6398 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6399 | I915_STATE_WARN(!crtc->state->active, |
| 6400 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6401 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6402 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6403 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6404 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6405 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6406 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6407 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6408 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6409 | "attached encoder crtc differs from connector crtc\n"); |
| 6410 | } else { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6411 | I915_STATE_WARN(crtc && crtc->state->active, |
| 6412 | "attached crtc is active, but connector isn't\n"); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6413 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6414 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6415 | } |
| 6416 | } |
| 6417 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6418 | int intel_connector_init(struct intel_connector *connector) |
| 6419 | { |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6420 | drm_atomic_helper_connector_reset(&connector->base); |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6421 | |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6422 | if (!connector->base.state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6423 | return -ENOMEM; |
| 6424 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6425 | return 0; |
| 6426 | } |
| 6427 | |
| 6428 | struct intel_connector *intel_connector_alloc(void) |
| 6429 | { |
| 6430 | struct intel_connector *connector; |
| 6431 | |
| 6432 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6433 | if (!connector) |
| 6434 | return NULL; |
| 6435 | |
| 6436 | if (intel_connector_init(connector) < 0) { |
| 6437 | kfree(connector); |
| 6438 | return NULL; |
| 6439 | } |
| 6440 | |
| 6441 | return connector; |
| 6442 | } |
| 6443 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6444 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6445 | * one connector and no cloning and hence the encoder state determines the state |
| 6446 | * of the connector. */ |
| 6447 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6448 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6449 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6450 | struct intel_encoder *encoder = connector->encoder; |
| 6451 | |
| 6452 | return encoder->get_hw_state(encoder, &pipe); |
| 6453 | } |
| 6454 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6455 | 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] | 6456 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6457 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6458 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6459 | |
| 6460 | return 0; |
| 6461 | } |
| 6462 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6463 | 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] | 6464 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6465 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6466 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6467 | struct intel_crtc *other_crtc; |
| 6468 | struct intel_crtc_state *other_crtc_state; |
| 6469 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6470 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6471 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6472 | if (pipe_config->fdi_lanes > 4) { |
| 6473 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6474 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6475 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6476 | } |
| 6477 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 6478 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6479 | if (pipe_config->fdi_lanes > 2) { |
| 6480 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6481 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6482 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6483 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6484 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6485 | } |
| 6486 | } |
| 6487 | |
| 6488 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6489 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6490 | |
| 6491 | /* Ivybridge 3 pipe is really complicated */ |
| 6492 | switch (pipe) { |
| 6493 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6494 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6495 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6496 | if (pipe_config->fdi_lanes <= 2) |
| 6497 | return 0; |
| 6498 | |
| 6499 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 6500 | other_crtc_state = |
| 6501 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6502 | if (IS_ERR(other_crtc_state)) |
| 6503 | return PTR_ERR(other_crtc_state); |
| 6504 | |
| 6505 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6506 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6507 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6508 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6509 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6510 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6511 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6512 | if (pipe_config->fdi_lanes > 2) { |
| 6513 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6514 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6515 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6516 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6517 | |
| 6518 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 6519 | other_crtc_state = |
| 6520 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6521 | if (IS_ERR(other_crtc_state)) |
| 6522 | return PTR_ERR(other_crtc_state); |
| 6523 | |
| 6524 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6525 | 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] | 6526 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6527 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6528 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6529 | default: |
| 6530 | BUG(); |
| 6531 | } |
| 6532 | } |
| 6533 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6534 | #define RETRY 1 |
| 6535 | 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] | 6536 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6537 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6538 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6539 | 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] | 6540 | int lane, link_bw, fdi_dotclock, ret; |
| 6541 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6542 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6543 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6544 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6545 | * each output octet as 10 bits. The actual frequency |
| 6546 | * is stored as a divider into a 100MHz clock, and the |
| 6547 | * mode pixel clock is stored in units of 1KHz. |
| 6548 | * Hence the bw of each lane in terms of the mode signal |
| 6549 | * is: |
| 6550 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6551 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6552 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6553 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6554 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6555 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6556 | pipe_config->pipe_bpp); |
| 6557 | |
| 6558 | pipe_config->fdi_lanes = lane; |
| 6559 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6560 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6561 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6562 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6563 | 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] | 6564 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6565 | pipe_config->pipe_bpp -= 2*3; |
| 6566 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6567 | pipe_config->pipe_bpp); |
| 6568 | needs_recompute = true; |
| 6569 | pipe_config->bw_constrained = true; |
| 6570 | |
| 6571 | goto retry; |
| 6572 | } |
| 6573 | |
| 6574 | if (needs_recompute) |
| 6575 | return RETRY; |
| 6576 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6577 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6578 | } |
| 6579 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6580 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
| 6581 | struct intel_crtc_state *pipe_config) |
| 6582 | { |
| 6583 | if (pipe_config->pipe_bpp > 24) |
| 6584 | return false; |
| 6585 | |
| 6586 | /* HSW can handle pixel rate up to cdclk? */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 6587 | if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6588 | return true; |
| 6589 | |
| 6590 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6591 | * We compare against max which means we must take |
| 6592 | * the increased cdclk requirement into account when |
| 6593 | * calculating the new cdclk. |
| 6594 | * |
| 6595 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6596 | */ |
| 6597 | return ilk_pipe_pixel_rate(pipe_config) <= |
| 6598 | dev_priv->max_cdclk_freq * 95 / 100; |
| 6599 | } |
| 6600 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6601 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6602 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6603 | { |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6604 | struct drm_device *dev = crtc->base.dev; |
| 6605 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6606 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6607 | pipe_config->ips_enabled = i915.enable_ips && |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6608 | hsw_crtc_supports_ips(crtc) && |
| 6609 | pipe_config_supports_ips(dev_priv, pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6610 | } |
| 6611 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6612 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6613 | { |
| 6614 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6615 | |
| 6616 | /* GDG double wide on either pipe, otherwise pipe A only */ |
| 6617 | return INTEL_INFO(dev_priv)->gen < 4 && |
| 6618 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6619 | } |
| 6620 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6621 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6622 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6623 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6624 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 6625 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6626 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6627 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6628 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6629 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6630 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6631 | |
| 6632 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6633 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6634 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6635 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6636 | if (intel_crtc_supports_double_wide(crtc) && |
| 6637 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6638 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6639 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6640 | } |
| 6641 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6642 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6643 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6644 | adjusted_mode->crtc_clock, clock_limit, |
| 6645 | yesno(pipe_config->double_wide)); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6646 | return -EINVAL; |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6647 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6648 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6649 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6650 | /* |
| 6651 | * Pipe horizontal size must be even in: |
| 6652 | * - DVO ganged mode |
| 6653 | * - LVDS dual channel mode |
| 6654 | * - Double wide pipe |
| 6655 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6656 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6657 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 6658 | pipe_config->pipe_src_w &= ~1; |
| 6659 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6660 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6661 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6662 | */ |
| 6663 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6664 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6665 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6666 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 6667 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6668 | hsw_compute_ips_config(crtc, pipe_config); |
| 6669 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6670 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6671 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6672 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6673 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6674 | } |
| 6675 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6676 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 6677 | { |
| 6678 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6679 | uint32_t cdctl; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6680 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6681 | skl_dpll0_update(dev_priv); |
| 6682 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6683 | if (dev_priv->cdclk_pll.vco == 0) |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 6684 | return dev_priv->cdclk_pll.ref; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6685 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6686 | cdctl = I915_READ(CDCLK_CTL); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6687 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6688 | if (dev_priv->cdclk_pll.vco == 8640000) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6689 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6690 | case CDCLK_FREQ_450_432: |
| 6691 | return 432000; |
| 6692 | case CDCLK_FREQ_337_308: |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6693 | return 308571; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6694 | case CDCLK_FREQ_540: |
| 6695 | return 540000; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6696 | case CDCLK_FREQ_675_617: |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6697 | return 617143; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6698 | default: |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6699 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6700 | } |
| 6701 | } else { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6702 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6703 | case CDCLK_FREQ_450_432: |
| 6704 | return 450000; |
| 6705 | case CDCLK_FREQ_337_308: |
| 6706 | return 337500; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6707 | case CDCLK_FREQ_540: |
| 6708 | return 540000; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6709 | case CDCLK_FREQ_675_617: |
| 6710 | return 675000; |
| 6711 | default: |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6712 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6713 | } |
| 6714 | } |
| 6715 | |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 6716 | return dev_priv->cdclk_pll.ref; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6717 | } |
| 6718 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6719 | static void bxt_de_pll_update(struct drm_i915_private *dev_priv) |
| 6720 | { |
| 6721 | u32 val; |
| 6722 | |
| 6723 | dev_priv->cdclk_pll.ref = 19200; |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6724 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6725 | |
| 6726 | val = I915_READ(BXT_DE_PLL_ENABLE); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6727 | if ((val & BXT_DE_PLL_PLL_ENABLE) == 0) |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6728 | return; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6729 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6730 | if (WARN_ON((val & BXT_DE_PLL_LOCK) == 0)) |
| 6731 | return; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6732 | |
| 6733 | val = I915_READ(BXT_DE_PLL_CTL); |
| 6734 | dev_priv->cdclk_pll.vco = (val & BXT_DE_PLL_RATIO_MASK) * |
| 6735 | dev_priv->cdclk_pll.ref; |
| 6736 | } |
| 6737 | |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6738 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
| 6739 | { |
| 6740 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6741 | u32 divider; |
| 6742 | int div, vco; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6743 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 6744 | bxt_de_pll_update(dev_priv); |
| 6745 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6746 | vco = dev_priv->cdclk_pll.vco; |
| 6747 | if (vco == 0) |
| 6748 | return dev_priv->cdclk_pll.ref; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6749 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6750 | divider = I915_READ(CDCLK_CTL) & BXT_CDCLK_CD2X_DIV_SEL_MASK; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6751 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6752 | switch (divider) { |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6753 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6754 | div = 2; |
| 6755 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6756 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6757 | div = 3; |
| 6758 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6759 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6760 | div = 4; |
| 6761 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6762 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6763 | div = 8; |
| 6764 | break; |
| 6765 | default: |
| 6766 | MISSING_CASE(divider); |
| 6767 | return dev_priv->cdclk_pll.ref; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6768 | } |
| 6769 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 6770 | return DIV_ROUND_CLOSEST(vco, div); |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6771 | } |
| 6772 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6773 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 6774 | { |
| 6775 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6776 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6777 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6778 | |
| 6779 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6780 | return 800000; |
| 6781 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6782 | return 450000; |
| 6783 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6784 | return 450000; |
| 6785 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6786 | return 540000; |
| 6787 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6788 | return 337500; |
| 6789 | else |
| 6790 | return 675000; |
| 6791 | } |
| 6792 | |
| 6793 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6794 | { |
| 6795 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6796 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6797 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6798 | |
| 6799 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6800 | return 800000; |
| 6801 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6802 | return 450000; |
| 6803 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6804 | return 450000; |
| 6805 | else if (IS_HSW_ULT(dev)) |
| 6806 | return 337500; |
| 6807 | else |
| 6808 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6809 | } |
| 6810 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6811 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6812 | { |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6813 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
| 6814 | CCK_DISPLAY_CLOCK_CONTROL); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6817 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6818 | { |
| 6819 | return 450000; |
| 6820 | } |
| 6821 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6822 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6823 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6824 | return 400000; |
| 6825 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6826 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6827 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 6828 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6829 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6830 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6831 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6832 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6833 | { |
| 6834 | return 200000; |
| 6835 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6836 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6837 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6838 | { |
| 6839 | u16 gcfgc = 0; |
| 6840 | |
| 6841 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6842 | |
| 6843 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6844 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6845 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6846 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6847 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6848 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6849 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6850 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6851 | return 200000; |
| 6852 | default: |
| 6853 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6854 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6855 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6856 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6857 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6858 | } |
| 6859 | } |
| 6860 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6861 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6862 | { |
| 6863 | u16 gcfgc = 0; |
| 6864 | |
| 6865 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6866 | |
| 6867 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6868 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6869 | else { |
| 6870 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6871 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6872 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6873 | default: |
| 6874 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6875 | return 190000; |
| 6876 | } |
| 6877 | } |
| 6878 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6879 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6880 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6881 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6882 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6883 | } |
| 6884 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6885 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6886 | { |
| 6887 | u16 hpllcc = 0; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6888 | |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 6889 | /* |
| 6890 | * 852GM/852GMV only supports 133 MHz and the HPLLCC |
| 6891 | * encoding is different :( |
| 6892 | * FIXME is this the right way to detect 852GM/852GMV? |
| 6893 | */ |
| 6894 | if (dev->pdev->revision == 0x1) |
| 6895 | return 133333; |
| 6896 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6897 | pci_bus_read_config_word(dev->pdev->bus, |
| 6898 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); |
| 6899 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6900 | /* Assume that the hardware is in the high speed state. This |
| 6901 | * should be the default. |
| 6902 | */ |
| 6903 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6904 | case GC_CLOCK_133_200: |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6905 | case GC_CLOCK_133_200_2: |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6906 | case GC_CLOCK_100_200: |
| 6907 | return 200000; |
| 6908 | case GC_CLOCK_166_250: |
| 6909 | return 250000; |
| 6910 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6911 | return 133333; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6912 | case GC_CLOCK_133_266: |
| 6913 | case GC_CLOCK_133_266_2: |
| 6914 | case GC_CLOCK_166_266: |
| 6915 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
| 6918 | /* Shouldn't happen */ |
| 6919 | return 0; |
| 6920 | } |
| 6921 | |
| 6922 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6923 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6924 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6925 | } |
| 6926 | |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6927 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
| 6928 | { |
| 6929 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6930 | static const unsigned int blb_vco[8] = { |
| 6931 | [0] = 3200000, |
| 6932 | [1] = 4000000, |
| 6933 | [2] = 5333333, |
| 6934 | [3] = 4800000, |
| 6935 | [4] = 6400000, |
| 6936 | }; |
| 6937 | static const unsigned int pnv_vco[8] = { |
| 6938 | [0] = 3200000, |
| 6939 | [1] = 4000000, |
| 6940 | [2] = 5333333, |
| 6941 | [3] = 4800000, |
| 6942 | [4] = 2666667, |
| 6943 | }; |
| 6944 | static const unsigned int cl_vco[8] = { |
| 6945 | [0] = 3200000, |
| 6946 | [1] = 4000000, |
| 6947 | [2] = 5333333, |
| 6948 | [3] = 6400000, |
| 6949 | [4] = 3333333, |
| 6950 | [5] = 3566667, |
| 6951 | [6] = 4266667, |
| 6952 | }; |
| 6953 | static const unsigned int elk_vco[8] = { |
| 6954 | [0] = 3200000, |
| 6955 | [1] = 4000000, |
| 6956 | [2] = 5333333, |
| 6957 | [3] = 4800000, |
| 6958 | }; |
| 6959 | static const unsigned int ctg_vco[8] = { |
| 6960 | [0] = 3200000, |
| 6961 | [1] = 4000000, |
| 6962 | [2] = 5333333, |
| 6963 | [3] = 6400000, |
| 6964 | [4] = 2666667, |
| 6965 | [5] = 4266667, |
| 6966 | }; |
| 6967 | const unsigned int *vco_table; |
| 6968 | unsigned int vco; |
| 6969 | uint8_t tmp = 0; |
| 6970 | |
| 6971 | /* FIXME other chipsets? */ |
| 6972 | if (IS_GM45(dev)) |
| 6973 | vco_table = ctg_vco; |
| 6974 | else if (IS_G4X(dev)) |
| 6975 | vco_table = elk_vco; |
| 6976 | else if (IS_CRESTLINE(dev)) |
| 6977 | vco_table = cl_vco; |
| 6978 | else if (IS_PINEVIEW(dev)) |
| 6979 | vco_table = pnv_vco; |
| 6980 | else if (IS_G33(dev)) |
| 6981 | vco_table = blb_vco; |
| 6982 | else |
| 6983 | return 0; |
| 6984 | |
| 6985 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); |
| 6986 | |
| 6987 | vco = vco_table[tmp & 0x7]; |
| 6988 | if (vco == 0) |
| 6989 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); |
| 6990 | else |
| 6991 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); |
| 6992 | |
| 6993 | return vco; |
| 6994 | } |
| 6995 | |
| 6996 | static int gm45_get_display_clock_speed(struct drm_device *dev) |
| 6997 | { |
| 6998 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6999 | uint16_t tmp = 0; |
| 7000 | |
| 7001 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 7002 | |
| 7003 | cdclk_sel = (tmp >> 12) & 0x1; |
| 7004 | |
| 7005 | switch (vco) { |
| 7006 | case 2666667: |
| 7007 | case 4000000: |
| 7008 | case 5333333: |
| 7009 | return cdclk_sel ? 333333 : 222222; |
| 7010 | case 3200000: |
| 7011 | return cdclk_sel ? 320000 : 228571; |
| 7012 | default: |
| 7013 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); |
| 7014 | return 222222; |
| 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | static int i965gm_get_display_clock_speed(struct drm_device *dev) |
| 7019 | { |
| 7020 | static const uint8_t div_3200[] = { 16, 10, 8 }; |
| 7021 | static const uint8_t div_4000[] = { 20, 12, 10 }; |
| 7022 | static const uint8_t div_5333[] = { 24, 16, 14 }; |
| 7023 | const uint8_t *div_table; |
| 7024 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 7025 | uint16_t tmp = 0; |
| 7026 | |
| 7027 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 7028 | |
| 7029 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; |
| 7030 | |
| 7031 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 7032 | goto fail; |
| 7033 | |
| 7034 | switch (vco) { |
| 7035 | case 3200000: |
| 7036 | div_table = div_3200; |
| 7037 | break; |
| 7038 | case 4000000: |
| 7039 | div_table = div_4000; |
| 7040 | break; |
| 7041 | case 5333333: |
| 7042 | div_table = div_5333; |
| 7043 | break; |
| 7044 | default: |
| 7045 | goto fail; |
| 7046 | } |
| 7047 | |
| 7048 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 7049 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 7050 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7051 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
| 7052 | return 200000; |
| 7053 | } |
| 7054 | |
| 7055 | static int g33_get_display_clock_speed(struct drm_device *dev) |
| 7056 | { |
| 7057 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; |
| 7058 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; |
| 7059 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; |
| 7060 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; |
| 7061 | const uint8_t *div_table; |
| 7062 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 7063 | uint16_t tmp = 0; |
| 7064 | |
| 7065 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 7066 | |
| 7067 | cdclk_sel = (tmp >> 4) & 0x7; |
| 7068 | |
| 7069 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 7070 | goto fail; |
| 7071 | |
| 7072 | switch (vco) { |
| 7073 | case 3200000: |
| 7074 | div_table = div_3200; |
| 7075 | break; |
| 7076 | case 4000000: |
| 7077 | div_table = div_4000; |
| 7078 | break; |
| 7079 | case 4800000: |
| 7080 | div_table = div_4800; |
| 7081 | break; |
| 7082 | case 5333333: |
| 7083 | div_table = div_5333; |
| 7084 | break; |
| 7085 | default: |
| 7086 | goto fail; |
| 7087 | } |
| 7088 | |
| 7089 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 7090 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 7091 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7092 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
| 7093 | return 190476; |
| 7094 | } |
| 7095 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7096 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7097 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7098 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7099 | while (*num > DATA_LINK_M_N_MASK || |
| 7100 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7101 | *num >>= 1; |
| 7102 | *den >>= 1; |
| 7103 | } |
| 7104 | } |
| 7105 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7106 | static void compute_m_n(unsigned int m, unsigned int n, |
| 7107 | uint32_t *ret_m, uint32_t *ret_n) |
| 7108 | { |
| 7109 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 7110 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 7111 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 7112 | } |
| 7113 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7114 | void |
| 7115 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 7116 | int pixel_clock, int link_clock, |
| 7117 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7118 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7119 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7120 | |
| 7121 | compute_m_n(bits_per_pixel * pixel_clock, |
| 7122 | link_clock * nlanes * 8, |
| 7123 | &m_n->gmch_m, &m_n->gmch_n); |
| 7124 | |
| 7125 | compute_m_n(pixel_clock, link_clock, |
| 7126 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7127 | } |
| 7128 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7129 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 7130 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7131 | if (i915.panel_use_ssc >= 0) |
| 7132 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7133 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 7134 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7137 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7138 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 7139 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7140 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7141 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7142 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 7143 | { |
| 7144 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7145 | } |
| 7146 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7147 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7148 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7149 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7150 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7151 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7152 | u32 fp, fp2 = 0; |
| 7153 | |
| 7154 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7155 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7156 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7157 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7158 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7159 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7160 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7161 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7162 | } |
| 7163 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7164 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7165 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7166 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7167 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7168 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7169 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7170 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7171 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7172 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7173 | } |
| 7174 | } |
| 7175 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7176 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 7177 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7178 | { |
| 7179 | u32 reg_val; |
| 7180 | |
| 7181 | /* |
| 7182 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 7183 | * and set it to a reasonable value instead. |
| 7184 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7185 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7186 | reg_val &= 0xffffff00; |
| 7187 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7188 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7189 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7190 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7191 | reg_val &= 0x8cffffff; |
| 7192 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7193 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7194 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7195 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7196 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7197 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7198 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7199 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7200 | reg_val &= 0x00ffffff; |
| 7201 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7202 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7203 | } |
| 7204 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7205 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 7206 | struct intel_link_m_n *m_n) |
| 7207 | { |
| 7208 | struct drm_device *dev = crtc->base.dev; |
| 7209 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7210 | int pipe = crtc->pipe; |
| 7211 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7212 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7213 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7214 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7215 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7216 | } |
| 7217 | |
| 7218 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7219 | struct intel_link_m_n *m_n, |
| 7220 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7221 | { |
| 7222 | struct drm_device *dev = crtc->base.dev; |
| 7223 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7224 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7225 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7226 | |
| 7227 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7228 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7229 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7230 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7231 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7232 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 7233 | * for gen < 8) and if DRRS is supported (to make sure the |
| 7234 | * registers are not unnecessarily accessed). |
| 7235 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 7236 | 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] | 7237 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7238 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7239 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7240 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7241 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7242 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7243 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7244 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7245 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7246 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7247 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7248 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7249 | } |
| 7250 | } |
| 7251 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7252 | 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] | 7253 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7254 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 7255 | |
| 7256 | if (m_n == M1_N1) { |
| 7257 | dp_m_n = &crtc->config->dp_m_n; |
| 7258 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 7259 | } else if (m_n == M2_N2) { |
| 7260 | |
| 7261 | /* |
| 7262 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7263 | * needs to be programmed into M1_N1. |
| 7264 | */ |
| 7265 | dp_m_n = &crtc->config->dp_m2_n2; |
| 7266 | } else { |
| 7267 | DRM_ERROR("Unsupported divider value\n"); |
| 7268 | return; |
| 7269 | } |
| 7270 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7271 | if (crtc->config->has_pch_encoder) |
| 7272 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7273 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7274 | 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] | 7275 | } |
| 7276 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7277 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7278 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7279 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7280 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7281 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7282 | if (crtc->pipe != PIPE_A) |
| 7283 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7284 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7285 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | 187a1c0 | 2016-04-18 20:34:04 +0300 | [diff] [blame] | 7286 | if (!pipe_config->has_dsi_encoder) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7287 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 7288 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 7289 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7290 | pipe_config->dpll_hw_state.dpll_md = |
| 7291 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 7292 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7293 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7294 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7295 | struct intel_crtc_state *pipe_config) |
| 7296 | { |
| 7297 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7298 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7299 | if (crtc->pipe != PIPE_A) |
| 7300 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7301 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7302 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | 187a1c0 | 2016-04-18 20:34:04 +0300 | [diff] [blame] | 7303 | if (!pipe_config->has_dsi_encoder) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7304 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 7305 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7306 | pipe_config->dpll_hw_state.dpll_md = |
| 7307 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7308 | } |
| 7309 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7310 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7311 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7312 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7313 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7314 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7315 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7316 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7317 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7318 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7319 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7320 | /* Enable Refclk */ |
| 7321 | I915_WRITE(DPLL(pipe), |
| 7322 | pipe_config->dpll_hw_state.dpll & |
| 7323 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7324 | |
| 7325 | /* No need to actually set up the DPLL with DSI */ |
| 7326 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7327 | return; |
| 7328 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7329 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7330 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7331 | bestn = pipe_config->dpll.n; |
| 7332 | bestm1 = pipe_config->dpll.m1; |
| 7333 | bestm2 = pipe_config->dpll.m2; |
| 7334 | bestp1 = pipe_config->dpll.p1; |
| 7335 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7336 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7337 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7338 | |
| 7339 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7340 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7341 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7342 | |
| 7343 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7344 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7345 | |
| 7346 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7347 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7348 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7349 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7350 | |
| 7351 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7352 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7353 | |
| 7354 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7355 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7356 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7357 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7358 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7359 | |
| 7360 | /* |
| 7361 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7362 | * but we don't support that). |
| 7363 | * Note: don't use the DAC post divider as it seems unstable. |
| 7364 | */ |
| 7365 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7366 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7367 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7368 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7369 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7370 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7371 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7372 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7373 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 7374 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7375 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7376 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7377 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7378 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7379 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7380 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7381 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7382 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7383 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7384 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7385 | 0x0df40000); |
| 7386 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7387 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7388 | 0x0df70000); |
| 7389 | } else { /* HDMI or VGA */ |
| 7390 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7391 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7392 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7393 | 0x0df70000); |
| 7394 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7395 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7396 | 0x0df40000); |
| 7397 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7398 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7399 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7400 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7401 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 7402 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7403 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7404 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7405 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7406 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7407 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7408 | } |
| 7409 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7410 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7411 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7412 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7413 | struct drm_device *dev = crtc->base.dev; |
| 7414 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7415 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7416 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7417 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7418 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7419 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7420 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7421 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7422 | /* Enable Refclk and SSC */ |
| 7423 | I915_WRITE(DPLL(pipe), |
| 7424 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7425 | |
| 7426 | /* No need to actually set up the DPLL with DSI */ |
| 7427 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7428 | return; |
| 7429 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7430 | bestn = pipe_config->dpll.n; |
| 7431 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7432 | bestm1 = pipe_config->dpll.m1; |
| 7433 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7434 | bestp1 = pipe_config->dpll.p1; |
| 7435 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7436 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7437 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7438 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7439 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7440 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7441 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7442 | /* p1 and p2 divider */ |
| 7443 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7444 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7445 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7446 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7447 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7448 | |
| 7449 | /* Feedback post-divider - m2 */ |
| 7450 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7451 | |
| 7452 | /* Feedback refclk divider - n and m1 */ |
| 7453 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7454 | DPIO_CHV_M1_DIV_BY_2 | |
| 7455 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7456 | |
| 7457 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7458 | 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] | 7459 | |
| 7460 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7461 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7462 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7463 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7464 | if (bestm2_frac) |
| 7465 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7466 | 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] | 7467 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7468 | /* Program digital lock detect threshold */ |
| 7469 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7470 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7471 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7472 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7473 | if (!bestm2_frac) |
| 7474 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7475 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7476 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7477 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7478 | if (vco == 5400000) { |
| 7479 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7480 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7481 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7482 | tribuf_calcntr = 0x9; |
| 7483 | } else if (vco <= 6200000) { |
| 7484 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7485 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7486 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7487 | tribuf_calcntr = 0x9; |
| 7488 | } else if (vco <= 6480000) { |
| 7489 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7490 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7491 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7492 | tribuf_calcntr = 0x8; |
| 7493 | } else { |
| 7494 | /* Not supported. Apply the same limits as in the max case */ |
| 7495 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7496 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7497 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7498 | tribuf_calcntr = 0; |
| 7499 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7500 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7501 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7502 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7503 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7504 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7505 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7506 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7507 | /* AFC Recal */ |
| 7508 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7509 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7510 | DPIO_AFC_RECAL); |
| 7511 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7512 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7513 | } |
| 7514 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7515 | /** |
| 7516 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7517 | * @dev_priv: i915 private structure |
| 7518 | * @pipe: pipe PLL to enable |
| 7519 | * @dpll: PLL configuration |
| 7520 | * |
| 7521 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7522 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7523 | * be enabled. |
| 7524 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7525 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 7526 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7527 | { |
| 7528 | struct intel_crtc *crtc = |
| 7529 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7530 | struct intel_crtc_state *pipe_config; |
| 7531 | |
| 7532 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7533 | if (!pipe_config) |
| 7534 | return -ENOMEM; |
| 7535 | |
| 7536 | pipe_config->base.crtc = &crtc->base; |
| 7537 | pipe_config->pixel_multiplier = 1; |
| 7538 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7539 | |
| 7540 | if (IS_CHERRYVIEW(dev)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7541 | chv_compute_dpll(crtc, pipe_config); |
| 7542 | chv_prepare_pll(crtc, pipe_config); |
| 7543 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7544 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7545 | vlv_compute_dpll(crtc, pipe_config); |
| 7546 | vlv_prepare_pll(crtc, pipe_config); |
| 7547 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7548 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7549 | |
| 7550 | kfree(pipe_config); |
| 7551 | |
| 7552 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** |
| 7556 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7557 | * @dev_priv: i915 private structure |
| 7558 | * @pipe: pipe PLL to disable |
| 7559 | * |
| 7560 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7561 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7562 | */ |
| 7563 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 7564 | { |
| 7565 | if (IS_CHERRYVIEW(dev)) |
| 7566 | chv_disable_pll(to_i915(dev), pipe); |
| 7567 | else |
| 7568 | vlv_disable_pll(to_i915(dev), pipe); |
| 7569 | } |
| 7570 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7571 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7572 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7573 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7574 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7575 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7576 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7577 | u32 dpll; |
| 7578 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7579 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7580 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7581 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7582 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7583 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7584 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7585 | |
| 7586 | dpll = DPLL_VGA_MODE_DIS; |
| 7587 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7588 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7589 | dpll |= DPLLB_MODE_LVDS; |
| 7590 | else |
| 7591 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7592 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7593 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7594 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7595 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7596 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7597 | |
| 7598 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7599 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7600 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7601 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7602 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7603 | |
| 7604 | /* compute bitmask from p1 value */ |
| 7605 | if (IS_PINEVIEW(dev)) |
| 7606 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7607 | else { |
| 7608 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7609 | if (IS_G4X(dev) && reduced_clock) |
| 7610 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7611 | } |
| 7612 | switch (clock->p2) { |
| 7613 | case 5: |
| 7614 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7615 | break; |
| 7616 | case 7: |
| 7617 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7618 | break; |
| 7619 | case 10: |
| 7620 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7621 | break; |
| 7622 | case 14: |
| 7623 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7624 | break; |
| 7625 | } |
| 7626 | if (INTEL_INFO(dev)->gen >= 4) |
| 7627 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7628 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7629 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7630 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7631 | 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] | 7632 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7633 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7634 | else |
| 7635 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7636 | |
| 7637 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7638 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7639 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7640 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7641 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7642 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7643 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7644 | } |
| 7645 | } |
| 7646 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7647 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7648 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7649 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7650 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7651 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7653 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7654 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7655 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7656 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7657 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7658 | dpll = DPLL_VGA_MODE_DIS; |
| 7659 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7660 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7661 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7662 | } else { |
| 7663 | if (clock->p1 == 2) |
| 7664 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7665 | else |
| 7666 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7667 | if (clock->p2 == 4) |
| 7668 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7669 | } |
| 7670 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7671 | 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] | 7672 | dpll |= DPLL_DVO_2X_MODE; |
| 7673 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7674 | 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] | 7675 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7676 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7677 | else |
| 7678 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7679 | |
| 7680 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7681 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7682 | } |
| 7683 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7684 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7685 | { |
| 7686 | struct drm_device *dev = intel_crtc->base.dev; |
| 7687 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7688 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7689 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7690 | 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] | 7691 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7692 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7693 | |
| 7694 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7695 | * the hw state checker will get angry at the mismatch. */ |
| 7696 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7697 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7698 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7699 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7700 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7701 | crtc_vtotal -= 1; |
| 7702 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7703 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7704 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7705 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7706 | else |
| 7707 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7708 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7709 | if (vsyncshift < 0) |
| 7710 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7711 | } |
| 7712 | |
| 7713 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7714 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7715 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7716 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7717 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7718 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7719 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7720 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7721 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7722 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7723 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7724 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7725 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7726 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7727 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7728 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7729 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7730 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7731 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7732 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7733 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7734 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7735 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7736 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7737 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7738 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7739 | * bits. */ |
| 7740 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 7741 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7742 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7743 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) |
| 7747 | { |
| 7748 | struct drm_device *dev = intel_crtc->base.dev; |
| 7749 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7750 | enum pipe pipe = intel_crtc->pipe; |
| 7751 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7752 | /* pipesrc controls the size that is scaled from, which should |
| 7753 | * always be the user's requested size. |
| 7754 | */ |
| 7755 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7756 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7757 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7758 | } |
| 7759 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7760 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7761 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7762 | { |
| 7763 | struct drm_device *dev = crtc->base.dev; |
| 7764 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7765 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7766 | uint32_t tmp; |
| 7767 | |
| 7768 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7769 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7770 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7771 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7772 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7773 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7774 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7775 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7776 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7777 | |
| 7778 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7779 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7780 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7781 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7782 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7783 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7784 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7785 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7786 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7787 | |
| 7788 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7789 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7790 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7791 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7792 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7793 | } |
| 7794 | |
| 7795 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7796 | struct intel_crtc_state *pipe_config) |
| 7797 | { |
| 7798 | struct drm_device *dev = crtc->base.dev; |
| 7799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7800 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7801 | |
| 7802 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7803 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7804 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7805 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7806 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7807 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7808 | } |
| 7809 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7810 | 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] | 7811 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7812 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7813 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7814 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7815 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7816 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7817 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7818 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7819 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7820 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7821 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7822 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7823 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7824 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7825 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7826 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 7827 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7828 | |
| 7829 | mode->hsync = drm_mode_hsync(mode); |
| 7830 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7831 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7832 | } |
| 7833 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7834 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7835 | { |
| 7836 | struct drm_device *dev = intel_crtc->base.dev; |
| 7837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7838 | uint32_t pipeconf; |
| 7839 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7840 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7841 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7842 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 7843 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 7844 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7845 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7846 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7847 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7848 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7849 | /* only g4x and later have fancy bpc/dither controls */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7850 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7851 | /* 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] | 7852 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7853 | pipeconf |= PIPECONF_DITHER_EN | |
| 7854 | PIPECONF_DITHER_TYPE_SP; |
| 7855 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7856 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7857 | case 18: |
| 7858 | pipeconf |= PIPECONF_6BPC; |
| 7859 | break; |
| 7860 | case 24: |
| 7861 | pipeconf |= PIPECONF_8BPC; |
| 7862 | break; |
| 7863 | case 30: |
| 7864 | pipeconf |= PIPECONF_10BPC; |
| 7865 | break; |
| 7866 | default: |
| 7867 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7868 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7869 | } |
| 7870 | } |
| 7871 | |
| 7872 | if (HAS_PIPE_CXSR(dev)) { |
| 7873 | if (intel_crtc->lowfreq_avail) { |
| 7874 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 7875 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 7876 | } else { |
| 7877 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7878 | } |
| 7879 | } |
| 7880 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7881 | 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] | 7882 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7883 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7884 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7885 | else |
| 7886 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7887 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7888 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7889 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7890 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 7891 | intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7892 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7893 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7894 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7895 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7896 | } |
| 7897 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7898 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7899 | struct intel_crtc_state *crtc_state) |
| 7900 | { |
| 7901 | struct drm_device *dev = crtc->base.dev; |
| 7902 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7903 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7904 | int refclk = 48000; |
| 7905 | |
| 7906 | memset(&crtc_state->dpll_hw_state, 0, |
| 7907 | sizeof(crtc_state->dpll_hw_state)); |
| 7908 | |
| 7909 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7910 | if (intel_panel_use_ssc(dev_priv)) { |
| 7911 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7912 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7913 | } |
| 7914 | |
| 7915 | limit = &intel_limits_i8xx_lvds; |
| 7916 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) { |
| 7917 | limit = &intel_limits_i8xx_dvo; |
| 7918 | } else { |
| 7919 | limit = &intel_limits_i8xx_dac; |
| 7920 | } |
| 7921 | |
| 7922 | if (!crtc_state->clock_set && |
| 7923 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7924 | refclk, NULL, &crtc_state->dpll)) { |
| 7925 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7926 | return -EINVAL; |
| 7927 | } |
| 7928 | |
| 7929 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7930 | |
| 7931 | return 0; |
| 7932 | } |
| 7933 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7934 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7935 | struct intel_crtc_state *crtc_state) |
| 7936 | { |
| 7937 | struct drm_device *dev = crtc->base.dev; |
| 7938 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7939 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7940 | int refclk = 96000; |
| 7941 | |
| 7942 | memset(&crtc_state->dpll_hw_state, 0, |
| 7943 | sizeof(crtc_state->dpll_hw_state)); |
| 7944 | |
| 7945 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7946 | if (intel_panel_use_ssc(dev_priv)) { |
| 7947 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7948 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7949 | } |
| 7950 | |
| 7951 | if (intel_is_dual_link_lvds(dev)) |
| 7952 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7953 | else |
| 7954 | limit = &intel_limits_g4x_single_channel_lvds; |
| 7955 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7956 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
| 7957 | limit = &intel_limits_g4x_hdmi; |
| 7958 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
| 7959 | limit = &intel_limits_g4x_sdvo; |
| 7960 | } else { |
| 7961 | /* The option is for other outputs */ |
| 7962 | limit = &intel_limits_i9xx_sdvo; |
| 7963 | } |
| 7964 | |
| 7965 | if (!crtc_state->clock_set && |
| 7966 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7967 | refclk, NULL, &crtc_state->dpll)) { |
| 7968 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7969 | return -EINVAL; |
| 7970 | } |
| 7971 | |
| 7972 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7973 | |
| 7974 | return 0; |
| 7975 | } |
| 7976 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7977 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7978 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7979 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7980 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7981 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7982 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7983 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7984 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7985 | memset(&crtc_state->dpll_hw_state, 0, |
| 7986 | sizeof(crtc_state->dpll_hw_state)); |
| 7987 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7988 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7989 | if (intel_panel_use_ssc(dev_priv)) { |
| 7990 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7991 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7992 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7993 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7994 | limit = &intel_limits_pineview_lvds; |
| 7995 | } else { |
| 7996 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7997 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7998 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7999 | if (!crtc_state->clock_set && |
| 8000 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8001 | refclk, NULL, &crtc_state->dpll)) { |
| 8002 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8003 | return -EINVAL; |
| 8004 | } |
| 8005 | |
| 8006 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 8007 | |
| 8008 | return 0; |
| 8009 | } |
| 8010 | |
| 8011 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 8012 | struct intel_crtc_state *crtc_state) |
| 8013 | { |
| 8014 | struct drm_device *dev = crtc->base.dev; |
| 8015 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8016 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8017 | int refclk = 96000; |
| 8018 | |
| 8019 | memset(&crtc_state->dpll_hw_state, 0, |
| 8020 | sizeof(crtc_state->dpll_hw_state)); |
| 8021 | |
| 8022 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 8023 | if (intel_panel_use_ssc(dev_priv)) { |
| 8024 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8025 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 8026 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8027 | |
| 8028 | limit = &intel_limits_i9xx_lvds; |
| 8029 | } else { |
| 8030 | limit = &intel_limits_i9xx_sdvo; |
| 8031 | } |
| 8032 | |
| 8033 | if (!crtc_state->clock_set && |
| 8034 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8035 | refclk, NULL, &crtc_state->dpll)) { |
| 8036 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8037 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8038 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8039 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8040 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8041 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8042 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8043 | } |
| 8044 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8045 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 8046 | struct intel_crtc_state *crtc_state) |
| 8047 | { |
| 8048 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8049 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8050 | |
| 8051 | memset(&crtc_state->dpll_hw_state, 0, |
| 8052 | sizeof(crtc_state->dpll_hw_state)); |
| 8053 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8054 | if (!crtc_state->clock_set && |
| 8055 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8056 | refclk, NULL, &crtc_state->dpll)) { |
| 8057 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8058 | return -EINVAL; |
| 8059 | } |
| 8060 | |
| 8061 | chv_compute_dpll(crtc, crtc_state); |
| 8062 | |
| 8063 | return 0; |
| 8064 | } |
| 8065 | |
| 8066 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 8067 | struct intel_crtc_state *crtc_state) |
| 8068 | { |
| 8069 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8070 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8071 | |
| 8072 | memset(&crtc_state->dpll_hw_state, 0, |
| 8073 | sizeof(crtc_state->dpll_hw_state)); |
| 8074 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8075 | if (!crtc_state->clock_set && |
| 8076 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8077 | refclk, NULL, &crtc_state->dpll)) { |
| 8078 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8079 | return -EINVAL; |
| 8080 | } |
| 8081 | |
| 8082 | vlv_compute_dpll(crtc, crtc_state); |
| 8083 | |
| 8084 | return 0; |
| 8085 | } |
| 8086 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8087 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8088 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8089 | { |
| 8090 | struct drm_device *dev = crtc->base.dev; |
| 8091 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8092 | uint32_t tmp; |
| 8093 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 8094 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 8095 | return; |
| 8096 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8097 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8098 | if (!(tmp & PFIT_ENABLE)) |
| 8099 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8100 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8101 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8102 | if (INTEL_INFO(dev)->gen < 4) { |
| 8103 | if (crtc->pipe != PIPE_B) |
| 8104 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8105 | } else { |
| 8106 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 8107 | return; |
| 8108 | } |
| 8109 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8110 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8111 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8112 | } |
| 8113 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8114 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8115 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8116 | { |
| 8117 | struct drm_device *dev = crtc->base.dev; |
| 8118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8119 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8120 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8121 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 8122 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8123 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8124 | /* In case of DSI, DPLL will not be used */ |
| 8125 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 8126 | return; |
| 8127 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8128 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 8129 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8130 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8131 | |
| 8132 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 8133 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 8134 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 8135 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 8136 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 8137 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8138 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8139 | } |
| 8140 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8141 | static void |
| 8142 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 8143 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8144 | { |
| 8145 | struct drm_device *dev = crtc->base.dev; |
| 8146 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8147 | u32 val, base, offset; |
| 8148 | int pipe = crtc->pipe, plane = crtc->plane; |
| 8149 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8150 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8151 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8152 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8153 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8154 | val = I915_READ(DSPCNTR(plane)); |
| 8155 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8156 | return; |
| 8157 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8158 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8159 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8160 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8161 | return; |
| 8162 | } |
| 8163 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8164 | fb = &intel_fb->base; |
| 8165 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8166 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8167 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8168 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8169 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8170 | } |
| 8171 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8172 | |
| 8173 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8174 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8175 | fb->pixel_format = fourcc; |
| 8176 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8177 | |
| 8178 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8179 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8180 | offset = I915_READ(DSPTILEOFF(plane)); |
| 8181 | else |
| 8182 | offset = I915_READ(DSPLINOFF(plane)); |
| 8183 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 8184 | } else { |
| 8185 | base = I915_READ(DSPADDR(plane)); |
| 8186 | } |
| 8187 | plane_config->base = base; |
| 8188 | |
| 8189 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8190 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8191 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8192 | |
| 8193 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8194 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8195 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8196 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8197 | fb->pixel_format, |
| 8198 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8199 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8200 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8201 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8202 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8203 | pipe_name(pipe), plane, fb->width, fb->height, |
| 8204 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8205 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8206 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8207 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8208 | } |
| 8209 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8210 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8211 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8212 | { |
| 8213 | struct drm_device *dev = crtc->base.dev; |
| 8214 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8215 | int pipe = pipe_config->cpu_transcoder; |
| 8216 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8217 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8218 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8219 | int refclk = 100000; |
| 8220 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8221 | /* In case of DSI, DPLL will not be used */ |
| 8222 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 8223 | return; |
| 8224 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8225 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8226 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8227 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8228 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8229 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8230 | 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] | 8231 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8232 | |
| 8233 | 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] | 8234 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8235 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8236 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8237 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8238 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8239 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8240 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8241 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8242 | } |
| 8243 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8244 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8245 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8246 | { |
| 8247 | struct drm_device *dev = crtc->base.dev; |
| 8248 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8249 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8250 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8251 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8252 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8253 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8254 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8255 | return false; |
| 8256 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8257 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8258 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8259 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8260 | ret = false; |
| 8261 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8262 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8263 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8264 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8265 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8266 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8267 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8268 | case PIPECONF_6BPC: |
| 8269 | pipe_config->pipe_bpp = 18; |
| 8270 | break; |
| 8271 | case PIPECONF_8BPC: |
| 8272 | pipe_config->pipe_bpp = 24; |
| 8273 | break; |
| 8274 | case PIPECONF_10BPC: |
| 8275 | pipe_config->pipe_bpp = 30; |
| 8276 | break; |
| 8277 | default: |
| 8278 | break; |
| 8279 | } |
| 8280 | } |
| 8281 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8282 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 8283 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8284 | pipe_config->limited_color_range = true; |
| 8285 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8286 | if (INTEL_INFO(dev)->gen < 4) |
| 8287 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8288 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8289 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8290 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8291 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8292 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8293 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8294 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8295 | /* No way to read it out on pipes B and C */ |
| 8296 | if (IS_CHERRYVIEW(dev) && crtc->pipe != PIPE_A) |
| 8297 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8298 | else |
| 8299 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8300 | pipe_config->pixel_multiplier = |
| 8301 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8302 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8303 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8304 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 8305 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8306 | pipe_config->pixel_multiplier = |
| 8307 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8308 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8309 | } else { |
| 8310 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8311 | * port and will be fixed up in the encoder->get_config |
| 8312 | * function. */ |
| 8313 | pipe_config->pixel_multiplier = 1; |
| 8314 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8315 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8316 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8317 | /* |
| 8318 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8319 | * on 830. Filter it out here so that we don't |
| 8320 | * report errors due to that. |
| 8321 | */ |
| 8322 | if (IS_I830(dev)) |
| 8323 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8324 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8325 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8326 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8327 | } else { |
| 8328 | /* Mask out read-only status bits. */ |
| 8329 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8330 | DPLL_PORTC_READY_MASK | |
| 8331 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8332 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8333 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8334 | if (IS_CHERRYVIEW(dev)) |
| 8335 | chv_crtc_clock_get(crtc, pipe_config); |
| 8336 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8337 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8338 | else |
| 8339 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8340 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8341 | /* |
| 8342 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8343 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8344 | * default. |
| 8345 | */ |
| 8346 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8347 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8348 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8349 | ret = true; |
| 8350 | |
| 8351 | out: |
| 8352 | intel_display_power_put(dev_priv, power_domain); |
| 8353 | |
| 8354 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8355 | } |
| 8356 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8357 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8358 | { |
| 8359 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8360 | struct intel_encoder *encoder; |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8361 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8362 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8363 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8364 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8365 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8366 | bool has_ck505 = false; |
| 8367 | bool can_ssc = false; |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8368 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8369 | |
| 8370 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8371 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8372 | switch (encoder->type) { |
| 8373 | case INTEL_OUTPUT_LVDS: |
| 8374 | has_panel = true; |
| 8375 | has_lvds = true; |
| 8376 | break; |
| 8377 | case INTEL_OUTPUT_EDP: |
| 8378 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8379 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8380 | has_cpu_edp = true; |
| 8381 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8382 | default: |
| 8383 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8384 | } |
| 8385 | } |
| 8386 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8387 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8388 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8389 | can_ssc = has_ck505; |
| 8390 | } else { |
| 8391 | has_ck505 = false; |
| 8392 | can_ssc = true; |
| 8393 | } |
| 8394 | |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8395 | /* Check if any DPLLs are using the SSC source */ |
| 8396 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8397 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8398 | |
| 8399 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8400 | continue; |
| 8401 | |
| 8402 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8403 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8404 | using_ssc_source = true; |
| 8405 | break; |
| 8406 | } |
| 8407 | } |
| 8408 | |
| 8409 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8410 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8411 | |
| 8412 | /* Ironlake: try to setup display ref clock before DPLL |
| 8413 | * enabling. This is only under driver's control after |
| 8414 | * PCH B stepping, previous chipset stepping should be |
| 8415 | * ignoring this setting. |
| 8416 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8417 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8418 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8419 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8420 | * compute the final state we want first and check if we need to |
| 8421 | * make any changes at all. |
| 8422 | */ |
| 8423 | final = val; |
| 8424 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8425 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8426 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8427 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8428 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8429 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8430 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8431 | |
| 8432 | if (!using_ssc_source) { |
| 8433 | final &= ~DREF_SSC_SOURCE_MASK; |
| 8434 | final &= ~DREF_SSC1_ENABLE; |
| 8435 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8436 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8437 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8438 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8439 | |
| 8440 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8441 | final |= DREF_SSC1_ENABLE; |
| 8442 | |
| 8443 | if (has_cpu_edp) { |
| 8444 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8445 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8446 | else |
| 8447 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8448 | } else |
| 8449 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8450 | } else { |
| 8451 | final |= DREF_SSC_SOURCE_DISABLE; |
| 8452 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8453 | } |
| 8454 | |
| 8455 | if (final == val) |
| 8456 | return; |
| 8457 | |
| 8458 | /* Always enable nonspread source */ |
| 8459 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8460 | |
| 8461 | if (has_ck505) |
| 8462 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8463 | else |
| 8464 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8465 | |
| 8466 | if (has_panel) { |
| 8467 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8468 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8469 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8470 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8471 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8472 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8473 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8474 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8475 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8476 | |
| 8477 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8478 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8479 | POSTING_READ(PCH_DREF_CONTROL); |
| 8480 | udelay(200); |
| 8481 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8482 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8483 | |
| 8484 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8485 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8486 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8487 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8488 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8489 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8490 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8491 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8492 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8493 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8494 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8495 | POSTING_READ(PCH_DREF_CONTROL); |
| 8496 | udelay(200); |
| 8497 | } else { |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8498 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8499 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8500 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8501 | |
| 8502 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8503 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8504 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8505 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8506 | POSTING_READ(PCH_DREF_CONTROL); |
| 8507 | udelay(200); |
| 8508 | |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8509 | if (!using_ssc_source) { |
| 8510 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8511 | |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8512 | /* Turn off the SSC source */ |
| 8513 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8514 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8515 | |
Lyude | f165d28 | 2016-05-25 14:11:02 -0400 | [diff] [blame^] | 8516 | /* Turn off SSC1 */ |
| 8517 | val &= ~DREF_SSC1_ENABLE; |
| 8518 | |
| 8519 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8520 | POSTING_READ(PCH_DREF_CONTROL); |
| 8521 | udelay(200); |
| 8522 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8523 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8524 | |
| 8525 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8528 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8529 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8530 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8531 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8532 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8533 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8534 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8535 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8536 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 8537 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 8538 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8539 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8540 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8541 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8542 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8543 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8544 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 8545 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 8546 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8547 | } |
| 8548 | |
| 8549 | /* WaMPhyProgramming:hsw */ |
| 8550 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8551 | { |
| 8552 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8553 | |
| 8554 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8555 | tmp &= ~(0xFF << 24); |
| 8556 | tmp |= (0x12 << 24); |
| 8557 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8558 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8559 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8560 | tmp |= (1 << 11); |
| 8561 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8562 | |
| 8563 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8564 | tmp |= (1 << 11); |
| 8565 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8566 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8567 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8568 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8569 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8570 | |
| 8571 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8572 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8573 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8574 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8575 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8576 | tmp &= ~(7 << 13); |
| 8577 | tmp |= (5 << 13); |
| 8578 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8579 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8580 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8581 | tmp &= ~(7 << 13); |
| 8582 | tmp |= (5 << 13); |
| 8583 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8584 | |
| 8585 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8586 | tmp &= ~0xFF; |
| 8587 | tmp |= 0x1C; |
| 8588 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8589 | |
| 8590 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8591 | tmp &= ~0xFF; |
| 8592 | tmp |= 0x1C; |
| 8593 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8594 | |
| 8595 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8596 | tmp &= ~(0xFF << 16); |
| 8597 | tmp |= (0x1C << 16); |
| 8598 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8599 | |
| 8600 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8601 | tmp &= ~(0xFF << 16); |
| 8602 | tmp |= (0x1C << 16); |
| 8603 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8604 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8605 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8606 | tmp |= (1 << 27); |
| 8607 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8608 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8609 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8610 | tmp |= (1 << 27); |
| 8611 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8612 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8613 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8614 | tmp &= ~(0xF << 28); |
| 8615 | tmp |= (4 << 28); |
| 8616 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8617 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8618 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8619 | tmp &= ~(0xF << 28); |
| 8620 | tmp |= (4 << 28); |
| 8621 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8622 | } |
| 8623 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8624 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8625 | * Programming" based on the parameters passed: |
| 8626 | * - Sequence to enable CLKOUT_DP |
| 8627 | * - Sequence to enable CLKOUT_DP without spread |
| 8628 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8629 | */ |
| 8630 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 8631 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8632 | { |
| 8633 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8634 | uint32_t reg, tmp; |
| 8635 | |
| 8636 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8637 | with_spread = true; |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8638 | 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] | 8639 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8640 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8641 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8642 | |
| 8643 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8644 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8645 | tmp |= SBI_SSCCTL_PATHALT; |
| 8646 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8647 | |
| 8648 | udelay(24); |
| 8649 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8650 | if (with_spread) { |
| 8651 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8652 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8653 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8654 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8655 | if (with_fdi) { |
| 8656 | lpt_reset_fdi_mphy(dev_priv); |
| 8657 | lpt_program_fdi_mphy(dev_priv); |
| 8658 | } |
| 8659 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8660 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8661 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8662 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8663 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8664 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8665 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8666 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8667 | } |
| 8668 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8669 | /* Sequence to disable CLKOUT_DP */ |
| 8670 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 8671 | { |
| 8672 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8673 | uint32_t reg, tmp; |
| 8674 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8675 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8676 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8677 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8678 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8679 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8680 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8681 | |
| 8682 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8683 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8684 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8685 | tmp |= SBI_SSCCTL_PATHALT; |
| 8686 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8687 | udelay(32); |
| 8688 | } |
| 8689 | tmp |= SBI_SSCCTL_DISABLE; |
| 8690 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8691 | } |
| 8692 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8693 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8694 | } |
| 8695 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8696 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8697 | |
| 8698 | static const uint16_t sscdivintphase[] = { |
| 8699 | [BEND_IDX( 50)] = 0x3B23, |
| 8700 | [BEND_IDX( 45)] = 0x3B23, |
| 8701 | [BEND_IDX( 40)] = 0x3C23, |
| 8702 | [BEND_IDX( 35)] = 0x3C23, |
| 8703 | [BEND_IDX( 30)] = 0x3D23, |
| 8704 | [BEND_IDX( 25)] = 0x3D23, |
| 8705 | [BEND_IDX( 20)] = 0x3E23, |
| 8706 | [BEND_IDX( 15)] = 0x3E23, |
| 8707 | [BEND_IDX( 10)] = 0x3F23, |
| 8708 | [BEND_IDX( 5)] = 0x3F23, |
| 8709 | [BEND_IDX( 0)] = 0x0025, |
| 8710 | [BEND_IDX( -5)] = 0x0025, |
| 8711 | [BEND_IDX(-10)] = 0x0125, |
| 8712 | [BEND_IDX(-15)] = 0x0125, |
| 8713 | [BEND_IDX(-20)] = 0x0225, |
| 8714 | [BEND_IDX(-25)] = 0x0225, |
| 8715 | [BEND_IDX(-30)] = 0x0325, |
| 8716 | [BEND_IDX(-35)] = 0x0325, |
| 8717 | [BEND_IDX(-40)] = 0x0425, |
| 8718 | [BEND_IDX(-45)] = 0x0425, |
| 8719 | [BEND_IDX(-50)] = 0x0525, |
| 8720 | }; |
| 8721 | |
| 8722 | /* |
| 8723 | * Bend CLKOUT_DP |
| 8724 | * steps -50 to 50 inclusive, in steps of 5 |
| 8725 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8726 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8727 | */ |
| 8728 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8729 | { |
| 8730 | uint32_t tmp; |
| 8731 | int idx = BEND_IDX(steps); |
| 8732 | |
| 8733 | if (WARN_ON(steps % 5 != 0)) |
| 8734 | return; |
| 8735 | |
| 8736 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8737 | return; |
| 8738 | |
| 8739 | mutex_lock(&dev_priv->sb_lock); |
| 8740 | |
| 8741 | if (steps % 10 != 0) |
| 8742 | tmp = 0xAAAAAAAB; |
| 8743 | else |
| 8744 | tmp = 0x00000000; |
| 8745 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8746 | |
| 8747 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8748 | tmp &= 0xffff0000; |
| 8749 | tmp |= sscdivintphase[idx]; |
| 8750 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8751 | |
| 8752 | mutex_unlock(&dev_priv->sb_lock); |
| 8753 | } |
| 8754 | |
| 8755 | #undef BEND_IDX |
| 8756 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8757 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 8758 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8759 | struct intel_encoder *encoder; |
| 8760 | bool has_vga = false; |
| 8761 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8762 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8763 | switch (encoder->type) { |
| 8764 | case INTEL_OUTPUT_ANALOG: |
| 8765 | has_vga = true; |
| 8766 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8767 | default: |
| 8768 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8769 | } |
| 8770 | } |
| 8771 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8772 | if (has_vga) { |
| 8773 | lpt_bend_clkout_dp(to_i915(dev), 0); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8774 | lpt_enable_clkout_dp(dev, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8775 | } else { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8776 | lpt_disable_clkout_dp(dev); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8777 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8778 | } |
| 8779 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8780 | /* |
| 8781 | * Initialize reference clocks when the driver loads |
| 8782 | */ |
| 8783 | void intel_init_pch_refclk(struct drm_device *dev) |
| 8784 | { |
| 8785 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 8786 | ironlake_init_pch_refclk(dev); |
| 8787 | else if (HAS_PCH_LPT(dev)) |
| 8788 | lpt_init_pch_refclk(dev); |
| 8789 | } |
| 8790 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8791 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8792 | { |
| 8793 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8794 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8795 | int pipe = intel_crtc->pipe; |
| 8796 | uint32_t val; |
| 8797 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8798 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8799 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8800 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8801 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8802 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8803 | break; |
| 8804 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8805 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8806 | break; |
| 8807 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8808 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8809 | break; |
| 8810 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8811 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8812 | break; |
| 8813 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8814 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8815 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8816 | } |
| 8817 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8818 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8819 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8820 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8821 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8822 | val |= PIPECONF_INTERLACED_ILK; |
| 8823 | else |
| 8824 | val |= PIPECONF_PROGRESSIVE; |
| 8825 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8826 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8827 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8828 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8829 | I915_WRITE(PIPECONF(pipe), val); |
| 8830 | POSTING_READ(PIPECONF(pipe)); |
| 8831 | } |
| 8832 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8833 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8834 | { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8835 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8836 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8837 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8838 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8839 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8840 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8841 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8842 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8843 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8844 | val |= PIPECONF_INTERLACED_ILK; |
| 8845 | else |
| 8846 | val |= PIPECONF_PROGRESSIVE; |
| 8847 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8848 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8849 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8850 | } |
| 8851 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8852 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
| 8853 | { |
| 8854 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8855 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8856 | |
| 8857 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
| 8858 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8859 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8860 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8861 | case 18: |
| 8862 | val |= PIPEMISC_DITHER_6_BPC; |
| 8863 | break; |
| 8864 | case 24: |
| 8865 | val |= PIPEMISC_DITHER_8_BPC; |
| 8866 | break; |
| 8867 | case 30: |
| 8868 | val |= PIPEMISC_DITHER_10_BPC; |
| 8869 | break; |
| 8870 | case 36: |
| 8871 | val |= PIPEMISC_DITHER_12_BPC; |
| 8872 | break; |
| 8873 | default: |
| 8874 | /* Case prevented by pipe_config_set_bpp. */ |
| 8875 | BUG(); |
| 8876 | } |
| 8877 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8878 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8879 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8880 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8881 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8882 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8883 | } |
| 8884 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8885 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8886 | { |
| 8887 | /* |
| 8888 | * Account for spread spectrum to avoid |
| 8889 | * oversubscribing the link. Max center spread |
| 8890 | * is 2.5%; use 5% for safety's sake. |
| 8891 | */ |
| 8892 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8893 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8894 | } |
| 8895 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8896 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8897 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8898 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8899 | } |
| 8900 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8901 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8902 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8903 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8904 | { |
| 8905 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8906 | struct drm_device *dev = crtc->dev; |
| 8907 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8908 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8909 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8910 | struct drm_connector_state *connector_state; |
| 8911 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8912 | u32 dpll, fp, fp2; |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8913 | int factor, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 8914 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8915 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8916 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8917 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8918 | continue; |
| 8919 | |
| 8920 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8921 | |
| 8922 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8923 | case INTEL_OUTPUT_LVDS: |
| 8924 | is_lvds = true; |
| 8925 | break; |
| 8926 | case INTEL_OUTPUT_SDVO: |
| 8927 | case INTEL_OUTPUT_HDMI: |
| 8928 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8929 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8930 | default: |
| 8931 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8932 | } |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8933 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8934 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8935 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8936 | factor = 21; |
| 8937 | if (is_lvds) { |
| 8938 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8939 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 8940 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8941 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8942 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8943 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8944 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8945 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8946 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8947 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8948 | fp |= FP_CB_TUNE; |
| 8949 | |
| 8950 | if (reduced_clock) { |
| 8951 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8952 | |
| 8953 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8954 | fp2 |= FP_CB_TUNE; |
| 8955 | } else { |
| 8956 | fp2 = fp; |
| 8957 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8958 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8959 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8960 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8961 | if (is_lvds) |
| 8962 | dpll |= DPLLB_MODE_LVDS; |
| 8963 | else |
| 8964 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8965 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8966 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8967 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8968 | |
| 8969 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8970 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8971 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8972 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8973 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8974 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8975 | 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] | 8976 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8977 | 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] | 8978 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8979 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8980 | case 5: |
| 8981 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8982 | break; |
| 8983 | case 7: |
| 8984 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8985 | break; |
| 8986 | case 10: |
| 8987 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8988 | break; |
| 8989 | case 14: |
| 8990 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8991 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8992 | } |
| 8993 | |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8994 | if (is_lvds && intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8995 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8996 | else |
| 8997 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8998 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8999 | dpll |= DPLL_VCO_ENABLE; |
| 9000 | |
| 9001 | crtc_state->dpll_hw_state.dpll = dpll; |
| 9002 | crtc_state->dpll_hw_state.fp0 = fp; |
| 9003 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 9004 | } |
| 9005 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9006 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 9007 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9008 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9009 | struct drm_device *dev = crtc->base.dev; |
| 9010 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 9011 | struct dpll reduced_clock; |
Ander Conselvan de Oliveira | 7ed9f89 | 2016-03-21 18:00:07 +0200 | [diff] [blame] | 9012 | bool has_reduced_clock = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 9013 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 9014 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9015 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9016 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 9017 | memset(&crtc_state->dpll_hw_state, 0, |
| 9018 | sizeof(crtc_state->dpll_hw_state)); |
| 9019 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9020 | crtc->lowfreq_avail = false; |
| 9021 | |
| 9022 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 9023 | if (!crtc_state->has_pch_encoder) |
| 9024 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9025 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9026 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 9027 | if (intel_panel_use_ssc(dev_priv)) { |
| 9028 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 9029 | dev_priv->vbt.lvds_ssc_freq); |
| 9030 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 9031 | } |
| 9032 | |
| 9033 | if (intel_is_dual_link_lvds(dev)) { |
| 9034 | if (refclk == 100000) |
| 9035 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 9036 | else |
| 9037 | limit = &intel_limits_ironlake_dual_lvds; |
| 9038 | } else { |
| 9039 | if (refclk == 100000) |
| 9040 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 9041 | else |
| 9042 | limit = &intel_limits_ironlake_single_lvds; |
| 9043 | } |
| 9044 | } else { |
| 9045 | limit = &intel_limits_ironlake_dac; |
| 9046 | } |
| 9047 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 9048 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9049 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 9050 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 9051 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 9052 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 9053 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9054 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9055 | ironlake_compute_dpll(crtc, crtc_state, |
| 9056 | has_reduced_clock ? &reduced_clock : NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9057 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9058 | pll = intel_get_shared_dpll(crtc, crtc_state, NULL); |
| 9059 | if (pll == NULL) { |
| 9060 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 9061 | pipe_name(crtc->pipe)); |
| 9062 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 9063 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9064 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9065 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 9066 | has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9067 | crtc->lowfreq_avail = true; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 9068 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9069 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9070 | } |
| 9071 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9072 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 9073 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9074 | { |
| 9075 | struct drm_device *dev = crtc->base.dev; |
| 9076 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9077 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9078 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9079 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 9080 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 9081 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 9082 | & ~TU_SIZE_MASK; |
| 9083 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 9084 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 9085 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9086 | } |
| 9087 | |
| 9088 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 9089 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9090 | struct intel_link_m_n *m_n, |
| 9091 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9092 | { |
| 9093 | struct drm_device *dev = crtc->base.dev; |
| 9094 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9095 | enum pipe pipe = crtc->pipe; |
| 9096 | |
| 9097 | if (INTEL_INFO(dev)->gen >= 5) { |
| 9098 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 9099 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 9100 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 9101 | & ~TU_SIZE_MASK; |
| 9102 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 9103 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 9104 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9105 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 9106 | * gen < 8) and if DRRS is supported (to make sure the |
| 9107 | * registers are not unnecessarily read). |
| 9108 | */ |
| 9109 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9110 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9111 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 9112 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 9113 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 9114 | & ~TU_SIZE_MASK; |
| 9115 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 9116 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 9117 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9118 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9119 | } else { |
| 9120 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 9121 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 9122 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9123 | & ~TU_SIZE_MASK; |
| 9124 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 9125 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9126 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9127 | } |
| 9128 | } |
| 9129 | |
| 9130 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9131 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9132 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 9133 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9134 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 9135 | else |
| 9136 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9137 | &pipe_config->dp_m_n, |
| 9138 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9139 | } |
| 9140 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9141 | 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] | 9142 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9143 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9144 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9145 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9146 | } |
| 9147 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9148 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9149 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9150 | { |
| 9151 | struct drm_device *dev = crtc->base.dev; |
| 9152 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9153 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 9154 | uint32_t ps_ctrl = 0; |
| 9155 | int id = -1; |
| 9156 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9157 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9158 | /* find scaler attached to this pipe */ |
| 9159 | for (i = 0; i < crtc->num_scalers; i++) { |
| 9160 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 9161 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 9162 | id = i; |
| 9163 | pipe_config->pch_pfit.enabled = true; |
| 9164 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 9165 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 9166 | break; |
| 9167 | } |
| 9168 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9169 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9170 | scaler_state->scaler_id = id; |
| 9171 | if (id >= 0) { |
| 9172 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 9173 | } else { |
| 9174 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9175 | } |
| 9176 | } |
| 9177 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9178 | static void |
| 9179 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9180 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9181 | { |
| 9182 | struct drm_device *dev = crtc->base.dev; |
| 9183 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9184 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9185 | int pipe = crtc->pipe; |
| 9186 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9187 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9188 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9189 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9190 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9191 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9192 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9193 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9194 | return; |
| 9195 | } |
| 9196 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9197 | fb = &intel_fb->base; |
| 9198 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9199 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9200 | if (!(val & PLANE_CTL_ENABLE)) |
| 9201 | goto error; |
| 9202 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9203 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 9204 | fourcc = skl_format_to_fourcc(pixel_format, |
| 9205 | val & PLANE_CTL_ORDER_RGBX, |
| 9206 | val & PLANE_CTL_ALPHA_MASK); |
| 9207 | fb->pixel_format = fourcc; |
| 9208 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 9209 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9210 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9211 | switch (tiling) { |
| 9212 | case PLANE_CTL_TILED_LINEAR: |
| 9213 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 9214 | break; |
| 9215 | case PLANE_CTL_TILED_X: |
| 9216 | plane_config->tiling = I915_TILING_X; |
| 9217 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9218 | break; |
| 9219 | case PLANE_CTL_TILED_Y: |
| 9220 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 9221 | break; |
| 9222 | case PLANE_CTL_TILED_YF: |
| 9223 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 9224 | break; |
| 9225 | default: |
| 9226 | MISSING_CASE(tiling); |
| 9227 | goto error; |
| 9228 | } |
| 9229 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9230 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 9231 | plane_config->base = base; |
| 9232 | |
| 9233 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 9234 | |
| 9235 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 9236 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9237 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9238 | |
| 9239 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 9240 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9241 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9242 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9243 | |
| 9244 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9245 | fb->pixel_format, |
| 9246 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9247 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9248 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9249 | |
| 9250 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9251 | pipe_name(pipe), fb->width, fb->height, |
| 9252 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9253 | plane_config->size); |
| 9254 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9255 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9256 | return; |
| 9257 | |
| 9258 | error: |
| 9259 | kfree(fb); |
| 9260 | } |
| 9261 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9262 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9263 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9264 | { |
| 9265 | struct drm_device *dev = crtc->base.dev; |
| 9266 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9267 | uint32_t tmp; |
| 9268 | |
| 9269 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9270 | |
| 9271 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9272 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9273 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9274 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9275 | |
| 9276 | /* We currently do not free assignements of panel fitters on |
| 9277 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9278 | * differentiates them) so just WARN about this case for now. */ |
| 9279 | if (IS_GEN7(dev)) { |
| 9280 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9281 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9282 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9283 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9284 | } |
| 9285 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9286 | static void |
| 9287 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9288 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9289 | { |
| 9290 | struct drm_device *dev = crtc->base.dev; |
| 9291 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9292 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9293 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9294 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9295 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9296 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9297 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9298 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9299 | val = I915_READ(DSPCNTR(pipe)); |
| 9300 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 9301 | return; |
| 9302 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9303 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9304 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9305 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9306 | return; |
| 9307 | } |
| 9308 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9309 | fb = &intel_fb->base; |
| 9310 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9311 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9312 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9313 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9314 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9315 | } |
| 9316 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9317 | |
| 9318 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 9319 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9320 | fb->pixel_format = fourcc; |
| 9321 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9322 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9323 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9324 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9325 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9326 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9327 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9328 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9329 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9330 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9331 | } |
| 9332 | plane_config->base = base; |
| 9333 | |
| 9334 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9335 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 9336 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9337 | |
| 9338 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9339 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9340 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9341 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9342 | fb->pixel_format, |
| 9343 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9344 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9345 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9346 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 9347 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9348 | pipe_name(pipe), fb->width, fb->height, |
| 9349 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9350 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9351 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9352 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9353 | } |
| 9354 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9355 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9356 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9357 | { |
| 9358 | struct drm_device *dev = crtc->base.dev; |
| 9359 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9360 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9361 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9362 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9363 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9364 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9365 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9366 | return false; |
| 9367 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9368 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9369 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9370 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9371 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9372 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9373 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9374 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9375 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9376 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9377 | case PIPECONF_6BPC: |
| 9378 | pipe_config->pipe_bpp = 18; |
| 9379 | break; |
| 9380 | case PIPECONF_8BPC: |
| 9381 | pipe_config->pipe_bpp = 24; |
| 9382 | break; |
| 9383 | case PIPECONF_10BPC: |
| 9384 | pipe_config->pipe_bpp = 30; |
| 9385 | break; |
| 9386 | case PIPECONF_12BPC: |
| 9387 | pipe_config->pipe_bpp = 36; |
| 9388 | break; |
| 9389 | default: |
| 9390 | break; |
| 9391 | } |
| 9392 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9393 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9394 | pipe_config->limited_color_range = true; |
| 9395 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9396 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9397 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9398 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9399 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9400 | pipe_config->has_pch_encoder = true; |
| 9401 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9402 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9403 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9404 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9405 | |
| 9406 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9407 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9408 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9409 | /* |
| 9410 | * The pipe->pch transcoder and pch transcoder->pll |
| 9411 | * mapping is fixed. |
| 9412 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9413 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9414 | } else { |
| 9415 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9416 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9417 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9418 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9419 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9420 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9421 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9422 | pipe_config->shared_dpll = |
| 9423 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9424 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9425 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9426 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 9427 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9428 | |
| 9429 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9430 | pipe_config->pixel_multiplier = |
| 9431 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9432 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9433 | |
| 9434 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9435 | } else { |
| 9436 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9437 | } |
| 9438 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9439 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9440 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9441 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9442 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9443 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9444 | ret = true; |
| 9445 | |
| 9446 | out: |
| 9447 | intel_display_power_put(dev_priv, power_domain); |
| 9448 | |
| 9449 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9450 | } |
| 9451 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9452 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9453 | { |
| 9454 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9455 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9456 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9457 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9458 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9459 | pipe_name(crtc->pipe)); |
| 9460 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9461 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 9462 | 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] | 9463 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9464 | 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] | 9465 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 9466 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9467 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9468 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9469 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9470 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9471 | 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] | 9472 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9473 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9474 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9475 | 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] | 9476 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9477 | /* |
| 9478 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9479 | * interrupts remain enabled. We used to check for that, but since it's |
| 9480 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9481 | * the interrupts, the check below should be enough. |
| 9482 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9483 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9484 | } |
| 9485 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9486 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9487 | { |
| 9488 | struct drm_device *dev = dev_priv->dev; |
| 9489 | |
| 9490 | if (IS_HASWELL(dev)) |
| 9491 | return I915_READ(D_COMP_HSW); |
| 9492 | else |
| 9493 | return I915_READ(D_COMP_BDW); |
| 9494 | } |
| 9495 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9496 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9497 | { |
| 9498 | struct drm_device *dev = dev_priv->dev; |
| 9499 | |
| 9500 | if (IS_HASWELL(dev)) { |
| 9501 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9502 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9503 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 9504 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9505 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9506 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9507 | I915_WRITE(D_COMP_BDW, val); |
| 9508 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9509 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9510 | } |
| 9511 | |
| 9512 | /* |
| 9513 | * This function implements pieces of two sequences from BSpec: |
| 9514 | * - Sequence for display software to disable LCPLL |
| 9515 | * - Sequence for display software to allow package C8+ |
| 9516 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9517 | * register. Callers should take care of disabling all the display engine |
| 9518 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9519 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9520 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9521 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9522 | { |
| 9523 | uint32_t val; |
| 9524 | |
| 9525 | assert_can_disable_lcpll(dev_priv); |
| 9526 | |
| 9527 | val = I915_READ(LCPLL_CTL); |
| 9528 | |
| 9529 | if (switch_to_fclk) { |
| 9530 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9531 | I915_WRITE(LCPLL_CTL, val); |
| 9532 | |
| 9533 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9534 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9535 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9536 | |
| 9537 | val = I915_READ(LCPLL_CTL); |
| 9538 | } |
| 9539 | |
| 9540 | val |= LCPLL_PLL_DISABLE; |
| 9541 | I915_WRITE(LCPLL_CTL, val); |
| 9542 | POSTING_READ(LCPLL_CTL); |
| 9543 | |
| 9544 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 9545 | DRM_ERROR("LCPLL still locked\n"); |
| 9546 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9547 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9548 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9549 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9550 | ndelay(100); |
| 9551 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9552 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9553 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9554 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9555 | |
| 9556 | if (allow_power_down) { |
| 9557 | val = I915_READ(LCPLL_CTL); |
| 9558 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9559 | I915_WRITE(LCPLL_CTL, val); |
| 9560 | POSTING_READ(LCPLL_CTL); |
| 9561 | } |
| 9562 | } |
| 9563 | |
| 9564 | /* |
| 9565 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9566 | * source. |
| 9567 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9568 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9569 | { |
| 9570 | uint32_t val; |
| 9571 | |
| 9572 | val = I915_READ(LCPLL_CTL); |
| 9573 | |
| 9574 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9575 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9576 | return; |
| 9577 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9578 | /* |
| 9579 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9580 | * 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] | 9581 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9582 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9583 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9584 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9585 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9586 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9587 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9588 | } |
| 9589 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9590 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9591 | val |= D_COMP_COMP_FORCE; |
| 9592 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9593 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9594 | |
| 9595 | val = I915_READ(LCPLL_CTL); |
| 9596 | val &= ~LCPLL_PLL_DISABLE; |
| 9597 | I915_WRITE(LCPLL_CTL, val); |
| 9598 | |
| 9599 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 9600 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9601 | |
| 9602 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9603 | val = I915_READ(LCPLL_CTL); |
| 9604 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9605 | I915_WRITE(LCPLL_CTL, val); |
| 9606 | |
| 9607 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9608 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9609 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9610 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9611 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9612 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 9613 | intel_update_cdclk(dev_priv->dev); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9614 | } |
| 9615 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9616 | /* |
| 9617 | * Package states C8 and deeper are really deep PC states that can only be |
| 9618 | * reached when all the devices on the system allow it, so even if the graphics |
| 9619 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9620 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9621 | * |
| 9622 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9623 | * well is disabled and most interrupts are disabled, and these are also |
| 9624 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9625 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9626 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9627 | * hang the machine. |
| 9628 | * |
| 9629 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9630 | * the state of some registers, so when we come back from PC8+ we need to |
| 9631 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9632 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9633 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9634 | * because of the runtime PM support). |
| 9635 | * |
| 9636 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9637 | * documentation. |
| 9638 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9639 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9640 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9641 | struct drm_device *dev = dev_priv->dev; |
| 9642 | uint32_t val; |
| 9643 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9644 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9645 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9646 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9647 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9648 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9649 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9650 | } |
| 9651 | |
| 9652 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9653 | hsw_disable_lcpll(dev_priv, true, true); |
| 9654 | } |
| 9655 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9656 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9657 | { |
| 9658 | struct drm_device *dev = dev_priv->dev; |
| 9659 | uint32_t val; |
| 9660 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9661 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9662 | |
| 9663 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9664 | lpt_init_pch_refclk(dev); |
| 9665 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9666 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9667 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9668 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9669 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9670 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9671 | } |
| 9672 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9673 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9674 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9675 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9676 | struct intel_atomic_state *old_intel_state = |
| 9677 | to_intel_atomic_state(old_state); |
| 9678 | unsigned int req_cdclk = old_intel_state->dev_cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9679 | |
Imre Deak | c6c4696 | 2016-04-01 16:02:40 +0300 | [diff] [blame] | 9680 | broxton_set_cdclk(to_i915(dev), req_cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9681 | } |
| 9682 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9683 | /* compute the max rate for new configuration */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9684 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9685 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9686 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 9687 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 9688 | struct drm_crtc *crtc; |
| 9689 | struct drm_crtc_state *cstate; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9690 | struct intel_crtc_state *crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9691 | unsigned max_pixel_rate = 0, i; |
| 9692 | enum pipe pipe; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9693 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9694 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 9695 | sizeof(intel_state->min_pixclk)); |
| 9696 | |
| 9697 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9698 | int pixel_rate; |
| 9699 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9700 | crtc_state = to_intel_crtc_state(cstate); |
| 9701 | if (!crtc_state->base.enable) { |
| 9702 | intel_state->min_pixclk[i] = 0; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9703 | continue; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9704 | } |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9705 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9706 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9707 | |
| 9708 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9709 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9710 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
| 9711 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9712 | intel_state->min_pixclk[i] = pixel_rate; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9713 | } |
| 9714 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9715 | for_each_pipe(dev_priv, pipe) |
| 9716 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); |
| 9717 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9718 | return max_pixel_rate; |
| 9719 | } |
| 9720 | |
| 9721 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) |
| 9722 | { |
| 9723 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9724 | uint32_t val, data; |
| 9725 | int ret; |
| 9726 | |
| 9727 | if (WARN((I915_READ(LCPLL_CTL) & |
| 9728 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | |
| 9729 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | |
| 9730 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | |
| 9731 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, |
| 9732 | "trying to change cdclk frequency with cdclk not enabled\n")) |
| 9733 | return; |
| 9734 | |
| 9735 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9736 | ret = sandybridge_pcode_write(dev_priv, |
| 9737 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); |
| 9738 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9739 | if (ret) { |
| 9740 | DRM_ERROR("failed to inform pcode about cdclk change\n"); |
| 9741 | return; |
| 9742 | } |
| 9743 | |
| 9744 | val = I915_READ(LCPLL_CTL); |
| 9745 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9746 | I915_WRITE(LCPLL_CTL, val); |
| 9747 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9748 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9749 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9750 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9751 | |
| 9752 | val = I915_READ(LCPLL_CTL); |
| 9753 | val &= ~LCPLL_CLK_FREQ_MASK; |
| 9754 | |
| 9755 | switch (cdclk) { |
| 9756 | case 450000: |
| 9757 | val |= LCPLL_CLK_FREQ_450; |
| 9758 | data = 0; |
| 9759 | break; |
| 9760 | case 540000: |
| 9761 | val |= LCPLL_CLK_FREQ_54O_BDW; |
| 9762 | data = 1; |
| 9763 | break; |
| 9764 | case 337500: |
| 9765 | val |= LCPLL_CLK_FREQ_337_5_BDW; |
| 9766 | data = 2; |
| 9767 | break; |
| 9768 | case 675000: |
| 9769 | val |= LCPLL_CLK_FREQ_675_BDW; |
| 9770 | data = 3; |
| 9771 | break; |
| 9772 | default: |
| 9773 | WARN(1, "invalid cdclk frequency\n"); |
| 9774 | return; |
| 9775 | } |
| 9776 | |
| 9777 | I915_WRITE(LCPLL_CTL, val); |
| 9778 | |
| 9779 | val = I915_READ(LCPLL_CTL); |
| 9780 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9781 | I915_WRITE(LCPLL_CTL, val); |
| 9782 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9783 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9784 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9785 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9786 | |
| 9787 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9788 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); |
| 9789 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9790 | |
Ville Syrjälä | 7f1052a | 2016-04-26 19:46:32 +0300 | [diff] [blame] | 9791 | I915_WRITE(CDCLK_FREQ, DIV_ROUND_CLOSEST(cdclk, 1000) - 1); |
| 9792 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9793 | intel_update_cdclk(dev); |
| 9794 | |
| 9795 | WARN(cdclk != dev_priv->cdclk_freq, |
| 9796 | "cdclk requested %d kHz but got %d kHz\n", |
| 9797 | cdclk, dev_priv->cdclk_freq); |
| 9798 | } |
| 9799 | |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 9800 | static int broadwell_calc_cdclk(int max_pixclk) |
| 9801 | { |
| 9802 | if (max_pixclk > 540000) |
| 9803 | return 675000; |
| 9804 | else if (max_pixclk > 450000) |
| 9805 | return 540000; |
| 9806 | else if (max_pixclk > 337500) |
| 9807 | return 450000; |
| 9808 | else |
| 9809 | return 337500; |
| 9810 | } |
| 9811 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9812 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9813 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9814 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9815 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9816 | int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9817 | int cdclk; |
| 9818 | |
| 9819 | /* |
| 9820 | * FIXME should also account for plane ratio |
| 9821 | * once 64bpp pixel formats are supported. |
| 9822 | */ |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 9823 | cdclk = broadwell_calc_cdclk(max_pixclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9824 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9825 | if (cdclk > dev_priv->max_cdclk_freq) { |
Maarten Lankhorst | 63ba534 | 2015-11-24 11:29:03 +0100 | [diff] [blame] | 9826 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 9827 | cdclk, dev_priv->max_cdclk_freq); |
| 9828 | return -EINVAL; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9829 | } |
| 9830 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9831 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 9832 | if (!intel_state->active_crtcs) |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 9833 | intel_state->dev_cdclk = broadwell_calc_cdclk(0); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9834 | |
| 9835 | return 0; |
| 9836 | } |
| 9837 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9838 | 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] | 9839 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9840 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9841 | struct intel_atomic_state *old_intel_state = |
| 9842 | to_intel_atomic_state(old_state); |
| 9843 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9844 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9845 | broadwell_set_cdclk(dev, req_cdclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9846 | } |
| 9847 | |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9848 | static int skl_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 9849 | { |
| 9850 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 9851 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
| 9852 | const int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 9853 | int vco = intel_state->cdclk_pll_vco; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9854 | int cdclk; |
| 9855 | |
| 9856 | /* |
| 9857 | * FIXME should also account for plane ratio |
| 9858 | * once 64bpp pixel formats are supported. |
| 9859 | */ |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 9860 | cdclk = skl_calc_cdclk(max_pixclk, vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9861 | |
| 9862 | /* |
| 9863 | * FIXME move the cdclk caclulation to |
| 9864 | * compute_config() so we can fail gracegully. |
| 9865 | */ |
| 9866 | if (cdclk > dev_priv->max_cdclk_freq) { |
| 9867 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 9868 | cdclk, dev_priv->max_cdclk_freq); |
| 9869 | cdclk = dev_priv->max_cdclk_freq; |
| 9870 | } |
| 9871 | |
| 9872 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 9873 | if (!intel_state->active_crtcs) |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 9874 | intel_state->dev_cdclk = skl_calc_cdclk(0, vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9875 | |
| 9876 | return 0; |
| 9877 | } |
| 9878 | |
| 9879 | static void skl_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
| 9880 | { |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 9881 | struct drm_i915_private *dev_priv = to_i915(old_state->dev); |
| 9882 | struct intel_atomic_state *intel_state = to_intel_atomic_state(old_state); |
| 9883 | unsigned int req_cdclk = intel_state->dev_cdclk; |
| 9884 | unsigned int req_vco = intel_state->cdclk_pll_vco; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9885 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 9886 | skl_set_cdclk(dev_priv, req_cdclk, req_vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 9887 | } |
| 9888 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9889 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9890 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9891 | { |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9892 | struct intel_encoder *intel_encoder = |
| 9893 | intel_ddi_get_crtc_new_encoder(crtc_state); |
| 9894 | |
| 9895 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { |
| 9896 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
| 9897 | return -EINVAL; |
| 9898 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9899 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9900 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 9901 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9902 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9903 | } |
| 9904 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9905 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9906 | enum port port, |
| 9907 | struct intel_crtc_state *pipe_config) |
| 9908 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9909 | enum intel_dpll_id id; |
| 9910 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9911 | switch (port) { |
| 9912 | case PORT_A: |
| 9913 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9914 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9915 | break; |
| 9916 | case PORT_B: |
| 9917 | pipe_config->ddi_pll_sel = SKL_DPLL1; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9918 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9919 | break; |
| 9920 | case PORT_C: |
| 9921 | pipe_config->ddi_pll_sel = SKL_DPLL2; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9922 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9923 | break; |
| 9924 | default: |
| 9925 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9926 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9927 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9928 | |
| 9929 | 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] | 9930 | } |
| 9931 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9932 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9933 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9934 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9935 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9936 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9937 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9938 | |
| 9939 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 9940 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 9941 | |
| 9942 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9943 | case SKL_DPLL0: |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9944 | id = DPLL_ID_SKL_DPLL0; |
| 9945 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9946 | case SKL_DPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9947 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9948 | break; |
| 9949 | case SKL_DPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9950 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9951 | break; |
| 9952 | case SKL_DPLL3: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9953 | id = DPLL_ID_SKL_DPLL3; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9954 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9955 | default: |
| 9956 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9957 | return; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9958 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9959 | |
| 9960 | 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] | 9961 | } |
| 9962 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9963 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9964 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9965 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9966 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9967 | enum intel_dpll_id id; |
| 9968 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9969 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 9970 | |
| 9971 | switch (pipe_config->ddi_pll_sel) { |
| 9972 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9973 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9974 | break; |
| 9975 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9976 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9977 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9978 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9979 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9980 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9981 | case PORT_CLK_SEL_LCPLL_810: |
| 9982 | id = DPLL_ID_LCPLL_810; |
| 9983 | break; |
| 9984 | case PORT_CLK_SEL_LCPLL_1350: |
| 9985 | id = DPLL_ID_LCPLL_1350; |
| 9986 | break; |
| 9987 | case PORT_CLK_SEL_LCPLL_2700: |
| 9988 | id = DPLL_ID_LCPLL_2700; |
| 9989 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9990 | default: |
| 9991 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9992 | /* fall through */ |
| 9993 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9994 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9995 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9996 | |
| 9997 | 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] | 9998 | } |
| 9999 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10000 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 10001 | struct intel_crtc_state *pipe_config, |
| 10002 | unsigned long *power_domain_mask) |
| 10003 | { |
| 10004 | struct drm_device *dev = crtc->base.dev; |
| 10005 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10006 | enum intel_display_power_domain power_domain; |
| 10007 | u32 tmp; |
| 10008 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 10009 | /* |
| 10010 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
| 10011 | * transcoder handled below. |
| 10012 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10013 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 10014 | |
| 10015 | /* |
| 10016 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 10017 | * consistency and less surprising code; it's in always on power). |
| 10018 | */ |
| 10019 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 10020 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 10021 | enum pipe trans_edp_pipe; |
| 10022 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 10023 | default: |
| 10024 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 10025 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 10026 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 10027 | trans_edp_pipe = PIPE_A; |
| 10028 | break; |
| 10029 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 10030 | trans_edp_pipe = PIPE_B; |
| 10031 | break; |
| 10032 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 10033 | trans_edp_pipe = PIPE_C; |
| 10034 | break; |
| 10035 | } |
| 10036 | |
| 10037 | if (trans_edp_pipe == crtc->pipe) |
| 10038 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 10039 | } |
| 10040 | |
| 10041 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 10042 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10043 | return false; |
| 10044 | *power_domain_mask |= BIT(power_domain); |
| 10045 | |
| 10046 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 10047 | |
| 10048 | return tmp & PIPECONF_ENABLE; |
| 10049 | } |
| 10050 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10051 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 10052 | struct intel_crtc_state *pipe_config, |
| 10053 | unsigned long *power_domain_mask) |
| 10054 | { |
| 10055 | struct drm_device *dev = crtc->base.dev; |
| 10056 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10057 | enum intel_display_power_domain power_domain; |
| 10058 | enum port port; |
| 10059 | enum transcoder cpu_transcoder; |
| 10060 | u32 tmp; |
| 10061 | |
| 10062 | pipe_config->has_dsi_encoder = false; |
| 10063 | |
| 10064 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 10065 | if (port == PORT_A) |
| 10066 | cpu_transcoder = TRANSCODER_DSI_A; |
| 10067 | else |
| 10068 | cpu_transcoder = TRANSCODER_DSI_C; |
| 10069 | |
| 10070 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 10071 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10072 | continue; |
| 10073 | *power_domain_mask |= BIT(power_domain); |
| 10074 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 10075 | /* |
| 10076 | * The PLL needs to be enabled with a valid divider |
| 10077 | * configuration, otherwise accessing DSI registers will hang |
| 10078 | * the machine. See BSpec North Display Engine |
| 10079 | * registers/MIPI[BXT]. We can break out here early, since we |
| 10080 | * need the same DSI PLL to be enabled for both DSI ports. |
| 10081 | */ |
| 10082 | if (!intel_dsi_pll_is_enabled(dev_priv)) |
| 10083 | break; |
| 10084 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10085 | /* XXX: this works for video mode only */ |
| 10086 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 10087 | if (!(tmp & DPI_ENABLE)) |
| 10088 | continue; |
| 10089 | |
| 10090 | tmp = I915_READ(MIPI_CTRL(port)); |
| 10091 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 10092 | continue; |
| 10093 | |
| 10094 | pipe_config->cpu_transcoder = cpu_transcoder; |
| 10095 | pipe_config->has_dsi_encoder = true; |
| 10096 | break; |
| 10097 | } |
| 10098 | |
| 10099 | return pipe_config->has_dsi_encoder; |
| 10100 | } |
| 10101 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10102 | 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] | 10103 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10104 | { |
| 10105 | struct drm_device *dev = crtc->base.dev; |
| 10106 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10107 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10108 | enum port port; |
| 10109 | uint32_t tmp; |
| 10110 | |
| 10111 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 10112 | |
| 10113 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 10114 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 10115 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10116 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10117 | else if (IS_BROXTON(dev)) |
| 10118 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10119 | else |
| 10120 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 10121 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10122 | pll = pipe_config->shared_dpll; |
| 10123 | if (pll) { |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 10124 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 10125 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10126 | } |
| 10127 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10128 | /* |
| 10129 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 10130 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 10131 | * the PCH transcoder is on. |
| 10132 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 10133 | if (INTEL_INFO(dev)->gen < 9 && |
| 10134 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10135 | pipe_config->has_pch_encoder = true; |
| 10136 | |
| 10137 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 10138 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 10139 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 10140 | |
| 10141 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 10142 | } |
| 10143 | } |
| 10144 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10145 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10146 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10147 | { |
| 10148 | struct drm_device *dev = crtc->base.dev; |
| 10149 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10150 | enum intel_display_power_domain power_domain; |
| 10151 | unsigned long power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10152 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10153 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10154 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 10155 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 10156 | return false; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10157 | power_domain_mask = BIT(power_domain); |
| 10158 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10159 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10160 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10161 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10162 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10163 | if (IS_BROXTON(dev_priv)) { |
| 10164 | bxt_get_dsi_transcoder_state(crtc, pipe_config, |
| 10165 | &power_domain_mask); |
| 10166 | WARN_ON(active && pipe_config->has_dsi_encoder); |
| 10167 | if (pipe_config->has_dsi_encoder) |
| 10168 | active = true; |
| 10169 | } |
| 10170 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10171 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10172 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10173 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10174 | if (!pipe_config->has_dsi_encoder) { |
| 10175 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 10176 | intel_get_pipe_timings(crtc, pipe_config); |
| 10177 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10178 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 10179 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10180 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 10181 | pipe_config->gamma_mode = |
| 10182 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 10183 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 10184 | if (INTEL_INFO(dev)->gen >= 9) { |
| 10185 | skl_init_scalers(dev, crtc, pipe_config); |
| 10186 | } |
| 10187 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 10188 | if (INTEL_INFO(dev)->gen >= 9) { |
| 10189 | pipe_config->scaler_state.scaler_id = -1; |
| 10190 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
| 10191 | } |
| 10192 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10193 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 10194 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
| 10195 | power_domain_mask |= BIT(power_domain); |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 10196 | if (INTEL_INFO(dev)->gen >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10197 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 10198 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 10199 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10200 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10201 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10202 | if (IS_HASWELL(dev)) |
| 10203 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 10204 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10205 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10206 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 10207 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 10208 | pipe_config->pixel_multiplier = |
| 10209 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 10210 | } else { |
| 10211 | pipe_config->pixel_multiplier = 1; |
| 10212 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10213 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10214 | out: |
| 10215 | for_each_power_domain(power_domain, power_domain_mask) |
| 10216 | intel_display_power_put(dev_priv, power_domain); |
| 10217 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10218 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10219 | } |
| 10220 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10221 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10222 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10223 | { |
| 10224 | struct drm_device *dev = crtc->dev; |
| 10225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10226 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10227 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10228 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10229 | if (plane_state && plane_state->visible) { |
| 10230 | unsigned int width = plane_state->base.crtc_w; |
| 10231 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10232 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 10233 | |
| 10234 | switch (stride) { |
| 10235 | default: |
| 10236 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 10237 | width, stride); |
| 10238 | stride = 256; |
| 10239 | /* fallthrough */ |
| 10240 | case 256: |
| 10241 | case 512: |
| 10242 | case 1024: |
| 10243 | case 2048: |
| 10244 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10245 | } |
| 10246 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10247 | cntl |= CURSOR_ENABLE | |
| 10248 | CURSOR_GAMMA_ENABLE | |
| 10249 | CURSOR_FORMAT_ARGB | |
| 10250 | CURSOR_STRIDE(stride); |
| 10251 | |
| 10252 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10253 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10254 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10255 | if (intel_crtc->cursor_cntl != 0 && |
| 10256 | (intel_crtc->cursor_base != base || |
| 10257 | intel_crtc->cursor_size != size || |
| 10258 | intel_crtc->cursor_cntl != cntl)) { |
| 10259 | /* On these chipsets we can only modify the base/size/stride |
| 10260 | * whilst the cursor is disabled. |
| 10261 | */ |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10262 | I915_WRITE(CURCNTR(PIPE_A), 0); |
| 10263 | POSTING_READ(CURCNTR(PIPE_A)); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10264 | intel_crtc->cursor_cntl = 0; |
| 10265 | } |
| 10266 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10267 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10268 | I915_WRITE(CURBASE(PIPE_A), base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10269 | intel_crtc->cursor_base = base; |
| 10270 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10271 | |
| 10272 | if (intel_crtc->cursor_size != size) { |
| 10273 | I915_WRITE(CURSIZE, size); |
| 10274 | intel_crtc->cursor_size = size; |
| 10275 | } |
| 10276 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10277 | if (intel_crtc->cursor_cntl != cntl) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10278 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
| 10279 | POSTING_READ(CURCNTR(PIPE_A)); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10280 | intel_crtc->cursor_cntl = cntl; |
| 10281 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10282 | } |
| 10283 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10284 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10285 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10286 | { |
| 10287 | struct drm_device *dev = crtc->dev; |
| 10288 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10289 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10290 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | 663f312 | 2015-12-14 13:16:48 +0200 | [diff] [blame] | 10291 | uint32_t cntl = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10292 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10293 | if (plane_state && plane_state->visible) { |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10294 | cntl = MCURSOR_GAMMA_ENABLE; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10295 | switch (plane_state->base.crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10296 | case 64: |
| 10297 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 10298 | break; |
| 10299 | case 128: |
| 10300 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 10301 | break; |
| 10302 | case 256: |
| 10303 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 10304 | break; |
| 10305 | default: |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10306 | MISSING_CASE(plane_state->base.crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10307 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10308 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10309 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10310 | |
Bob Paauwe | fc6f93b | 2015-08-31 14:03:30 -0700 | [diff] [blame] | 10311 | if (HAS_DDI(dev)) |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10312 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10313 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10314 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) |
| 10315 | cntl |= CURSOR_ROTATE_180; |
| 10316 | } |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 10317 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10318 | if (intel_crtc->cursor_cntl != cntl) { |
| 10319 | I915_WRITE(CURCNTR(pipe), cntl); |
| 10320 | POSTING_READ(CURCNTR(pipe)); |
| 10321 | intel_crtc->cursor_cntl = cntl; |
| 10322 | } |
| 10323 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10324 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10325 | I915_WRITE(CURBASE(pipe), base); |
| 10326 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10327 | |
| 10328 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10329 | } |
| 10330 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10331 | /* 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] | 10332 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10333 | const struct intel_plane_state *plane_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10334 | { |
| 10335 | struct drm_device *dev = crtc->dev; |
| 10336 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10337 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10338 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10339 | u32 base = intel_crtc->cursor_addr; |
| 10340 | u32 pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10341 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10342 | if (plane_state) { |
| 10343 | int x = plane_state->base.crtc_x; |
| 10344 | int y = plane_state->base.crtc_y; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10345 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10346 | if (x < 0) { |
| 10347 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 10348 | x = -x; |
| 10349 | } |
| 10350 | pos |= x << CURSOR_X_SHIFT; |
| 10351 | |
| 10352 | if (y < 0) { |
| 10353 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 10354 | y = -y; |
| 10355 | } |
| 10356 | pos |= y << CURSOR_Y_SHIFT; |
| 10357 | |
| 10358 | /* ILK+ do this automagically */ |
| 10359 | if (HAS_GMCH_DISPLAY(dev) && |
| 10360 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { |
| 10361 | base += (plane_state->base.crtc_h * |
| 10362 | plane_state->base.crtc_w - 1) * 4; |
| 10363 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10364 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10365 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10366 | I915_WRITE(CURPOS(pipe), pos); |
| 10367 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 10368 | if (IS_845G(dev) || IS_I865G(dev)) |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10369 | i845_update_cursor(crtc, base, plane_state); |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10370 | else |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10371 | i9xx_update_cursor(crtc, base, plane_state); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10372 | } |
| 10373 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10374 | static bool cursor_size_ok(struct drm_device *dev, |
| 10375 | uint32_t width, uint32_t height) |
| 10376 | { |
| 10377 | if (width == 0 || height == 0) |
| 10378 | return false; |
| 10379 | |
| 10380 | /* |
| 10381 | * 845g/865g are special in that they are only limited by |
| 10382 | * the width of their cursors, the height is arbitrary up to |
| 10383 | * the precision of the register. Everything else requires |
| 10384 | * square cursors, limited to a few power-of-two sizes. |
| 10385 | */ |
| 10386 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 10387 | if ((width & 63) != 0) |
| 10388 | return false; |
| 10389 | |
| 10390 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 10391 | return false; |
| 10392 | |
| 10393 | if (height > 1023) |
| 10394 | return false; |
| 10395 | } else { |
| 10396 | switch (width | height) { |
| 10397 | case 256: |
| 10398 | case 128: |
| 10399 | if (IS_GEN2(dev)) |
| 10400 | return false; |
| 10401 | case 64: |
| 10402 | break; |
| 10403 | default: |
| 10404 | return false; |
| 10405 | } |
| 10406 | } |
| 10407 | |
| 10408 | return true; |
| 10409 | } |
| 10410 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10411 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 10412 | static struct drm_display_mode load_detect_mode = { |
| 10413 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10414 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10415 | }; |
| 10416 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10417 | struct drm_framebuffer * |
| 10418 | __intel_framebuffer_create(struct drm_device *dev, |
| 10419 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10420 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10421 | { |
| 10422 | struct intel_framebuffer *intel_fb; |
| 10423 | int ret; |
| 10424 | |
| 10425 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10426 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10427 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10428 | |
| 10429 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10430 | if (ret) |
| 10431 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10432 | |
| 10433 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10434 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10435 | err: |
| 10436 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10437 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10438 | } |
| 10439 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 10440 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10441 | intel_framebuffer_create(struct drm_device *dev, |
| 10442 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10443 | struct drm_i915_gem_object *obj) |
| 10444 | { |
| 10445 | struct drm_framebuffer *fb; |
| 10446 | int ret; |
| 10447 | |
| 10448 | ret = i915_mutex_lock_interruptible(dev); |
| 10449 | if (ret) |
| 10450 | return ERR_PTR(ret); |
| 10451 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 10452 | mutex_unlock(&dev->struct_mutex); |
| 10453 | |
| 10454 | return fb; |
| 10455 | } |
| 10456 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10457 | static u32 |
| 10458 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 10459 | { |
| 10460 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 10461 | return ALIGN(pitch, 64); |
| 10462 | } |
| 10463 | |
| 10464 | static u32 |
| 10465 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 10466 | { |
| 10467 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 10468 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10469 | } |
| 10470 | |
| 10471 | static struct drm_framebuffer * |
| 10472 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 10473 | struct drm_display_mode *mode, |
| 10474 | int depth, int bpp) |
| 10475 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10476 | struct drm_framebuffer *fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10477 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 10478 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10479 | |
Dave Gordon | d37cd8a | 2016-04-22 19:14:32 +0100 | [diff] [blame] | 10480 | obj = i915_gem_object_create(dev, |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10481 | intel_framebuffer_size_for_mode(mode, bpp)); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 10482 | if (IS_ERR(obj)) |
| 10483 | return ERR_CAST(obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10484 | |
| 10485 | mode_cmd.width = mode->hdisplay; |
| 10486 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 10487 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 10488 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 10489 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10490 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10491 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
| 10492 | if (IS_ERR(fb)) |
| 10493 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10494 | |
| 10495 | return fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10496 | } |
| 10497 | |
| 10498 | static struct drm_framebuffer * |
| 10499 | mode_fits_in_fbdev(struct drm_device *dev, |
| 10500 | struct drm_display_mode *mode) |
| 10501 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 10502 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10503 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10504 | struct drm_i915_gem_object *obj; |
| 10505 | struct drm_framebuffer *fb; |
| 10506 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10507 | if (!dev_priv->fbdev) |
| 10508 | return NULL; |
| 10509 | |
| 10510 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10511 | return NULL; |
| 10512 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10513 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10514 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10515 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10516 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10517 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 10518 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10519 | return NULL; |
| 10520 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10521 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10522 | return NULL; |
| 10523 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10524 | drm_framebuffer_reference(fb); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10525 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 10526 | #else |
| 10527 | return NULL; |
| 10528 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10529 | } |
| 10530 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10531 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 10532 | struct drm_crtc *crtc, |
| 10533 | struct drm_display_mode *mode, |
| 10534 | struct drm_framebuffer *fb, |
| 10535 | int x, int y) |
| 10536 | { |
| 10537 | struct drm_plane_state *plane_state; |
| 10538 | int hdisplay, vdisplay; |
| 10539 | int ret; |
| 10540 | |
| 10541 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 10542 | if (IS_ERR(plane_state)) |
| 10543 | return PTR_ERR(plane_state); |
| 10544 | |
| 10545 | if (mode) |
| 10546 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 10547 | else |
| 10548 | hdisplay = vdisplay = 0; |
| 10549 | |
| 10550 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 10551 | if (ret) |
| 10552 | return ret; |
| 10553 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 10554 | plane_state->crtc_x = 0; |
| 10555 | plane_state->crtc_y = 0; |
| 10556 | plane_state->crtc_w = hdisplay; |
| 10557 | plane_state->crtc_h = vdisplay; |
| 10558 | plane_state->src_x = x << 16; |
| 10559 | plane_state->src_y = y << 16; |
| 10560 | plane_state->src_w = hdisplay << 16; |
| 10561 | plane_state->src_h = vdisplay << 16; |
| 10562 | |
| 10563 | return 0; |
| 10564 | } |
| 10565 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10566 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10567 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10568 | struct intel_load_detect_pipe *old, |
| 10569 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10570 | { |
| 10571 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10572 | struct intel_encoder *intel_encoder = |
| 10573 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10574 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10575 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10576 | struct drm_crtc *crtc = NULL; |
| 10577 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10578 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10579 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10580 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10581 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10582 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10583 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10584 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10585 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10586 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10587 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10588 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10589 | old->restore_state = NULL; |
| 10590 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10591 | retry: |
| 10592 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 10593 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10594 | goto fail; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10595 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10596 | /* |
| 10597 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10598 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10599 | * - if the connector already has an assigned crtc, use it (but make |
| 10600 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10601 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10602 | * - try to find the first unused crtc that can drive this connector, |
| 10603 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10604 | */ |
| 10605 | |
| 10606 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10607 | if (connector->state->crtc) { |
| 10608 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10609 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10610 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10611 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10612 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10613 | |
| 10614 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10615 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10616 | } |
| 10617 | |
| 10618 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10619 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10620 | i++; |
| 10621 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10622 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10623 | |
| 10624 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10625 | if (ret) |
| 10626 | goto fail; |
| 10627 | |
| 10628 | if (possible_crtc->state->enable) { |
| 10629 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10630 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10631 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10632 | |
| 10633 | crtc = possible_crtc; |
| 10634 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10635 | } |
| 10636 | |
| 10637 | /* |
| 10638 | * If we didn't find an unused CRTC, don't use any. |
| 10639 | */ |
| 10640 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10641 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10642 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10643 | } |
| 10644 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10645 | found: |
| 10646 | intel_crtc = to_intel_crtc(crtc); |
| 10647 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 10648 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 10649 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10650 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10651 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10652 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10653 | restore_state = drm_atomic_state_alloc(dev); |
| 10654 | if (!state || !restore_state) { |
| 10655 | ret = -ENOMEM; |
| 10656 | goto fail; |
| 10657 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10658 | |
| 10659 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10660 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10661 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10662 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10663 | if (IS_ERR(connector_state)) { |
| 10664 | ret = PTR_ERR(connector_state); |
| 10665 | goto fail; |
| 10666 | } |
| 10667 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10668 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10669 | if (ret) |
| 10670 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10671 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10672 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10673 | if (IS_ERR(crtc_state)) { |
| 10674 | ret = PTR_ERR(crtc_state); |
| 10675 | goto fail; |
| 10676 | } |
| 10677 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10678 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10679 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10680 | if (!mode) |
| 10681 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10682 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10683 | /* We need a framebuffer large enough to accommodate all accesses |
| 10684 | * that the plane may generate whilst we perform load detection. |
| 10685 | * We can not rely on the fbcon either being present (we get called |
| 10686 | * during its initialisation to detect all boot displays, or it may |
| 10687 | * not even exist) or that it is large enough to satisfy the |
| 10688 | * requested mode. |
| 10689 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10690 | fb = mode_fits_in_fbdev(dev, mode); |
| 10691 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10692 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10693 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10694 | } else |
| 10695 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10696 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10697 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10698 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10699 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10700 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10701 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 10702 | if (ret) |
| 10703 | goto fail; |
| 10704 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10705 | drm_framebuffer_unreference(fb); |
| 10706 | |
| 10707 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
| 10708 | if (ret) |
| 10709 | goto fail; |
| 10710 | |
| 10711 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10712 | if (!ret) |
| 10713 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); |
| 10714 | if (!ret) |
| 10715 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); |
| 10716 | if (ret) { |
| 10717 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10718 | goto fail; |
| 10719 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10720 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10721 | ret = drm_atomic_commit(state); |
| 10722 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10723 | 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] | 10724 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10725 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10726 | |
| 10727 | old->restore_state = restore_state; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10728 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10729 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 10730 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10731 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10732 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10733 | fail: |
Ander Conselvan de Oliveira | e5d958e | 2015-04-21 17:12:57 +0300 | [diff] [blame] | 10734 | drm_atomic_state_free(state); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10735 | drm_atomic_state_free(restore_state); |
| 10736 | restore_state = state = NULL; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10737 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10738 | if (ret == -EDEADLK) { |
| 10739 | drm_modeset_backoff(ctx); |
| 10740 | goto retry; |
| 10741 | } |
| 10742 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10743 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10744 | } |
| 10745 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10746 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10747 | struct intel_load_detect_pipe *old, |
| 10748 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10749 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10750 | struct intel_encoder *intel_encoder = |
| 10751 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10752 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10753 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10754 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10755 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10756 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10757 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10758 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10759 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10760 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10761 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10762 | |
| 10763 | ret = drm_atomic_commit(state); |
| 10764 | if (ret) { |
| 10765 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
| 10766 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10767 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10768 | } |
| 10769 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10770 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10771 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10772 | { |
| 10773 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10774 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10775 | |
| 10776 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10777 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10778 | else if (HAS_PCH_SPLIT(dev)) |
| 10779 | return 120000; |
| 10780 | else if (!IS_GEN2(dev)) |
| 10781 | return 96000; |
| 10782 | else |
| 10783 | return 48000; |
| 10784 | } |
| 10785 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10786 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10787 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10788 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10789 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10790 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10791 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10792 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10793 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10794 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10795 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10796 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10797 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10798 | |
| 10799 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10800 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10801 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10802 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10803 | |
| 10804 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10805 | if (IS_PINEVIEW(dev)) { |
| 10806 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10807 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10808 | } else { |
| 10809 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10810 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10811 | } |
| 10812 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 10813 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10814 | if (IS_PINEVIEW(dev)) |
| 10815 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10816 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10817 | else |
| 10818 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10819 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10820 | |
| 10821 | switch (dpll & DPLL_MODE_MASK) { |
| 10822 | case DPLLB_MODE_DAC_SERIAL: |
| 10823 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10824 | 5 : 10; |
| 10825 | break; |
| 10826 | case DPLLB_MODE_LVDS: |
| 10827 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10828 | 7 : 14; |
| 10829 | break; |
| 10830 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10831 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10832 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10833 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10834 | } |
| 10835 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10836 | if (IS_PINEVIEW(dev)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10837 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10838 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10839 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10840 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 10841 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10842 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10843 | |
| 10844 | if (is_lvds) { |
| 10845 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10846 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10847 | |
| 10848 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10849 | clock.p2 = 7; |
| 10850 | else |
| 10851 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10852 | } else { |
| 10853 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10854 | clock.p1 = 2; |
| 10855 | else { |
| 10856 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10857 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10858 | } |
| 10859 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10860 | clock.p2 = 4; |
| 10861 | else |
| 10862 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10863 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10864 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10865 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10866 | } |
| 10867 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10868 | /* |
| 10869 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10870 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10871 | * encoder's get_config() function. |
| 10872 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10873 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10874 | } |
| 10875 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10876 | int intel_dotclock_calculate(int link_freq, |
| 10877 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10878 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10879 | /* |
| 10880 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10881 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10882 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10883 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10884 | * |
| 10885 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10886 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10887 | */ |
| 10888 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10889 | if (!m_n->link_n) |
| 10890 | return 0; |
| 10891 | |
| 10892 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 10893 | } |
| 10894 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10895 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10896 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10897 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10898 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10899 | |
| 10900 | /* read out port_clock from the DPLL */ |
| 10901 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10902 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10903 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10904 | * In case there is an active pipe without active ports, |
| 10905 | * we may need some idea for the dotclock anyway. |
| 10906 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10907 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10908 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10909 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10910 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10911 | } |
| 10912 | |
| 10913 | /** Returns the currently programmed mode of the given pipe. */ |
| 10914 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 10915 | struct drm_crtc *crtc) |
| 10916 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 10917 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10918 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10919 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10920 | struct drm_display_mode *mode; |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10921 | struct intel_crtc_state *pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10922 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 10923 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10924 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 10925 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10926 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10927 | |
| 10928 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10929 | if (!mode) |
| 10930 | return NULL; |
| 10931 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10932 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10933 | if (!pipe_config) { |
| 10934 | kfree(mode); |
| 10935 | return NULL; |
| 10936 | } |
| 10937 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10938 | /* |
| 10939 | * Construct a pipe_config sufficient for getting the clock info |
| 10940 | * back out of crtc_clock_get. |
| 10941 | * |
| 10942 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 10943 | * to use a real value here instead. |
| 10944 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10945 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
| 10946 | pipe_config->pixel_multiplier = 1; |
| 10947 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 10948 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 10949 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
| 10950 | i9xx_crtc_clock_get(intel_crtc, pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10951 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10952 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10953 | mode->hdisplay = (htot & 0xffff) + 1; |
| 10954 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 10955 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 10956 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 10957 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 10958 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 10959 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 10960 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 10961 | |
| 10962 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10963 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10964 | kfree(pipe_config); |
| 10965 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10966 | return mode; |
| 10967 | } |
| 10968 | |
Tvrtko Ursulin | 7d99373 | 2016-04-28 12:57:00 +0100 | [diff] [blame] | 10969 | void intel_mark_busy(struct drm_i915_private *dev_priv) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10970 | { |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10971 | if (dev_priv->mm.busy) |
| 10972 | return; |
| 10973 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10974 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10975 | i915_update_gfx_val(dev_priv); |
Tvrtko Ursulin | 7d99373 | 2016-04-28 12:57:00 +0100 | [diff] [blame] | 10976 | if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 10977 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10978 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10979 | } |
| 10980 | |
Tvrtko Ursulin | 7d99373 | 2016-04-28 12:57:00 +0100 | [diff] [blame] | 10981 | void intel_mark_idle(struct drm_i915_private *dev_priv) |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10982 | { |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10983 | if (!dev_priv->mm.busy) |
| 10984 | return; |
| 10985 | |
| 10986 | dev_priv->mm.busy = false; |
| 10987 | |
Tvrtko Ursulin | 7d99373 | 2016-04-28 12:57:00 +0100 | [diff] [blame] | 10988 | if (INTEL_GEN(dev_priv) >= 6) |
| 10989 | gen6_rps_idle(dev_priv); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 10990 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10991 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10992 | } |
| 10993 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10994 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10995 | { |
| 10996 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10997 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 10998 | struct intel_flip_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10999 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11000 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11001 | work = intel_crtc->flip_work; |
| 11002 | intel_crtc->flip_work = NULL; |
| 11003 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11004 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11005 | if (work) { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11006 | cancel_work_sync(&work->mmio_work); |
| 11007 | cancel_work_sync(&work->unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11008 | kfree(work); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11009 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11010 | |
| 11011 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11012 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11013 | kfree(intel_crtc); |
| 11014 | } |
| 11015 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11016 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 11017 | { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11018 | struct intel_flip_work *work = |
| 11019 | container_of(__work, struct intel_flip_work, unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11020 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 11021 | struct drm_device *dev = crtc->base.dev; |
| 11022 | struct drm_plane *primary = crtc->base.primary; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11023 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11024 | if (is_mmio_work(work)) |
| 11025 | flush_work(&work->mmio_work); |
| 11026 | |
| 11027 | mutex_lock(&dev->struct_mutex); |
| 11028 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); |
| 11029 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 11030 | |
| 11031 | if (work->flip_queued_req) |
| 11032 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
| 11033 | mutex_unlock(&dev->struct_mutex); |
| 11034 | |
| 11035 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
| 11036 | intel_fbc_post_update(crtc); |
| 11037 | drm_framebuffer_unreference(work->old_fb); |
| 11038 | |
| 11039 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
| 11040 | atomic_dec(&crtc->unpin_work_count); |
| 11041 | |
| 11042 | kfree(work); |
| 11043 | } |
| 11044 | |
| 11045 | /* Is 'a' after or equal to 'b'? */ |
| 11046 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 11047 | { |
| 11048 | return !((a - b) & 0x80000000); |
| 11049 | } |
| 11050 | |
| 11051 | static bool __pageflip_finished_cs(struct intel_crtc *crtc, |
| 11052 | struct intel_flip_work *work) |
| 11053 | { |
| 11054 | struct drm_device *dev = crtc->base.dev; |
| 11055 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11056 | unsigned reset_counter; |
| 11057 | |
| 11058 | reset_counter = i915_reset_counter(&dev_priv->gpu_error); |
| 11059 | if (crtc->reset_counter != reset_counter) |
| 11060 | return true; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11061 | |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11062 | /* |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11063 | * The relevant registers doen't exist on pre-ctg. |
| 11064 | * As the flip done interrupt doesn't trigger for mmio |
| 11065 | * flips on gmch platforms, a flip count check isn't |
| 11066 | * really needed there. But since ctg has the registers, |
| 11067 | * include it in the check anyway. |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11068 | */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11069 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 11070 | return true; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11071 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11072 | /* |
| 11073 | * BDW signals flip done immediately if the plane |
| 11074 | * is disabled, even if the plane enable is already |
| 11075 | * armed to occur at the next vblank :( |
| 11076 | */ |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 11077 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11078 | /* |
| 11079 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 11080 | * used the same base address. In that case the mmio flip might |
| 11081 | * have completed, but the CS hasn't even executed the flip yet. |
| 11082 | * |
| 11083 | * A flip count check isn't enough as the CS might have updated |
| 11084 | * the base address just after start of vblank, but before we |
| 11085 | * managed to process the interrupt. This means we'd complete the |
| 11086 | * CS flip too soon. |
| 11087 | * |
| 11088 | * Combining both checks should get us a good enough result. It may |
| 11089 | * still happen that the CS flip has been executed, but has not |
| 11090 | * yet actually completed. But in case the base address is the same |
| 11091 | * anyway, we don't really care. |
| 11092 | */ |
| 11093 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 11094 | crtc->flip_work->gtt_offset && |
| 11095 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
| 11096 | crtc->flip_work->flip_count); |
| 11097 | } |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11098 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11099 | static bool |
| 11100 | __pageflip_finished_mmio(struct intel_crtc *crtc, |
| 11101 | struct intel_flip_work *work) |
| 11102 | { |
| 11103 | /* |
| 11104 | * MMIO work completes when vblank is different from |
| 11105 | * flip_queued_vblank. |
| 11106 | * |
| 11107 | * Reset counter value doesn't matter, this is handled by |
| 11108 | * i915_wait_request finishing early, so no need to handle |
| 11109 | * reset here. |
| 11110 | */ |
| 11111 | return intel_crtc_get_vblank_counter(crtc) != work->flip_queued_vblank; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11112 | } |
| 11113 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11114 | |
| 11115 | static bool pageflip_finished(struct intel_crtc *crtc, |
| 11116 | struct intel_flip_work *work) |
| 11117 | { |
| 11118 | if (!atomic_read(&work->pending)) |
| 11119 | return false; |
| 11120 | |
| 11121 | smp_rmb(); |
| 11122 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11123 | if (is_mmio_work(work)) |
| 11124 | return __pageflip_finished_mmio(crtc, work); |
| 11125 | else |
| 11126 | return __pageflip_finished_cs(crtc, work); |
| 11127 | } |
| 11128 | |
| 11129 | void intel_finish_page_flip_cs(struct drm_i915_private *dev_priv, int pipe) |
| 11130 | { |
| 11131 | struct drm_device *dev = dev_priv->dev; |
| 11132 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 11133 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11134 | struct intel_flip_work *work; |
| 11135 | unsigned long flags; |
| 11136 | |
| 11137 | /* Ignore early vblank irqs */ |
| 11138 | if (!crtc) |
| 11139 | return; |
| 11140 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11141 | /* |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11142 | * This is called both by irq handlers and the reset code (to complete |
| 11143 | * lost pageflips) so needs the full irqsave spinlocks. |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11144 | */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11145 | spin_lock_irqsave(&dev->event_lock, flags); |
| 11146 | work = intel_crtc->flip_work; |
| 11147 | |
| 11148 | if (work != NULL && |
| 11149 | !is_mmio_work(work) && |
| 11150 | pageflip_finished(intel_crtc, work)) |
| 11151 | page_flip_completed(intel_crtc); |
| 11152 | |
| 11153 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11154 | } |
| 11155 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11156 | void intel_finish_page_flip_mmio(struct drm_i915_private *dev_priv, int pipe) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11157 | { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11158 | struct drm_device *dev = dev_priv->dev; |
| 11159 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 11160 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11161 | struct intel_flip_work *work; |
| 11162 | unsigned long flags; |
| 11163 | |
| 11164 | /* Ignore early vblank irqs */ |
| 11165 | if (!crtc) |
| 11166 | return; |
| 11167 | |
| 11168 | /* |
| 11169 | * This is called both by irq handlers and the reset code (to complete |
| 11170 | * lost pageflips) so needs the full irqsave spinlocks. |
| 11171 | */ |
| 11172 | spin_lock_irqsave(&dev->event_lock, flags); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11173 | work = intel_crtc->flip_work; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11174 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11175 | if (work != NULL && |
| 11176 | is_mmio_work(work) && |
| 11177 | pageflip_finished(intel_crtc, work)) |
| 11178 | page_flip_completed(intel_crtc); |
Maarten Lankhorst | 6885843 | 2016-05-17 15:07:52 +0200 | [diff] [blame] | 11179 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11180 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 11181 | } |
| 11182 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11183 | static inline void intel_mark_page_flip_active(struct intel_crtc *crtc, |
| 11184 | struct intel_flip_work *work) |
| 11185 | { |
| 11186 | work->flip_queued_vblank = intel_crtc_get_vblank_counter(crtc); |
| 11187 | |
| 11188 | /* Ensure that the work item is consistent when activating it ... */ |
| 11189 | smp_mb__before_atomic(); |
| 11190 | atomic_set(&work->pending, 1); |
| 11191 | } |
| 11192 | |
| 11193 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 11194 | struct drm_crtc *crtc, |
| 11195 | struct drm_framebuffer *fb, |
| 11196 | struct drm_i915_gem_object *obj, |
| 11197 | struct drm_i915_gem_request *req, |
| 11198 | uint32_t flags) |
| 11199 | { |
| 11200 | struct intel_engine_cs *engine = req->engine; |
| 11201 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11202 | u32 flip_mask; |
| 11203 | int ret; |
| 11204 | |
| 11205 | ret = intel_ring_begin(req, 6); |
| 11206 | if (ret) |
| 11207 | return ret; |
| 11208 | |
| 11209 | /* Can't queue multiple flips, so wait for the previous |
| 11210 | * one to finish before executing the next. |
| 11211 | */ |
| 11212 | if (intel_crtc->plane) |
| 11213 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11214 | else |
| 11215 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
| 11216 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 11217 | intel_ring_emit(engine, MI_NOOP); |
| 11218 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
| 11219 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 11220 | intel_ring_emit(engine, fb->pitches[0]); |
| 11221 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); |
| 11222 | intel_ring_emit(engine, 0); /* aux display base address, unused */ |
| 11223 | |
| 11224 | return 0; |
| 11225 | } |
| 11226 | |
| 11227 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 11228 | struct drm_crtc *crtc, |
| 11229 | struct drm_framebuffer *fb, |
| 11230 | struct drm_i915_gem_object *obj, |
| 11231 | struct drm_i915_gem_request *req, |
| 11232 | uint32_t flags) |
| 11233 | { |
| 11234 | struct intel_engine_cs *engine = req->engine; |
| 11235 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11236 | u32 flip_mask; |
| 11237 | int ret; |
| 11238 | |
| 11239 | ret = intel_ring_begin(req, 6); |
| 11240 | if (ret) |
| 11241 | return ret; |
| 11242 | |
| 11243 | if (intel_crtc->plane) |
| 11244 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11245 | else |
| 11246 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
| 11247 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 11248 | intel_ring_emit(engine, MI_NOOP); |
| 11249 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | |
| 11250 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 11251 | intel_ring_emit(engine, fb->pitches[0]); |
| 11252 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); |
| 11253 | intel_ring_emit(engine, MI_NOOP); |
| 11254 | |
| 11255 | return 0; |
| 11256 | } |
| 11257 | |
| 11258 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 11259 | struct drm_crtc *crtc, |
| 11260 | struct drm_framebuffer *fb, |
| 11261 | struct drm_i915_gem_object *obj, |
| 11262 | struct drm_i915_gem_request *req, |
| 11263 | uint32_t flags) |
| 11264 | { |
| 11265 | struct intel_engine_cs *engine = req->engine; |
| 11266 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11268 | uint32_t pf, pipesrc; |
| 11269 | int ret; |
| 11270 | |
| 11271 | ret = intel_ring_begin(req, 4); |
| 11272 | if (ret) |
| 11273 | return ret; |
| 11274 | |
| 11275 | /* i965+ uses the linear or tiled offsets from the |
| 11276 | * Display Registers (which do not change across a page-flip) |
| 11277 | * so we need only reprogram the base address. |
| 11278 | */ |
| 11279 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
| 11280 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 11281 | intel_ring_emit(engine, fb->pitches[0]); |
| 11282 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset | |
| 11283 | obj->tiling_mode); |
| 11284 | |
| 11285 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 11286 | * untested on non-native modes, so ignore it for now. |
| 11287 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 11288 | */ |
| 11289 | pf = 0; |
| 11290 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
| 11291 | intel_ring_emit(engine, pf | pipesrc); |
| 11292 | |
| 11293 | return 0; |
| 11294 | } |
| 11295 | |
| 11296 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 11297 | struct drm_crtc *crtc, |
| 11298 | struct drm_framebuffer *fb, |
| 11299 | struct drm_i915_gem_object *obj, |
| 11300 | struct drm_i915_gem_request *req, |
| 11301 | uint32_t flags) |
| 11302 | { |
| 11303 | struct intel_engine_cs *engine = req->engine; |
| 11304 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11305 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11306 | uint32_t pf, pipesrc; |
| 11307 | int ret; |
| 11308 | |
| 11309 | ret = intel_ring_begin(req, 4); |
| 11310 | if (ret) |
| 11311 | return ret; |
| 11312 | |
| 11313 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
| 11314 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 11315 | intel_ring_emit(engine, fb->pitches[0] | obj->tiling_mode); |
| 11316 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); |
| 11317 | |
| 11318 | /* Contrary to the suggestions in the documentation, |
| 11319 | * "Enable Panel Fitter" does not seem to be required when page |
| 11320 | * flipping with a non-native mode, and worse causes a normal |
| 11321 | * modeset to fail. |
| 11322 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 11323 | */ |
| 11324 | pf = 0; |
| 11325 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
| 11326 | intel_ring_emit(engine, pf | pipesrc); |
| 11327 | |
| 11328 | return 0; |
| 11329 | } |
| 11330 | |
| 11331 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 11332 | struct drm_crtc *crtc, |
| 11333 | struct drm_framebuffer *fb, |
| 11334 | struct drm_i915_gem_object *obj, |
| 11335 | struct drm_i915_gem_request *req, |
| 11336 | uint32_t flags) |
| 11337 | { |
| 11338 | struct intel_engine_cs *engine = req->engine; |
| 11339 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11340 | uint32_t plane_bit = 0; |
| 11341 | int len, ret; |
| 11342 | |
| 11343 | switch (intel_crtc->plane) { |
| 11344 | case PLANE_A: |
| 11345 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 11346 | break; |
| 11347 | case PLANE_B: |
| 11348 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 11349 | break; |
| 11350 | case PLANE_C: |
| 11351 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 11352 | break; |
| 11353 | default: |
| 11354 | WARN_ONCE(1, "unknown plane in flip command\n"); |
| 11355 | return -ENODEV; |
| 11356 | } |
| 11357 | |
| 11358 | len = 4; |
| 11359 | if (engine->id == RCS) { |
| 11360 | len += 6; |
| 11361 | /* |
| 11362 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 11363 | * 48bits addresses, and we need a NOOP for the batch size to |
| 11364 | * stay even. |
| 11365 | */ |
| 11366 | if (IS_GEN8(dev)) |
| 11367 | len += 2; |
| 11368 | } |
| 11369 | |
| 11370 | /* |
| 11371 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 11372 | * "The full packet must be contained within the same cache line." |
| 11373 | * |
| 11374 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 11375 | * cacheline, if we ever start emitting more commands before |
| 11376 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 11377 | * then do the cacheline alignment, and finally emit the |
| 11378 | * MI_DISPLAY_FLIP. |
| 11379 | */ |
| 11380 | ret = intel_ring_cacheline_align(req); |
| 11381 | if (ret) |
| 11382 | return ret; |
| 11383 | |
| 11384 | ret = intel_ring_begin(req, len); |
| 11385 | if (ret) |
| 11386 | return ret; |
| 11387 | |
| 11388 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 11389 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 11390 | * more than one flip event at any time (or ensure that one flip message |
| 11391 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 11392 | * Experimentation says that BCS works despite DERRMR masking all |
| 11393 | * flip-done completion events and that unmasking all planes at once |
| 11394 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 11395 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 11396 | */ |
| 11397 | if (engine->id == RCS) { |
| 11398 | intel_ring_emit(engine, MI_LOAD_REGISTER_IMM(1)); |
| 11399 | intel_ring_emit_reg(engine, DERRMR); |
| 11400 | intel_ring_emit(engine, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 11401 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 11402 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
| 11403 | if (IS_GEN8(dev)) |
| 11404 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM_GEN8 | |
| 11405 | MI_SRM_LRM_GLOBAL_GTT); |
| 11406 | else |
| 11407 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM | |
| 11408 | MI_SRM_LRM_GLOBAL_GTT); |
| 11409 | intel_ring_emit_reg(engine, DERRMR); |
| 11410 | intel_ring_emit(engine, engine->scratch.gtt_offset + 256); |
| 11411 | if (IS_GEN8(dev)) { |
| 11412 | intel_ring_emit(engine, 0); |
| 11413 | intel_ring_emit(engine, MI_NOOP); |
| 11414 | } |
| 11415 | } |
| 11416 | |
| 11417 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | plane_bit); |
| 11418 | intel_ring_emit(engine, (fb->pitches[0] | obj->tiling_mode)); |
| 11419 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); |
| 11420 | intel_ring_emit(engine, (MI_NOOP)); |
| 11421 | |
| 11422 | return 0; |
| 11423 | } |
| 11424 | |
| 11425 | static bool use_mmio_flip(struct intel_engine_cs *engine, |
| 11426 | struct drm_i915_gem_object *obj) |
| 11427 | { |
| 11428 | /* |
| 11429 | * This is not being used for older platforms, because |
| 11430 | * non-availability of flip done interrupt forces us to use |
| 11431 | * CS flips. Older platforms derive flip done using some clever |
| 11432 | * tricks involving the flip_pending status bits and vblank irqs. |
| 11433 | * So using MMIO flips there would disrupt this mechanism. |
| 11434 | */ |
| 11435 | |
| 11436 | if (engine == NULL) |
| 11437 | return true; |
| 11438 | |
| 11439 | if (INTEL_GEN(engine->i915) < 5) |
| 11440 | return false; |
| 11441 | |
| 11442 | if (i915.use_mmio_flip < 0) |
| 11443 | return false; |
| 11444 | else if (i915.use_mmio_flip > 0) |
| 11445 | return true; |
| 11446 | else if (i915.enable_execlists) |
| 11447 | return true; |
| 11448 | else if (obj->base.dma_buf && |
| 11449 | !reservation_object_test_signaled_rcu(obj->base.dma_buf->resv, |
| 11450 | false)) |
| 11451 | return true; |
| 11452 | else |
| 11453 | return engine != i915_gem_request_get_engine(obj->last_write_req); |
| 11454 | } |
| 11455 | |
| 11456 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 11457 | unsigned int rotation, |
| 11458 | struct intel_flip_work *work) |
| 11459 | { |
| 11460 | struct drm_device *dev = intel_crtc->base.dev; |
| 11461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11462 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
| 11463 | const enum pipe pipe = intel_crtc->pipe; |
| 11464 | u32 ctl, stride, tile_height; |
| 11465 | |
| 11466 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 11467 | ctl &= ~PLANE_CTL_TILED_MASK; |
| 11468 | switch (fb->modifier[0]) { |
| 11469 | case DRM_FORMAT_MOD_NONE: |
| 11470 | break; |
| 11471 | case I915_FORMAT_MOD_X_TILED: |
| 11472 | ctl |= PLANE_CTL_TILED_X; |
| 11473 | break; |
| 11474 | case I915_FORMAT_MOD_Y_TILED: |
| 11475 | ctl |= PLANE_CTL_TILED_Y; |
| 11476 | break; |
| 11477 | case I915_FORMAT_MOD_Yf_TILED: |
| 11478 | ctl |= PLANE_CTL_TILED_YF; |
| 11479 | break; |
| 11480 | default: |
| 11481 | MISSING_CASE(fb->modifier[0]); |
| 11482 | } |
| 11483 | |
| 11484 | /* |
| 11485 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 11486 | * linear buffers or in number of tiles for tiled buffers. |
| 11487 | */ |
| 11488 | if (intel_rotation_90_or_270(rotation)) { |
| 11489 | /* stride = Surface height in tiles */ |
| 11490 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); |
| 11491 | stride = DIV_ROUND_UP(fb->height, tile_height); |
| 11492 | } else { |
| 11493 | stride = fb->pitches[0] / |
| 11494 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
| 11495 | fb->pixel_format); |
| 11496 | } |
| 11497 | |
| 11498 | /* |
| 11499 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 11500 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 11501 | */ |
| 11502 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 11503 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 11504 | |
| 11505 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
| 11506 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 11507 | } |
| 11508 | |
| 11509 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 11510 | struct intel_flip_work *work) |
| 11511 | { |
| 11512 | struct drm_device *dev = intel_crtc->base.dev; |
| 11513 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11514 | struct intel_framebuffer *intel_fb = |
| 11515 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 11516 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 11517 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
| 11518 | u32 dspcntr; |
| 11519 | |
| 11520 | dspcntr = I915_READ(reg); |
| 11521 | |
| 11522 | if (obj->tiling_mode != I915_TILING_NONE) |
| 11523 | dspcntr |= DISPPLANE_TILED; |
| 11524 | else |
| 11525 | dspcntr &= ~DISPPLANE_TILED; |
| 11526 | |
| 11527 | I915_WRITE(reg, dspcntr); |
| 11528 | |
| 11529 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
| 11530 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
| 11531 | } |
| 11532 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11533 | static void intel_mmio_flip_work_func(struct work_struct *w) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11534 | { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11535 | struct intel_flip_work *work = |
| 11536 | container_of(w, struct intel_flip_work, mmio_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11537 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 11538 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 11539 | struct intel_framebuffer *intel_fb = |
| 11540 | to_intel_framebuffer(crtc->base.primary->fb); |
| 11541 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 11542 | |
| 11543 | if (work->flip_queued_req) |
| 11544 | WARN_ON(__i915_wait_request(work->flip_queued_req, |
| 11545 | false, NULL, |
| 11546 | &dev_priv->rps.mmioflips)); |
| 11547 | |
| 11548 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 11549 | if (obj->base.dma_buf) |
| 11550 | WARN_ON(reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 11551 | false, false, |
| 11552 | MAX_SCHEDULE_TIMEOUT) < 0); |
| 11553 | |
| 11554 | intel_pipe_update_start(crtc); |
| 11555 | |
| 11556 | if (INTEL_GEN(dev_priv) >= 9) |
| 11557 | skl_do_mmio_flip(crtc, work->rotation, work); |
| 11558 | else |
| 11559 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 11560 | ilk_do_mmio_flip(crtc, work); |
| 11561 | |
| 11562 | intel_pipe_update_end(crtc, work); |
| 11563 | } |
| 11564 | |
| 11565 | static int intel_default_queue_flip(struct drm_device *dev, |
| 11566 | struct drm_crtc *crtc, |
| 11567 | struct drm_framebuffer *fb, |
| 11568 | struct drm_i915_gem_object *obj, |
| 11569 | struct drm_i915_gem_request *req, |
| 11570 | uint32_t flags) |
| 11571 | { |
| 11572 | return -ENODEV; |
| 11573 | } |
| 11574 | |
| 11575 | static bool __pageflip_stall_check_cs(struct drm_i915_private *dev_priv, |
| 11576 | struct intel_crtc *intel_crtc, |
| 11577 | struct intel_flip_work *work) |
| 11578 | { |
| 11579 | u32 addr, vblank; |
| 11580 | |
| 11581 | if (!atomic_read(&work->pending)) |
| 11582 | return false; |
| 11583 | |
| 11584 | smp_rmb(); |
| 11585 | |
| 11586 | vblank = intel_crtc_get_vblank_counter(intel_crtc); |
| 11587 | if (work->flip_ready_vblank == 0) { |
| 11588 | if (work->flip_queued_req && |
| 11589 | !i915_gem_request_completed(work->flip_queued_req, true)) |
| 11590 | return false; |
| 11591 | |
| 11592 | work->flip_ready_vblank = vblank; |
| 11593 | } |
| 11594 | |
| 11595 | if (vblank - work->flip_ready_vblank < 3) |
| 11596 | return false; |
| 11597 | |
| 11598 | /* Potential stall - if we see that the flip has happened, |
| 11599 | * assume a missed interrupt. */ |
| 11600 | if (INTEL_GEN(dev_priv) >= 4) |
| 11601 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 11602 | else |
| 11603 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 11604 | |
| 11605 | /* There is a potential issue here with a false positive after a flip |
| 11606 | * to the same address. We could address this by checking for a |
| 11607 | * non-incrementing frame counter. |
| 11608 | */ |
| 11609 | return addr == work->gtt_offset; |
| 11610 | } |
| 11611 | |
| 11612 | void intel_check_page_flip(struct drm_i915_private *dev_priv, int pipe) |
| 11613 | { |
| 11614 | struct drm_device *dev = dev_priv->dev; |
| 11615 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11616 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11617 | struct intel_flip_work *work; |
| 11618 | |
| 11619 | WARN_ON(!in_interrupt()); |
| 11620 | |
| 11621 | if (crtc == NULL) |
| 11622 | return; |
| 11623 | |
| 11624 | spin_lock(&dev->event_lock); |
| 11625 | work = intel_crtc->flip_work; |
| 11626 | |
| 11627 | if (work != NULL && !is_mmio_work(work) && |
| 11628 | __pageflip_stall_check_cs(dev_priv, intel_crtc, work)) { |
| 11629 | WARN_ONCE(1, |
| 11630 | "Kicking stuck page flip: queued at %d, now %d\n", |
| 11631 | work->flip_queued_vblank, intel_crtc_get_vblank_counter(intel_crtc)); |
| 11632 | page_flip_completed(intel_crtc); |
| 11633 | work = NULL; |
| 11634 | } |
| 11635 | |
| 11636 | if (work != NULL && !is_mmio_work(work) && |
| 11637 | intel_crtc_get_vblank_counter(intel_crtc) - work->flip_queued_vblank > 1) |
| 11638 | intel_queue_rps_boost_for_request(work->flip_queued_req); |
| 11639 | spin_unlock(&dev->event_lock); |
| 11640 | } |
| 11641 | |
| 11642 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 11643 | struct drm_framebuffer *fb, |
| 11644 | struct drm_pending_vblank_event *event, |
| 11645 | uint32_t page_flip_flags) |
| 11646 | { |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11647 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | aa420dd | 2016-05-17 15:07:51 +0200 | [diff] [blame] | 11648 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11649 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 11650 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 11651 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11652 | struct drm_plane *primary = crtc->primary; |
| 11653 | enum pipe pipe = intel_crtc->pipe; |
| 11654 | struct intel_flip_work *work; |
| 11655 | struct intel_engine_cs *engine; |
| 11656 | bool mmio_flip; |
| 11657 | struct drm_i915_gem_request *request = NULL; |
| 11658 | int ret; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11659 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11660 | /* |
| 11661 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 11662 | * check to be safe. In the future we may enable pageflipping from |
| 11663 | * a disabled primary plane. |
| 11664 | */ |
| 11665 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 11666 | return -EBUSY; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 11667 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11668 | /* Can't change pixel format via MI display flips. */ |
| 11669 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
| 11670 | return -EINVAL; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11671 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11672 | /* |
| 11673 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 11674 | * Note that pitch changes could also affect these register. |
| 11675 | */ |
| 11676 | if (INTEL_INFO(dev)->gen > 3 && |
| 11677 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 11678 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
| 11679 | return -EINVAL; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11680 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11681 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 11682 | goto out_hang; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11683 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11684 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
| 11685 | if (work == NULL) |
| 11686 | return -ENOMEM; |
| 11687 | |
| 11688 | work->event = event; |
| 11689 | work->crtc = crtc; |
| 11690 | work->old_fb = old_fb; |
| 11691 | INIT_WORK(&work->unpin_work, intel_unpin_work_fn); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11692 | |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 11693 | ret = drm_crtc_vblank_get(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11694 | if (ret) |
| 11695 | goto free_work; |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 11696 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11697 | /* We borrow the event spin lock for protecting flip_work */ |
| 11698 | spin_lock_irq(&dev->event_lock); |
| 11699 | if (intel_crtc->flip_work) { |
| 11700 | /* Before declaring the flip queue wedged, check if |
| 11701 | * the hardware completed the operation behind our backs. |
| 11702 | */ |
| 11703 | if (pageflip_finished(intel_crtc, intel_crtc->flip_work)) { |
| 11704 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 11705 | page_flip_completed(intel_crtc); |
| 11706 | } else { |
| 11707 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
| 11708 | spin_unlock_irq(&dev->event_lock); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 11709 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11710 | drm_crtc_vblank_put(crtc); |
| 11711 | kfree(work); |
| 11712 | return -EBUSY; |
| 11713 | } |
| 11714 | } |
| 11715 | intel_crtc->flip_work = work; |
| 11716 | spin_unlock_irq(&dev->event_lock); |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11717 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11718 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 11719 | flush_workqueue(dev_priv->wq); |
| 11720 | |
| 11721 | /* Reference the objects for the scheduled work. */ |
| 11722 | drm_framebuffer_reference(work->old_fb); |
| 11723 | drm_gem_object_reference(&obj->base); |
| 11724 | |
| 11725 | crtc->primary->fb = fb; |
| 11726 | update_state_fb(crtc->primary); |
| 11727 | intel_fbc_pre_update(intel_crtc); |
| 11728 | |
| 11729 | work->pending_flip_obj = obj; |
| 11730 | |
| 11731 | ret = i915_mutex_lock_interruptible(dev); |
| 11732 | if (ret) |
| 11733 | goto cleanup; |
| 11734 | |
| 11735 | intel_crtc->reset_counter = i915_reset_counter(&dev_priv->gpu_error); |
| 11736 | if (__i915_reset_in_progress_or_wedged(intel_crtc->reset_counter)) { |
| 11737 | ret = -EIO; |
| 11738 | goto cleanup; |
| 11739 | } |
| 11740 | |
| 11741 | atomic_inc(&intel_crtc->unpin_work_count); |
| 11742 | |
| 11743 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 11744 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
| 11745 | |
| 11746 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
| 11747 | engine = &dev_priv->engine[BCS]; |
| 11748 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
| 11749 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 11750 | engine = NULL; |
| 11751 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
| 11752 | engine = &dev_priv->engine[BCS]; |
| 11753 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 11754 | engine = i915_gem_request_get_engine(obj->last_write_req); |
| 11755 | if (engine == NULL || engine->id != RCS) |
| 11756 | engine = &dev_priv->engine[BCS]; |
| 11757 | } else { |
| 11758 | engine = &dev_priv->engine[RCS]; |
| 11759 | } |
| 11760 | |
| 11761 | mmio_flip = use_mmio_flip(engine, obj); |
| 11762 | |
| 11763 | /* When using CS flips, we want to emit semaphores between rings. |
| 11764 | * However, when using mmio flips we will create a task to do the |
| 11765 | * synchronisation, so all we want here is to pin the framebuffer |
| 11766 | * into the display plane and skip any waits. |
| 11767 | */ |
| 11768 | if (!mmio_flip) { |
| 11769 | ret = i915_gem_object_sync(obj, engine, &request); |
| 11770 | if (!ret && !request) { |
| 11771 | request = i915_gem_request_alloc(engine, NULL); |
| 11772 | ret = PTR_ERR_OR_ZERO(request); |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11773 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11774 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11775 | if (ret) |
| 11776 | goto cleanup_pending; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11777 | } |
| 11778 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11779 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); |
| 11780 | if (ret) |
| 11781 | goto cleanup_pending; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11782 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11783 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
| 11784 | obj, 0); |
| 11785 | work->gtt_offset += intel_crtc->dspaddr_offset; |
| 11786 | work->rotation = crtc->primary->state->rotation; |
| 11787 | |
| 11788 | if (mmio_flip) { |
| 11789 | INIT_WORK(&work->mmio_work, intel_mmio_flip_work_func); |
| 11790 | |
| 11791 | i915_gem_request_assign(&work->flip_queued_req, |
| 11792 | obj->last_write_req); |
| 11793 | |
| 11794 | schedule_work(&work->mmio_work); |
| 11795 | } else { |
| 11796 | i915_gem_request_assign(&work->flip_queued_req, request); |
| 11797 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, |
| 11798 | page_flip_flags); |
| 11799 | if (ret) |
| 11800 | goto cleanup_unpin; |
| 11801 | |
| 11802 | intel_mark_page_flip_active(intel_crtc, work); |
| 11803 | |
| 11804 | i915_add_request_no_flush(request); |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11805 | } |
| 11806 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11807 | i915_gem_track_fb(intel_fb_obj(old_fb), obj, |
| 11808 | to_intel_plane(primary)->frontbuffer_bit); |
| 11809 | mutex_unlock(&dev->struct_mutex); |
| 11810 | |
| 11811 | intel_frontbuffer_flip_prepare(dev, |
| 11812 | to_intel_plane(primary)->frontbuffer_bit); |
| 11813 | |
| 11814 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 11815 | |
| 11816 | return 0; |
| 11817 | |
| 11818 | cleanup_unpin: |
| 11819 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); |
| 11820 | cleanup_pending: |
| 11821 | if (!IS_ERR_OR_NULL(request)) |
| 11822 | i915_add_request_no_flush(request); |
| 11823 | atomic_dec(&intel_crtc->unpin_work_count); |
| 11824 | mutex_unlock(&dev->struct_mutex); |
| 11825 | cleanup: |
| 11826 | crtc->primary->fb = old_fb; |
| 11827 | update_state_fb(crtc->primary); |
| 11828 | |
| 11829 | drm_gem_object_unreference_unlocked(&obj->base); |
| 11830 | drm_framebuffer_unreference(work->old_fb); |
| 11831 | |
| 11832 | spin_lock_irq(&dev->event_lock); |
| 11833 | intel_crtc->flip_work = NULL; |
| 11834 | spin_unlock_irq(&dev->event_lock); |
| 11835 | |
| 11836 | drm_crtc_vblank_put(crtc); |
| 11837 | free_work: |
| 11838 | kfree(work); |
| 11839 | |
| 11840 | if (ret == -EIO) { |
| 11841 | struct drm_atomic_state *state; |
| 11842 | struct drm_plane_state *plane_state; |
| 11843 | |
| 11844 | out_hang: |
| 11845 | state = drm_atomic_state_alloc(dev); |
| 11846 | if (!state) |
| 11847 | return -ENOMEM; |
| 11848 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 11849 | |
| 11850 | retry: |
| 11851 | plane_state = drm_atomic_get_plane_state(state, primary); |
| 11852 | ret = PTR_ERR_OR_ZERO(plane_state); |
| 11853 | if (!ret) { |
| 11854 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 11855 | |
| 11856 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 11857 | if (!ret) |
| 11858 | ret = drm_atomic_commit(state); |
| 11859 | } |
| 11860 | |
| 11861 | if (ret == -EDEADLK) { |
| 11862 | drm_modeset_backoff(state->acquire_ctx); |
| 11863 | drm_atomic_state_clear(state); |
| 11864 | goto retry; |
| 11865 | } |
| 11866 | |
| 11867 | if (ret) |
| 11868 | drm_atomic_state_free(state); |
| 11869 | |
| 11870 | if (ret == 0 && event) { |
| 11871 | spin_lock_irq(&dev->event_lock); |
| 11872 | drm_crtc_send_vblank_event(crtc, event); |
| 11873 | spin_unlock_irq(&dev->event_lock); |
| 11874 | } |
| 11875 | } |
| 11876 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11877 | } |
| 11878 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11879 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11880 | /** |
| 11881 | * intel_wm_need_update - Check whether watermarks need updating |
| 11882 | * @plane: drm plane |
| 11883 | * @state: new plane state |
| 11884 | * |
| 11885 | * Check current plane state versus the new one to determine whether |
| 11886 | * watermarks need to be recalculated. |
| 11887 | * |
| 11888 | * Returns true or false. |
| 11889 | */ |
| 11890 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 11891 | struct drm_plane_state *state) |
| 11892 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11893 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 11894 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 11895 | |
| 11896 | /* Update watermarks on tiling or size changes. */ |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11897 | if (new->visible != cur->visible) |
| 11898 | return true; |
| 11899 | |
| 11900 | if (!cur->base.fb || !new->base.fb) |
| 11901 | return false; |
| 11902 | |
| 11903 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || |
| 11904 | cur->base.rotation != new->base.rotation || |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11905 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || |
| 11906 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || |
| 11907 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || |
| 11908 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11909 | return true; |
| 11910 | |
| 11911 | return false; |
| 11912 | } |
| 11913 | |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11914 | static bool needs_scaling(struct intel_plane_state *state) |
| 11915 | { |
| 11916 | int src_w = drm_rect_width(&state->src) >> 16; |
| 11917 | int src_h = drm_rect_height(&state->src) >> 16; |
| 11918 | int dst_w = drm_rect_width(&state->dst); |
| 11919 | int dst_h = drm_rect_height(&state->dst); |
| 11920 | |
| 11921 | return (src_w != dst_w || src_h != dst_h); |
| 11922 | } |
| 11923 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11924 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
| 11925 | struct drm_plane_state *plane_state) |
| 11926 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11927 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11928 | struct drm_crtc *crtc = crtc_state->crtc; |
| 11929 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11930 | struct drm_plane *plane = plane_state->plane; |
| 11931 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11932 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11933 | struct intel_plane_state *old_plane_state = |
| 11934 | to_intel_plane_state(plane->state); |
| 11935 | int idx = intel_crtc->base.base.id, ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11936 | bool mode_changed = needs_modeset(crtc_state); |
| 11937 | bool was_crtc_enabled = crtc->state->active; |
| 11938 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11939 | bool turn_off, turn_on, visible, was_visible; |
| 11940 | struct drm_framebuffer *fb = plane_state->fb; |
| 11941 | |
| 11942 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && |
| 11943 | plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11944 | ret = skl_update_scaler_plane( |
| 11945 | to_intel_crtc_state(crtc_state), |
| 11946 | to_intel_plane_state(plane_state)); |
| 11947 | if (ret) |
| 11948 | return ret; |
| 11949 | } |
| 11950 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11951 | was_visible = old_plane_state->visible; |
| 11952 | visible = to_intel_plane_state(plane_state)->visible; |
| 11953 | |
| 11954 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 11955 | was_visible = false; |
| 11956 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 11957 | /* |
| 11958 | * Visibility is calculated as if the crtc was on, but |
| 11959 | * after scaler setup everything depends on it being off |
| 11960 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 11961 | * |
| 11962 | * FIXME this is wrong for watermarks. Watermarks should also |
| 11963 | * be computed as if the pipe would be active. Perhaps move |
| 11964 | * per-plane wm computation to the .check_plane() hook, and |
| 11965 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 11966 | */ |
| 11967 | if (!is_crtc_enabled) |
| 11968 | to_intel_plane_state(plane_state)->visible = visible = false; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11969 | |
| 11970 | if (!was_visible && !visible) |
| 11971 | return 0; |
| 11972 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11973 | if (fb != old_plane_state->base.fb) |
| 11974 | pipe_config->fb_changed = true; |
| 11975 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11976 | turn_off = was_visible && (!visible || mode_changed); |
| 11977 | turn_on = visible && (!was_visible || mode_changed); |
| 11978 | |
| 11979 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, |
| 11980 | plane->base.id, fb ? fb->base.id : -1); |
| 11981 | |
| 11982 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", |
| 11983 | plane->base.id, was_visible, visible, |
| 11984 | turn_off, turn_on, mode_changed); |
| 11985 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11986 | if (turn_on) { |
| 11987 | pipe_config->update_wm_pre = true; |
| 11988 | |
| 11989 | /* must disable cxsr around plane enable/disable */ |
| 11990 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 11991 | pipe_config->disable_cxsr = true; |
| 11992 | } else if (turn_off) { |
| 11993 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11994 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11995 | /* must disable cxsr around plane enable/disable */ |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11996 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11997 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11998 | } else if (intel_wm_need_update(plane, plane_state)) { |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11999 | /* FIXME bollocks */ |
| 12000 | pipe_config->update_wm_pre = true; |
| 12001 | pipe_config->update_wm_post = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12002 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12003 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12004 | /* Pre-gen9 platforms need two-step watermark updates */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12005 | if ((pipe_config->update_wm_pre || pipe_config->update_wm_post) && |
| 12006 | INTEL_INFO(dev)->gen < 9 && dev_priv->display.optimize_watermarks) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12007 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; |
| 12008 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 12009 | if (visible || was_visible) |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 12010 | pipe_config->fb_bits |= to_intel_plane(plane)->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 12011 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 12012 | /* |
| 12013 | * WaCxSRDisabledForSpriteScaling:ivb |
| 12014 | * |
| 12015 | * cstate->update_wm was already set above, so this flag will |
| 12016 | * take effect when we commit and program watermarks. |
| 12017 | */ |
| 12018 | if (plane->type == DRM_PLANE_TYPE_OVERLAY && IS_IVYBRIDGE(dev) && |
| 12019 | needs_scaling(to_intel_plane_state(plane_state)) && |
| 12020 | !needs_scaling(old_plane_state)) |
| 12021 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12022 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12023 | return 0; |
| 12024 | } |
| 12025 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12026 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 12027 | const struct intel_encoder *b) |
| 12028 | { |
| 12029 | /* masks could be asymmetric, so check both ways */ |
| 12030 | return a == b || (a->cloneable & (1 << b->type) && |
| 12031 | b->cloneable & (1 << a->type)); |
| 12032 | } |
| 12033 | |
| 12034 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 12035 | struct intel_crtc *crtc, |
| 12036 | struct intel_encoder *encoder) |
| 12037 | { |
| 12038 | struct intel_encoder *source_encoder; |
| 12039 | struct drm_connector *connector; |
| 12040 | struct drm_connector_state *connector_state; |
| 12041 | int i; |
| 12042 | |
| 12043 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12044 | if (connector_state->crtc != &crtc->base) |
| 12045 | continue; |
| 12046 | |
| 12047 | source_encoder = |
| 12048 | to_intel_encoder(connector_state->best_encoder); |
| 12049 | if (!encoders_cloneable(encoder, source_encoder)) |
| 12050 | return false; |
| 12051 | } |
| 12052 | |
| 12053 | return true; |
| 12054 | } |
| 12055 | |
| 12056 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 12057 | struct intel_crtc *crtc) |
| 12058 | { |
| 12059 | struct intel_encoder *encoder; |
| 12060 | struct drm_connector *connector; |
| 12061 | struct drm_connector_state *connector_state; |
| 12062 | int i; |
| 12063 | |
| 12064 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12065 | if (connector_state->crtc != &crtc->base) |
| 12066 | continue; |
| 12067 | |
| 12068 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12069 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
| 12070 | return false; |
| 12071 | } |
| 12072 | |
| 12073 | return true; |
| 12074 | } |
| 12075 | |
| 12076 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 12077 | struct drm_crtc_state *crtc_state) |
| 12078 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 12079 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12080 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12081 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 12082 | struct intel_crtc_state *pipe_config = |
| 12083 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12084 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12085 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12086 | bool mode_changed = needs_modeset(crtc_state); |
| 12087 | |
| 12088 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { |
| 12089 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 12090 | return -EINVAL; |
| 12091 | } |
| 12092 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12093 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12094 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12095 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12096 | if (mode_changed && crtc_state->enable && |
| 12097 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12098 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12099 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 12100 | pipe_config); |
| 12101 | if (ret) |
| 12102 | return ret; |
| 12103 | } |
| 12104 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 12105 | if (crtc_state->color_mgmt_changed) { |
| 12106 | ret = intel_color_check(crtc, crtc_state); |
| 12107 | if (ret) |
| 12108 | return ret; |
| 12109 | } |
| 12110 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 12111 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12112 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 12113 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12114 | if (ret) { |
| 12115 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12116 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12117 | } |
| 12118 | } |
| 12119 | |
| 12120 | if (dev_priv->display.compute_intermediate_wm && |
| 12121 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 12122 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 12123 | return 0; |
| 12124 | |
| 12125 | /* |
| 12126 | * Calculate 'intermediate' watermarks that satisfy both the |
| 12127 | * old state and the new state. We can program these |
| 12128 | * immediately. |
| 12129 | */ |
| 12130 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, |
| 12131 | intel_crtc, |
| 12132 | pipe_config); |
| 12133 | if (ret) { |
| 12134 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 12135 | return ret; |
| 12136 | } |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 12137 | } else if (dev_priv->display.compute_intermediate_wm) { |
| 12138 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) |
| 12139 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12140 | } |
| 12141 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 12142 | if (INTEL_INFO(dev)->gen >= 9) { |
| 12143 | if (mode_changed) |
| 12144 | ret = skl_update_scaler_crtc(pipe_config); |
| 12145 | |
| 12146 | if (!ret) |
| 12147 | ret = intel_atomic_setup_scalers(dev, intel_crtc, |
| 12148 | pipe_config); |
| 12149 | } |
| 12150 | |
| 12151 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12152 | } |
| 12153 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 12154 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12155 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12156 | .atomic_begin = intel_begin_crtc_commit, |
| 12157 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12158 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12159 | }; |
| 12160 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12161 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 12162 | { |
| 12163 | struct intel_connector *connector; |
| 12164 | |
| 12165 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 12166 | if (connector->base.state->crtc) |
| 12167 | drm_connector_unreference(&connector->base); |
| 12168 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12169 | if (connector->base.encoder) { |
| 12170 | connector->base.state->best_encoder = |
| 12171 | connector->base.encoder; |
| 12172 | connector->base.state->crtc = |
| 12173 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 12174 | |
| 12175 | drm_connector_reference(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12176 | } else { |
| 12177 | connector->base.state->best_encoder = NULL; |
| 12178 | connector->base.state->crtc = NULL; |
| 12179 | } |
| 12180 | } |
| 12181 | } |
| 12182 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12183 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 12184 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12185 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12186 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12187 | int bpp = pipe_config->pipe_bpp; |
| 12188 | |
| 12189 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 12190 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12191 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12192 | |
| 12193 | /* Don't use an invalid EDID bpc value */ |
| 12194 | if (connector->base.display_info.bpc && |
| 12195 | connector->base.display_info.bpc * 3 < bpp) { |
| 12196 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 12197 | bpp, connector->base.display_info.bpc*3); |
| 12198 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 12199 | } |
| 12200 | |
Jani Nikula | 013dd9e | 2016-01-13 16:35:20 +0200 | [diff] [blame] | 12201 | /* Clamp bpp to default limit on screens without EDID 1.4 */ |
| 12202 | if (connector->base.display_info.bpc == 0) { |
| 12203 | int type = connector->base.connector_type; |
| 12204 | int clamp_bpp = 24; |
| 12205 | |
| 12206 | /* Fall back to 18 bpp when DP sink capability is unknown. */ |
| 12207 | if (type == DRM_MODE_CONNECTOR_DisplayPort || |
| 12208 | type == DRM_MODE_CONNECTOR_eDP) |
| 12209 | clamp_bpp = 18; |
| 12210 | |
| 12211 | if (bpp > clamp_bpp) { |
| 12212 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", |
| 12213 | bpp, clamp_bpp); |
| 12214 | pipe_config->pipe_bpp = clamp_bpp; |
| 12215 | } |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12216 | } |
| 12217 | } |
| 12218 | |
| 12219 | static int |
| 12220 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12221 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12222 | { |
| 12223 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12224 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12225 | struct drm_connector *connector; |
| 12226 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12227 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12228 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 12229 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12230 | bpp = 10*3; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12231 | else if (INTEL_INFO(dev)->gen >= 5) |
| 12232 | bpp = 12*3; |
| 12233 | else |
| 12234 | bpp = 8*3; |
| 12235 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12236 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12237 | pipe_config->pipe_bpp = bpp; |
| 12238 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12239 | state = pipe_config->base.state; |
| 12240 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12241 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12242 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12243 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12244 | continue; |
| 12245 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12246 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 12247 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12248 | } |
| 12249 | |
| 12250 | return bpp; |
| 12251 | } |
| 12252 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12253 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 12254 | { |
| 12255 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 12256 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 12257 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12258 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 12259 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 12260 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 12261 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 12262 | } |
| 12263 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12264 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12265 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12266 | const char *context) |
| 12267 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12268 | struct drm_device *dev = crtc->base.dev; |
| 12269 | struct drm_plane *plane; |
| 12270 | struct intel_plane *intel_plane; |
| 12271 | struct intel_plane_state *state; |
| 12272 | struct drm_framebuffer *fb; |
| 12273 | |
| 12274 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 12275 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12276 | |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 12277 | 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] | 12278 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 12279 | pipe_config->pipe_bpp, pipe_config->dither); |
| 12280 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 12281 | pipe_config->has_pch_encoder, |
| 12282 | pipe_config->fdi_lanes, |
| 12283 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 12284 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 12285 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12286 | 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] | 12287 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12288 | pipe_config->lane_count, |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12289 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 12290 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 12291 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12292 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12293 | 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] | 12294 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12295 | pipe_config->lane_count, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12296 | pipe_config->dp_m2_n2.gmch_m, |
| 12297 | pipe_config->dp_m2_n2.gmch_n, |
| 12298 | pipe_config->dp_m2_n2.link_m, |
| 12299 | pipe_config->dp_m2_n2.link_n, |
| 12300 | pipe_config->dp_m2_n2.tu); |
| 12301 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 12302 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 12303 | pipe_config->has_audio, |
| 12304 | pipe_config->has_infoframe); |
| 12305 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12306 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12307 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12308 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12309 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 12310 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 12311 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 12312 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 12313 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Tvrtko Ursulin | 0ec463d | 2015-05-13 16:51:08 +0100 | [diff] [blame] | 12314 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 12315 | crtc->num_scalers, |
| 12316 | pipe_config->scaler_state.scaler_users, |
| 12317 | pipe_config->scaler_state.scaler_id); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12318 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 12319 | pipe_config->gmch_pfit.control, |
| 12320 | pipe_config->gmch_pfit.pgm_ratios, |
| 12321 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12322 | 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] | 12323 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12324 | pipe_config->pch_pfit.size, |
| 12325 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12326 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 12327 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12328 | |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12329 | if (IS_BROXTON(dev)) { |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12330 | 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] | 12331 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12332 | "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] | 12333 | pipe_config->ddi_pll_sel, |
| 12334 | pipe_config->dpll_hw_state.ebb0, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12335 | pipe_config->dpll_hw_state.ebb4, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12336 | pipe_config->dpll_hw_state.pll0, |
| 12337 | pipe_config->dpll_hw_state.pll1, |
| 12338 | pipe_config->dpll_hw_state.pll2, |
| 12339 | pipe_config->dpll_hw_state.pll3, |
| 12340 | pipe_config->dpll_hw_state.pll6, |
| 12341 | pipe_config->dpll_hw_state.pll8, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12342 | pipe_config->dpll_hw_state.pll9, |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12343 | pipe_config->dpll_hw_state.pll10, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12344 | pipe_config->dpll_hw_state.pcsdw12); |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 12345 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12346 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
| 12347 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", |
| 12348 | pipe_config->ddi_pll_sel, |
| 12349 | pipe_config->dpll_hw_state.ctrl1, |
| 12350 | pipe_config->dpll_hw_state.cfgcr1, |
| 12351 | pipe_config->dpll_hw_state.cfgcr2); |
| 12352 | } else if (HAS_DDI(dev)) { |
Ville Syrjälä | 1260f07 | 2016-02-17 21:41:08 +0200 | [diff] [blame] | 12353 | 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] | 12354 | pipe_config->ddi_pll_sel, |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12355 | pipe_config->dpll_hw_state.wrpll, |
| 12356 | pipe_config->dpll_hw_state.spll); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12357 | } else { |
| 12358 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " |
| 12359 | "fp0: 0x%x, fp1: 0x%x\n", |
| 12360 | pipe_config->dpll_hw_state.dpll, |
| 12361 | pipe_config->dpll_hw_state.dpll_md, |
| 12362 | pipe_config->dpll_hw_state.fp0, |
| 12363 | pipe_config->dpll_hw_state.fp1); |
| 12364 | } |
| 12365 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12366 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 12367 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 12368 | intel_plane = to_intel_plane(plane); |
| 12369 | if (intel_plane->pipe != crtc->pipe) |
| 12370 | continue; |
| 12371 | |
| 12372 | state = to_intel_plane_state(plane->state); |
| 12373 | fb = state->base.fb; |
| 12374 | if (!fb) { |
| 12375 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 12376 | "disabled, scaler_id = %d\n", |
| 12377 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12378 | plane->base.id, intel_plane->pipe, |
| 12379 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 12380 | drm_plane_index(plane), state->scaler_id); |
| 12381 | continue; |
| 12382 | } |
| 12383 | |
| 12384 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 12385 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12386 | plane->base.id, intel_plane->pipe, |
| 12387 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 12388 | drm_plane_index(plane)); |
| 12389 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 12390 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 12391 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 12392 | state->scaler_id, |
| 12393 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 12394 | drm_rect_width(&state->src) >> 16, |
| 12395 | drm_rect_height(&state->src) >> 16, |
| 12396 | state->dst.x1, state->dst.y1, |
| 12397 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 12398 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12399 | } |
| 12400 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12401 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12402 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12403 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12404 | struct drm_connector *connector; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12405 | unsigned int used_ports = 0; |
| 12406 | |
| 12407 | /* |
| 12408 | * Walk the connector list instead of the encoder |
| 12409 | * list to detect the problem on ddi platforms |
| 12410 | * where there's just one encoder per digital port. |
| 12411 | */ |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 12412 | drm_for_each_connector(connector, dev) { |
| 12413 | struct drm_connector_state *connector_state; |
| 12414 | struct intel_encoder *encoder; |
| 12415 | |
| 12416 | connector_state = drm_atomic_get_existing_connector_state(state, connector); |
| 12417 | if (!connector_state) |
| 12418 | connector_state = connector->state; |
| 12419 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12420 | if (!connector_state->best_encoder) |
| 12421 | continue; |
| 12422 | |
| 12423 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12424 | |
| 12425 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12426 | |
| 12427 | switch (encoder->type) { |
| 12428 | unsigned int port_mask; |
| 12429 | case INTEL_OUTPUT_UNKNOWN: |
| 12430 | if (WARN_ON(!HAS_DDI(dev))) |
| 12431 | break; |
| 12432 | case INTEL_OUTPUT_DISPLAYPORT: |
| 12433 | case INTEL_OUTPUT_HDMI: |
| 12434 | case INTEL_OUTPUT_EDP: |
| 12435 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 12436 | |
| 12437 | /* the same port mustn't appear more than once */ |
| 12438 | if (used_ports & port_mask) |
| 12439 | return false; |
| 12440 | |
| 12441 | used_ports |= port_mask; |
| 12442 | default: |
| 12443 | break; |
| 12444 | } |
| 12445 | } |
| 12446 | |
| 12447 | return true; |
| 12448 | } |
| 12449 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12450 | static void |
| 12451 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 12452 | { |
| 12453 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12454 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12455 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12456 | struct intel_shared_dpll *shared_dpll; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12457 | uint32_t ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12458 | bool force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12459 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 12460 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 12461 | * kzalloc'd. Code that depends on any field being zero should be |
| 12462 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 12463 | * only fields that are know to not cause problems are preserved. */ |
| 12464 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12465 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12466 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12467 | shared_dpll = crtc_state->shared_dpll; |
| 12468 | dpll_hw_state = crtc_state->dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12469 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12470 | force_thru = crtc_state->pch_pfit.force_thru; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12471 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12472 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12473 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12474 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12475 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12476 | crtc_state->shared_dpll = shared_dpll; |
| 12477 | crtc_state->dpll_hw_state = dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12478 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12479 | crtc_state->pch_pfit.force_thru = force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12480 | } |
| 12481 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12482 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12483 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12484 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12485 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12486 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12487 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12488 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12489 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12490 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12491 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12492 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12493 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12494 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12495 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 12496 | pipe_config->cpu_transcoder = |
| 12497 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12498 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12499 | /* |
| 12500 | * Sanitize sync polarity flags based on requested ones. If neither |
| 12501 | * positive or negative polarity is requested, treat this as meaning |
| 12502 | * negative polarity. |
| 12503 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12504 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12505 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12506 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12507 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12508 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12509 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12510 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12511 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12512 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 12513 | pipe_config); |
| 12514 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12515 | goto fail; |
| 12516 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12517 | /* |
| 12518 | * Determine the real pipe dimensions. Note that stereo modes can |
| 12519 | * increase the actual pipe size due to the frame doubling and |
| 12520 | * insertion of additional space for blanks between the frame. This |
| 12521 | * is stored in the crtc timings. We use the requested mode to do this |
| 12522 | * computation to clearly distinguish it from the adjusted mode, which |
| 12523 | * can be changed by the connectors in the below retry loop. |
| 12524 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12525 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 12526 | &pipe_config->pipe_src_w, |
| 12527 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12528 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12529 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12530 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12531 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12532 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12533 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12534 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12535 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 12536 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12537 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12538 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 12539 | * adjust it according to limitations or connector properties, and also |
| 12540 | * a chance to reject the mode entirely. |
| 12541 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12542 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12543 | if (connector_state->crtc != crtc) |
| 12544 | continue; |
| 12545 | |
| 12546 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12547 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 12548 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 12549 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12550 | goto fail; |
| 12551 | } |
| 12552 | } |
| 12553 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12554 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 12555 | * done afterwards in case the encoder adjusts the mode. */ |
| 12556 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12557 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 12558 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12559 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 12560 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12561 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12562 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 12563 | goto fail; |
| 12564 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12565 | |
| 12566 | if (ret == RETRY) { |
| 12567 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 12568 | ret = -EINVAL; |
| 12569 | goto fail; |
| 12570 | } |
| 12571 | |
| 12572 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 12573 | retry = false; |
| 12574 | goto encoder_retry; |
| 12575 | } |
| 12576 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 12577 | /* Dithering seems to not pass-through bits correctly when it should, so |
| 12578 | * only enable it on 6bpc panels. */ |
| 12579 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 12580 | 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] | 12581 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12582 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12583 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12584 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12585 | } |
| 12586 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12587 | static void |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12588 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12589 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12590 | struct drm_crtc *crtc; |
| 12591 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12592 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12593 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12594 | /* Double check state. */ |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12595 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 3cb480b | 2015-06-01 12:49:49 +0200 | [diff] [blame] | 12596 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 12597 | |
| 12598 | /* Update hwmode for vblank functions */ |
| 12599 | if (crtc->state->active) |
| 12600 | crtc->hwmode = crtc->state->adjusted_mode; |
| 12601 | else |
| 12602 | crtc->hwmode.crtc_clock = 0; |
Maarten Lankhorst | 61067a5 | 2015-09-23 16:29:36 +0200 | [diff] [blame] | 12603 | |
| 12604 | /* |
| 12605 | * Update legacy state to satisfy fbc code. This can |
| 12606 | * be removed when fbc uses the atomic state. |
| 12607 | */ |
| 12608 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { |
| 12609 | struct drm_plane_state *plane_state = crtc->primary->state; |
| 12610 | |
| 12611 | crtc->primary->fb = plane_state->fb; |
| 12612 | crtc->x = plane_state->src_x >> 16; |
| 12613 | crtc->y = plane_state->src_y >> 16; |
| 12614 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12615 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12616 | } |
| 12617 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12618 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12619 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12620 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12621 | |
| 12622 | if (clock1 == clock2) |
| 12623 | return true; |
| 12624 | |
| 12625 | if (!clock1 || !clock2) |
| 12626 | return false; |
| 12627 | |
| 12628 | diff = abs(clock1 - clock2); |
| 12629 | |
| 12630 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 12631 | return true; |
| 12632 | |
| 12633 | return false; |
| 12634 | } |
| 12635 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12636 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 12637 | list_for_each_entry((intel_crtc), \ |
| 12638 | &(dev)->mode_config.crtc_list, \ |
| 12639 | base.head) \ |
Jani Nikula | 95150bd | 2015-11-24 21:21:56 +0200 | [diff] [blame] | 12640 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12641 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12642 | static bool |
| 12643 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 12644 | unsigned int m2, unsigned int n2, |
| 12645 | bool exact) |
| 12646 | { |
| 12647 | if (m == m2 && n == n2) |
| 12648 | return true; |
| 12649 | |
| 12650 | if (exact || !m || !n || !m2 || !n2) |
| 12651 | return false; |
| 12652 | |
| 12653 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 12654 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12655 | if (n > n2) { |
| 12656 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12657 | m2 <<= 1; |
| 12658 | n2 <<= 1; |
| 12659 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12660 | } else if (n < n2) { |
| 12661 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12662 | m <<= 1; |
| 12663 | n <<= 1; |
| 12664 | } |
| 12665 | } |
| 12666 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12667 | if (n != n2) |
| 12668 | return false; |
| 12669 | |
| 12670 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12671 | } |
| 12672 | |
| 12673 | static bool |
| 12674 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 12675 | struct intel_link_m_n *m2_n2, |
| 12676 | bool adjust) |
| 12677 | { |
| 12678 | if (m_n->tu == m2_n2->tu && |
| 12679 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 12680 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 12681 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 12682 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 12683 | if (adjust) |
| 12684 | *m2_n2 = *m_n; |
| 12685 | |
| 12686 | return true; |
| 12687 | } |
| 12688 | |
| 12689 | return false; |
| 12690 | } |
| 12691 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12692 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12693 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12694 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12695 | struct intel_crtc_state *pipe_config, |
| 12696 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12697 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12698 | bool ret = true; |
| 12699 | |
| 12700 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ |
| 12701 | do { \ |
| 12702 | if (!adjust) \ |
| 12703 | DRM_ERROR(fmt, ##__VA_ARGS__); \ |
| 12704 | else \ |
| 12705 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ |
| 12706 | } while (0) |
| 12707 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12708 | #define PIPE_CONF_CHECK_X(name) \ |
| 12709 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12710 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12711 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 12712 | current_config->name, \ |
| 12713 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12714 | ret = false; \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12715 | } |
| 12716 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12717 | #define PIPE_CONF_CHECK_I(name) \ |
| 12718 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12719 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12720 | "(expected %i, found %i)\n", \ |
| 12721 | current_config->name, \ |
| 12722 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12723 | ret = false; \ |
| 12724 | } |
| 12725 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12726 | #define PIPE_CONF_CHECK_P(name) \ |
| 12727 | if (current_config->name != pipe_config->name) { \ |
| 12728 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12729 | "(expected %p, found %p)\n", \ |
| 12730 | current_config->name, \ |
| 12731 | pipe_config->name); \ |
| 12732 | ret = false; \ |
| 12733 | } |
| 12734 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12735 | #define PIPE_CONF_CHECK_M_N(name) \ |
| 12736 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12737 | &pipe_config->name,\ |
| 12738 | adjust)) { \ |
| 12739 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12740 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12741 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12742 | current_config->name.tu, \ |
| 12743 | current_config->name.gmch_m, \ |
| 12744 | current_config->name.gmch_n, \ |
| 12745 | current_config->name.link_m, \ |
| 12746 | current_config->name.link_n, \ |
| 12747 | pipe_config->name.tu, \ |
| 12748 | pipe_config->name.gmch_m, \ |
| 12749 | pipe_config->name.gmch_n, \ |
| 12750 | pipe_config->name.link_m, \ |
| 12751 | pipe_config->name.link_n); \ |
| 12752 | ret = false; \ |
| 12753 | } |
| 12754 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 12755 | /* This is required for BDW+ where there is only one set of registers for |
| 12756 | * switching between high and low RR. |
| 12757 | * This macro can be used whenever a comparison has to be made between one |
| 12758 | * hw state and multiple sw state variables. |
| 12759 | */ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12760 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
| 12761 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12762 | &pipe_config->name, adjust) && \ |
| 12763 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 12764 | &pipe_config->name, adjust)) { \ |
| 12765 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12766 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12767 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 12768 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12769 | current_config->name.tu, \ |
| 12770 | current_config->name.gmch_m, \ |
| 12771 | current_config->name.gmch_n, \ |
| 12772 | current_config->name.link_m, \ |
| 12773 | current_config->name.link_n, \ |
| 12774 | current_config->alt_name.tu, \ |
| 12775 | current_config->alt_name.gmch_m, \ |
| 12776 | current_config->alt_name.gmch_n, \ |
| 12777 | current_config->alt_name.link_m, \ |
| 12778 | current_config->alt_name.link_n, \ |
| 12779 | pipe_config->name.tu, \ |
| 12780 | pipe_config->name.gmch_m, \ |
| 12781 | pipe_config->name.gmch_n, \ |
| 12782 | pipe_config->name.link_m, \ |
| 12783 | pipe_config->name.link_n); \ |
| 12784 | ret = false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 12785 | } |
| 12786 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12787 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 12788 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12789 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12790 | "(expected %i, found %i)\n", \ |
| 12791 | current_config->name & (mask), \ |
| 12792 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12793 | ret = false; \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12794 | } |
| 12795 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12796 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 12797 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12798 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12799 | "(expected %i, found %i)\n", \ |
| 12800 | current_config->name, \ |
| 12801 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12802 | ret = false; \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12803 | } |
| 12804 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12805 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12806 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12807 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12808 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12809 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12810 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 12811 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12812 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12813 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12814 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12815 | PIPE_CONF_CHECK_I(lane_count); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12816 | |
| 12817 | if (INTEL_INFO(dev)->gen < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12818 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12819 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12820 | if (current_config->has_drrs) |
| 12821 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12822 | } else |
| 12823 | 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] | 12824 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 12825 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
| 12826 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12827 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12828 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12829 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12830 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12831 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12832 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12833 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12834 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12835 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12836 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12837 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12838 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12839 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12840 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12841 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 12842 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12843 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 12844 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12845 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 12846 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12847 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12848 | PIPE_CONF_CHECK_I(has_audio); |
| 12849 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12850 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12851 | DRM_MODE_FLAG_INTERLACE); |
| 12852 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12853 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12854 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12855 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12856 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12857 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12858 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12859 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12860 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12861 | DRM_MODE_FLAG_NVSYNC); |
| 12862 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12863 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12864 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12865 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 12866 | if (INTEL_INFO(dev)->gen < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 12867 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12868 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12869 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12870 | if (!adjust) { |
| 12871 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12872 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 12873 | |
| 12874 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 12875 | if (current_config->pch_pfit.enabled) { |
| 12876 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 12877 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 12878 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12879 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12880 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 12881 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12882 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 12883 | /* BDW+ don't expose a synchronous way to read the state */ |
| 12884 | if (IS_HASWELL(dev)) |
| 12885 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12886 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12887 | PIPE_CONF_CHECK_I(double_wide); |
| 12888 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 12889 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 12890 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12891 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12892 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12893 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12894 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12895 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12896 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12897 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12898 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12899 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12900 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12901 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 12902 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 12903 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 12904 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12905 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 12906 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12907 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12908 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12909 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12910 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12911 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12912 | #undef PIPE_CONF_CHECK_I |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12913 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12914 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12915 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12916 | #undef PIPE_CONF_QUIRK |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12917 | #undef INTEL_ERR_OR_DBG_KMS |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12918 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12919 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12920 | } |
| 12921 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12922 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 12923 | const struct intel_crtc_state *pipe_config) |
| 12924 | { |
| 12925 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 12926 | 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] | 12927 | &pipe_config->fdi_m_n); |
| 12928 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 12929 | |
| 12930 | /* |
| 12931 | * FDI already provided one idea for the dotclock. |
| 12932 | * Yell if the encoder disagrees. |
| 12933 | */ |
| 12934 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 12935 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 12936 | fdi_dotclock, dotclock); |
| 12937 | } |
| 12938 | } |
| 12939 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12940 | static void verify_wm_state(struct drm_crtc *crtc, |
| 12941 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12942 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12943 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12944 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12945 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12946 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 12947 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12948 | const enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12949 | int plane; |
| 12950 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12951 | if (INTEL_INFO(dev)->gen < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12952 | return; |
| 12953 | |
| 12954 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12955 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12956 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12957 | /* planes */ |
| 12958 | for_each_plane(dev_priv, pipe, plane) { |
| 12959 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 12960 | sw_entry = &sw_ddb->plane[pipe][plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12961 | |
| 12962 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12963 | continue; |
| 12964 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12965 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 12966 | "(expected (%u,%u), found (%u,%u))\n", |
| 12967 | pipe_name(pipe), plane + 1, |
| 12968 | sw_entry->start, sw_entry->end, |
| 12969 | hw_entry->start, hw_entry->end); |
| 12970 | } |
| 12971 | |
| 12972 | /* cursor */ |
| 12973 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 12974 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
| 12975 | |
| 12976 | if (!skl_ddb_entry_equal(hw_entry, sw_entry)) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12977 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 12978 | "(expected (%u,%u), found (%u,%u))\n", |
| 12979 | pipe_name(pipe), |
| 12980 | sw_entry->start, sw_entry->end, |
| 12981 | hw_entry->start, hw_entry->end); |
| 12982 | } |
| 12983 | } |
| 12984 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12985 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12986 | verify_connector_state(struct drm_device *dev, struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12987 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12988 | struct drm_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12989 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12990 | drm_for_each_connector(connector, dev) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12991 | struct drm_encoder *encoder = connector->encoder; |
| 12992 | struct drm_connector_state *state = connector->state; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12993 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12994 | if (state->crtc != crtc) |
| 12995 | continue; |
| 12996 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12997 | intel_connector_verify_state(to_intel_connector(connector)); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12998 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12999 | I915_STATE_WARN(state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 13000 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13001 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13002 | } |
| 13003 | |
| 13004 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13005 | verify_encoder_state(struct drm_device *dev) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13006 | { |
| 13007 | struct intel_encoder *encoder; |
| 13008 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13009 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13010 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13011 | bool enabled = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13012 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13013 | |
| 13014 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 13015 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13016 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13017 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13018 | for_each_intel_connector(dev, connector) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13019 | if (connector->base.state->best_encoder != &encoder->base) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13020 | continue; |
| 13021 | enabled = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 13022 | |
| 13023 | I915_STATE_WARN(connector->base.state->crtc != |
| 13024 | encoder->base.crtc, |
| 13025 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13026 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 13027 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 13028 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13029 | "encoder's enabled state mismatch " |
| 13030 | "(expected %i, found %i)\n", |
| 13031 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13032 | |
| 13033 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13034 | bool active; |
| 13035 | |
| 13036 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13037 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13038 | "encoder detached but still enabled on pipe %c.\n", |
| 13039 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13040 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13041 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13042 | } |
| 13043 | |
| 13044 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13045 | verify_crtc_state(struct drm_crtc *crtc, |
| 13046 | struct drm_crtc_state *old_crtc_state, |
| 13047 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13048 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13049 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13050 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13051 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13052 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13053 | struct intel_crtc_state *pipe_config, *sw_config; |
| 13054 | struct drm_atomic_state *old_state; |
| 13055 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13056 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13057 | old_state = old_crtc_state->state; |
| 13058 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
| 13059 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 13060 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 13061 | pipe_config->base.crtc = crtc; |
| 13062 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13063 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13064 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13065 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13066 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13067 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13068 | /* hw state is inconsistent with the pipe quirk */ |
| 13069 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 13070 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 13071 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13072 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13073 | I915_STATE_WARN(new_crtc_state->active != active, |
| 13074 | "crtc active state doesn't match with hw state " |
| 13075 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13076 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13077 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 13078 | "transitional active state does not match atomic hw state " |
| 13079 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13080 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13081 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 13082 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13083 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13084 | active = encoder->get_hw_state(encoder, &pipe); |
| 13085 | I915_STATE_WARN(active != new_crtc_state->active, |
| 13086 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 13087 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13088 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13089 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 13090 | "Encoder connected to wrong pipe %c\n", |
| 13091 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13092 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13093 | if (active) |
| 13094 | encoder->get_config(encoder, pipe_config); |
| 13095 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13096 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13097 | if (!new_crtc_state->active) |
| 13098 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13099 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13100 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13101 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13102 | sw_config = to_intel_crtc_state(crtc->state); |
| 13103 | if (!intel_pipe_config_compare(dev, sw_config, |
| 13104 | pipe_config, false)) { |
| 13105 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 13106 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 13107 | "[hw state]"); |
| 13108 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 13109 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13110 | } |
| 13111 | } |
| 13112 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13113 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13114 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 13115 | struct intel_shared_dpll *pll, |
| 13116 | struct drm_crtc *crtc, |
| 13117 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13118 | { |
| 13119 | struct intel_dpll_hw_state dpll_hw_state; |
| 13120 | unsigned crtc_mask; |
| 13121 | bool active; |
| 13122 | |
| 13123 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 13124 | |
| 13125 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 13126 | |
| 13127 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 13128 | |
| 13129 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
| 13130 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 13131 | "pll in active use but not on in sw tracking\n"); |
| 13132 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 13133 | "pll is on but not used by any active crtc\n"); |
| 13134 | I915_STATE_WARN(pll->on != active, |
| 13135 | "pll on state mismatch (expected %i, found %i)\n", |
| 13136 | pll->on, active); |
| 13137 | } |
| 13138 | |
| 13139 | if (!crtc) { |
| 13140 | I915_STATE_WARN(pll->active_mask & ~pll->config.crtc_mask, |
| 13141 | "more active pll users than references: %x vs %x\n", |
| 13142 | pll->active_mask, pll->config.crtc_mask); |
| 13143 | |
| 13144 | return; |
| 13145 | } |
| 13146 | |
| 13147 | crtc_mask = 1 << drm_crtc_index(crtc); |
| 13148 | |
| 13149 | if (new_state->active) |
| 13150 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 13151 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 13152 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 13153 | else |
| 13154 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 13155 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 13156 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 13157 | |
| 13158 | I915_STATE_WARN(!(pll->config.crtc_mask & crtc_mask), |
| 13159 | "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n", |
| 13160 | crtc_mask, pll->config.crtc_mask); |
| 13161 | |
| 13162 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, |
| 13163 | &dpll_hw_state, |
| 13164 | sizeof(dpll_hw_state)), |
| 13165 | "pll hw state mismatch\n"); |
| 13166 | } |
| 13167 | |
| 13168 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13169 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 13170 | struct drm_crtc_state *old_crtc_state, |
| 13171 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13172 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13173 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13174 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 13175 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 13176 | |
| 13177 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13178 | verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13179 | |
| 13180 | if (old_state->shared_dpll && |
| 13181 | old_state->shared_dpll != new_state->shared_dpll) { |
| 13182 | unsigned crtc_mask = 1 << drm_crtc_index(crtc); |
| 13183 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 13184 | |
| 13185 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 13186 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 13187 | pipe_name(drm_crtc_index(crtc))); |
| 13188 | I915_STATE_WARN(pll->config.crtc_mask & crtc_mask, |
| 13189 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 13190 | pipe_name(drm_crtc_index(crtc))); |
| 13191 | } |
| 13192 | } |
| 13193 | |
| 13194 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13195 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13196 | struct drm_crtc_state *old_state, |
| 13197 | struct drm_crtc_state *new_state) |
| 13198 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13199 | if (!needs_modeset(new_state) && |
| 13200 | !to_intel_crtc_state(new_state)->update_pipe) |
| 13201 | return; |
| 13202 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13203 | verify_wm_state(crtc, new_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13204 | verify_connector_state(crtc->dev, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13205 | verify_crtc_state(crtc, old_state, new_state); |
| 13206 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13207 | } |
| 13208 | |
| 13209 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13210 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13211 | { |
| 13212 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13213 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13214 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13215 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13216 | verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13217 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13218 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13219 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13220 | intel_modeset_verify_disabled(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13221 | { |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13222 | verify_encoder_state(dev); |
| 13223 | verify_connector_state(dev, NULL); |
| 13224 | verify_disabled_dpll_state(dev); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 13225 | } |
| 13226 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13227 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 13228 | { |
| 13229 | struct drm_device *dev = crtc->base.dev; |
| 13230 | |
| 13231 | /* |
| 13232 | * The scanline counter increments at the leading edge of hsync. |
| 13233 | * |
| 13234 | * On most platforms it starts counting from vtotal-1 on the |
| 13235 | * first active line. That means the scanline counter value is |
| 13236 | * always one less than what we would expect. Ie. just after |
| 13237 | * start of vblank, which also occurs at start of hsync (on the |
| 13238 | * last active line), the scanline counter will read vblank_start-1. |
| 13239 | * |
| 13240 | * On gen2 the scanline counter starts counting from 1 instead |
| 13241 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 13242 | * to keep the value positive), instead of adding one. |
| 13243 | * |
| 13244 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 13245 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 13246 | * there's an extra 1 line difference. So we need to add two instead of |
| 13247 | * one to the value. |
| 13248 | */ |
| 13249 | if (IS_GEN2(dev)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13250 | 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] | 13251 | int vtotal; |
| 13252 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13253 | vtotal = adjusted_mode->crtc_vtotal; |
| 13254 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13255 | vtotal /= 2; |
| 13256 | |
| 13257 | crtc->scanline_offset = vtotal - 1; |
| 13258 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 13259 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13260 | crtc->scanline_offset = 2; |
| 13261 | } else |
| 13262 | crtc->scanline_offset = 1; |
| 13263 | } |
| 13264 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13265 | 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] | 13266 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13267 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13268 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13269 | struct intel_shared_dpll_config *shared_dpll = NULL; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13270 | struct drm_crtc *crtc; |
| 13271 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13272 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13273 | |
| 13274 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13275 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13276 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13277 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13278 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13279 | struct intel_shared_dpll *old_dpll = |
| 13280 | to_intel_crtc_state(crtc->state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13281 | |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13282 | if (!needs_modeset(crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13283 | continue; |
| 13284 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13285 | to_intel_crtc_state(crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13286 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13287 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13288 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13289 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13290 | if (!shared_dpll) |
| 13291 | shared_dpll = intel_atomic_get_shared_dpll_state(state); |
| 13292 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13293 | 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] | 13294 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13295 | } |
| 13296 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13297 | /* |
| 13298 | * This implements the workaround described in the "notes" section of the mode |
| 13299 | * set sequence documentation. When going from no pipes or single pipe to |
| 13300 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 13301 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 13302 | */ |
| 13303 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 13304 | { |
| 13305 | struct drm_crtc_state *crtc_state; |
| 13306 | struct intel_crtc *intel_crtc; |
| 13307 | struct drm_crtc *crtc; |
| 13308 | struct intel_crtc_state *first_crtc_state = NULL; |
| 13309 | struct intel_crtc_state *other_crtc_state = NULL; |
| 13310 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 13311 | int i; |
| 13312 | |
| 13313 | /* look at all crtc's that are going to be enabled in during modeset */ |
| 13314 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13315 | intel_crtc = to_intel_crtc(crtc); |
| 13316 | |
| 13317 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 13318 | continue; |
| 13319 | |
| 13320 | if (first_crtc_state) { |
| 13321 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 13322 | break; |
| 13323 | } else { |
| 13324 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 13325 | first_pipe = intel_crtc->pipe; |
| 13326 | } |
| 13327 | } |
| 13328 | |
| 13329 | /* No workaround needed? */ |
| 13330 | if (!first_crtc_state) |
| 13331 | return 0; |
| 13332 | |
| 13333 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 13334 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 13335 | struct intel_crtc_state *pipe_config; |
| 13336 | |
| 13337 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 13338 | if (IS_ERR(pipe_config)) |
| 13339 | return PTR_ERR(pipe_config); |
| 13340 | |
| 13341 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 13342 | |
| 13343 | if (!pipe_config->base.active || |
| 13344 | needs_modeset(&pipe_config->base)) |
| 13345 | continue; |
| 13346 | |
| 13347 | /* 2 or more enabled crtcs means no need for w/a */ |
| 13348 | if (enabled_pipe != INVALID_PIPE) |
| 13349 | return 0; |
| 13350 | |
| 13351 | enabled_pipe = intel_crtc->pipe; |
| 13352 | } |
| 13353 | |
| 13354 | if (enabled_pipe != INVALID_PIPE) |
| 13355 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 13356 | else if (other_crtc_state) |
| 13357 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 13358 | |
| 13359 | return 0; |
| 13360 | } |
| 13361 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13362 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 13363 | { |
| 13364 | struct drm_crtc *crtc; |
| 13365 | struct drm_crtc_state *crtc_state; |
| 13366 | int ret = 0; |
| 13367 | |
| 13368 | /* add all active pipes to the state */ |
| 13369 | for_each_crtc(state->dev, crtc) { |
| 13370 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13371 | if (IS_ERR(crtc_state)) |
| 13372 | return PTR_ERR(crtc_state); |
| 13373 | |
| 13374 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 13375 | continue; |
| 13376 | |
| 13377 | crtc_state->mode_changed = true; |
| 13378 | |
| 13379 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13380 | if (ret) |
| 13381 | break; |
| 13382 | |
| 13383 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13384 | if (ret) |
| 13385 | break; |
| 13386 | } |
| 13387 | |
| 13388 | return ret; |
| 13389 | } |
| 13390 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13391 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13392 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13393 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13394 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 13395 | struct drm_crtc *crtc; |
| 13396 | struct drm_crtc_state *crtc_state; |
| 13397 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13398 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13399 | if (!check_digital_port_conflicts(state)) { |
| 13400 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 13401 | return -EINVAL; |
| 13402 | } |
| 13403 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13404 | intel_state->modeset = true; |
| 13405 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 13406 | |
| 13407 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13408 | if (crtc_state->active) |
| 13409 | intel_state->active_crtcs |= 1 << i; |
| 13410 | else |
| 13411 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 13412 | |
| 13413 | if (crtc_state->active != crtc->state->active) |
| 13414 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13415 | } |
| 13416 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13417 | /* |
| 13418 | * See if the config requires any additional preparation, e.g. |
| 13419 | * to adjust global state with pipes off. We need to do this |
| 13420 | * here so we can get the modeset_pipe updated config for the new |
| 13421 | * mode set on this crtc. For other crtcs we need to use the |
| 13422 | * adjusted_mode bits in the crtc directly. |
| 13423 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13424 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 13425 | if (!intel_state->cdclk_pll_vco) |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 13426 | intel_state->cdclk_pll_vco = dev_priv->cdclk_pll.vco; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 13427 | if (!intel_state->cdclk_pll_vco) |
| 13428 | intel_state->cdclk_pll_vco = dev_priv->skl_preferred_vco_freq; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13429 | |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 13430 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 13431 | if (ret < 0) |
| 13432 | return ret; |
| 13433 | |
| 13434 | if (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 13435 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco) |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13436 | ret = intel_modeset_all_pipes(state); |
| 13437 | |
| 13438 | if (ret < 0) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13439 | return ret; |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 13440 | |
| 13441 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", |
| 13442 | intel_state->cdclk, intel_state->dev_cdclk); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13443 | } else |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13444 | 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] | 13445 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13446 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13447 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13448 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13449 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13450 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13451 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13452 | } |
| 13453 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13454 | /* |
| 13455 | * Handle calculation of various watermark data at the end of the atomic check |
| 13456 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 13457 | * handlers to ensure that all derived state has been updated. |
| 13458 | */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 13459 | static int calc_watermark_data(struct drm_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13460 | { |
| 13461 | struct drm_device *dev = state->dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 13462 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 13463 | |
| 13464 | /* Is there platform-specific watermark information to calculate? */ |
| 13465 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 13466 | return dev_priv->display.compute_global_watermarks(state); |
| 13467 | |
| 13468 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13469 | } |
| 13470 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13471 | /** |
| 13472 | * intel_atomic_check - validate state object |
| 13473 | * @dev: drm device |
| 13474 | * @state: state to validate |
| 13475 | */ |
| 13476 | static int intel_atomic_check(struct drm_device *dev, |
| 13477 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13478 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13479 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13480 | 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] | 13481 | struct drm_crtc *crtc; |
| 13482 | struct drm_crtc_state *crtc_state; |
| 13483 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13484 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13485 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13486 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13487 | if (ret) |
| 13488 | return ret; |
| 13489 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13490 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13491 | struct intel_crtc_state *pipe_config = |
| 13492 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13493 | |
| 13494 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 13495 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) |
| 13496 | crtc_state->mode_changed = true; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13497 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13498 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13499 | continue; |
| 13500 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 13501 | if (!crtc_state->enable) { |
| 13502 | any_ms = true; |
| 13503 | continue; |
| 13504 | } |
| 13505 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13506 | /* FIXME: For only active_changed we shouldn't need to do any |
| 13507 | * state recomputation at all. */ |
| 13508 | |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13509 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13510 | if (ret) |
| 13511 | return ret; |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13512 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13513 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 13514 | if (ret) { |
| 13515 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 13516 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13517 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 13518 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13519 | |
Jani Nikula | 7383123 | 2015-11-19 10:26:30 +0200 | [diff] [blame] | 13520 | if (i915.fastboot && |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13521 | intel_pipe_config_compare(dev, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13522 | to_intel_crtc_state(crtc->state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13523 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13524 | crtc_state->mode_changed = false; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13525 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13526 | } |
| 13527 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 13528 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13529 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13530 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 13531 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13532 | if (ret) |
| 13533 | return ret; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13534 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13535 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 13536 | needs_modeset(crtc_state) ? |
| 13537 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13538 | } |
| 13539 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13540 | if (any_ms) { |
| 13541 | ret = intel_modeset_checks(state); |
| 13542 | |
| 13543 | if (ret) |
| 13544 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13545 | } else |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13546 | intel_state->cdclk = dev_priv->cdclk_freq; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13547 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13548 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13549 | if (ret) |
| 13550 | return ret; |
| 13551 | |
Paulo Zanoni | f51be2e | 2016-01-19 11:35:50 -0200 | [diff] [blame] | 13552 | intel_fbc_choose_crtc(dev_priv, state); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 13553 | return calc_watermark_data(state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13554 | } |
| 13555 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13556 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
| 13557 | struct drm_atomic_state *state, |
Maarten Lankhorst | 81072bf | 2016-04-26 16:11:45 +0200 | [diff] [blame] | 13558 | bool nonblock) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13559 | { |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13560 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13561 | struct drm_plane_state *plane_state; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13562 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13563 | struct drm_plane *plane; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13564 | struct drm_crtc *crtc; |
| 13565 | int i, ret; |
| 13566 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13567 | if (nonblock) { |
| 13568 | DRM_DEBUG_KMS("i915 does not yet support nonblocking commit\n"); |
| 13569 | return -EINVAL; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13570 | } |
| 13571 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13572 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13573 | if (state->legacy_cursor_update) |
| 13574 | continue; |
| 13575 | |
| 13576 | ret = intel_crtc_wait_for_pending_flips(crtc); |
| 13577 | if (ret) |
| 13578 | return ret; |
| 13579 | |
| 13580 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) |
| 13581 | flush_workqueue(dev_priv->wq); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 13582 | } |
| 13583 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13584 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 13585 | if (ret) |
| 13586 | return ret; |
| 13587 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13588 | ret = drm_atomic_helper_prepare_planes(dev, state); |
Chris Wilson | f7e5838 | 2016-04-13 17:35:07 +0100 | [diff] [blame] | 13589 | mutex_unlock(&dev->struct_mutex); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13590 | |
Dave Airlie | 21daaee | 2016-05-05 09:56:30 +1000 | [diff] [blame] | 13591 | if (!ret && !nonblock) { |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13592 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 13593 | struct intel_plane_state *intel_plane_state = |
| 13594 | to_intel_plane_state(plane_state); |
| 13595 | |
| 13596 | if (!intel_plane_state->wait_req) |
| 13597 | continue; |
| 13598 | |
| 13599 | ret = __i915_wait_request(intel_plane_state->wait_req, |
Chris Wilson | 299259a | 2016-04-13 17:35:06 +0100 | [diff] [blame] | 13600 | true, NULL, NULL); |
Chris Wilson | f7e5838 | 2016-04-13 17:35:07 +0100 | [diff] [blame] | 13601 | if (ret) { |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13602 | /* Any hang should be swallowed by the wait */ |
| 13603 | WARN_ON(ret == -EIO); |
Chris Wilson | f7e5838 | 2016-04-13 17:35:07 +0100 | [diff] [blame] | 13604 | mutex_lock(&dev->struct_mutex); |
| 13605 | drm_atomic_helper_cleanup_planes(dev, state); |
| 13606 | mutex_unlock(&dev->struct_mutex); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13607 | break; |
Chris Wilson | f7e5838 | 2016-04-13 17:35:07 +0100 | [diff] [blame] | 13608 | } |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13609 | } |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13610 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13611 | |
| 13612 | return ret; |
| 13613 | } |
| 13614 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 13615 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 13616 | { |
| 13617 | struct drm_device *dev = crtc->base.dev; |
| 13618 | |
| 13619 | if (!dev->max_vblank_count) |
| 13620 | return drm_accurate_vblank_count(&crtc->base); |
| 13621 | |
| 13622 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 13623 | } |
| 13624 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13625 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
| 13626 | struct drm_i915_private *dev_priv, |
| 13627 | unsigned crtc_mask) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13628 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13629 | unsigned last_vblank_count[I915_MAX_PIPES]; |
| 13630 | enum pipe pipe; |
| 13631 | int ret; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13632 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13633 | if (!crtc_mask) |
| 13634 | return; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13635 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13636 | for_each_pipe(dev_priv, pipe) { |
| 13637 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13638 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13639 | if (!((1 << pipe) & crtc_mask)) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13640 | continue; |
| 13641 | |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 13642 | ret = drm_crtc_vblank_get(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13643 | if (WARN_ON(ret != 0)) { |
| 13644 | crtc_mask &= ~(1 << pipe); |
| 13645 | continue; |
| 13646 | } |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 13647 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13648 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); |
| 13649 | } |
| 13650 | |
| 13651 | for_each_pipe(dev_priv, pipe) { |
| 13652 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 13653 | long lret; |
| 13654 | |
| 13655 | if (!((1 << pipe) & crtc_mask)) |
| 13656 | continue; |
| 13657 | |
| 13658 | lret = wait_event_timeout(dev->vblank[pipe].queue, |
| 13659 | last_vblank_count[pipe] != |
| 13660 | drm_crtc_vblank_count(crtc), |
| 13661 | msecs_to_jiffies(50)); |
| 13662 | |
| 13663 | WARN(!lret, "pipe %c vblank wait timed out\n", pipe_name(pipe)); |
| 13664 | |
| 13665 | drm_crtc_vblank_put(crtc); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 13666 | } |
| 13667 | } |
| 13668 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13669 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13670 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13671 | /* fb updated, need to unpin old fb */ |
| 13672 | if (crtc_state->fb_changed) |
| 13673 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13674 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13675 | /* wm changes, need vblank before final wm's */ |
| 13676 | if (crtc_state->update_wm_post) |
| 13677 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13678 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13679 | /* |
| 13680 | * cxsr is re-enabled after vblank. |
| 13681 | * This is already handled by crtc_state->update_wm_post, |
| 13682 | * but added for clarity. |
| 13683 | */ |
| 13684 | if (crtc_state->disable_cxsr) |
| 13685 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13686 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13687 | return false; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13688 | } |
| 13689 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13690 | /** |
| 13691 | * intel_atomic_commit - commit validated state object |
| 13692 | * @dev: DRM device |
| 13693 | * @state: the top-level driver state object |
Maarten Lankhorst | 81072bf | 2016-04-26 16:11:45 +0200 | [diff] [blame] | 13694 | * @nonblock: nonblocking commit |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13695 | * |
| 13696 | * This function commits a top-level state object that has been validated |
| 13697 | * with drm_atomic_helper_check(). |
| 13698 | * |
| 13699 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment |
| 13700 | * we can only handle plane-related operations and do not yet support |
Maarten Lankhorst | 81072bf | 2016-04-26 16:11:45 +0200 | [diff] [blame] | 13701 | * nonblocking commit. |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13702 | * |
| 13703 | * RETURNS |
| 13704 | * Zero for success or -errno. |
| 13705 | */ |
| 13706 | static int intel_atomic_commit(struct drm_device *dev, |
| 13707 | struct drm_atomic_state *state, |
Maarten Lankhorst | 81072bf | 2016-04-26 16:11:45 +0200 | [diff] [blame] | 13708 | bool nonblock) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13709 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13710 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13711 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13712 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13713 | struct drm_crtc *crtc; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13714 | struct intel_crtc_state *intel_cstate; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13715 | int ret = 0, i; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13716 | bool hw_check = intel_state->modeset; |
| 13717 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
| 13718 | unsigned crtc_vblank_mask = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13719 | |
Maarten Lankhorst | 81072bf | 2016-04-26 16:11:45 +0200 | [diff] [blame] | 13720 | ret = intel_atomic_prepare_commit(dev, state, nonblock); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13721 | if (ret) { |
| 13722 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13723 | return ret; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13724 | } |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13725 | |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13726 | drm_atomic_helper_swap_state(dev, state); |
Matt Roper | 279e99d | 2016-05-12 07:06:02 -0700 | [diff] [blame] | 13727 | dev_priv->wm.distrust_bios_wm = false; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 13728 | dev_priv->wm.skl_results = intel_state->wm_results; |
Maarten Lankhorst | a1475e7 | 2016-03-14 09:27:53 +0100 | [diff] [blame] | 13729 | intel_shared_dpll_commit(state); |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13730 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13731 | if (intel_state->modeset) { |
| 13732 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, |
| 13733 | sizeof(intel_state->min_pixclk)); |
| 13734 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13735 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13736 | |
| 13737 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13738 | } |
| 13739 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13740 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13741 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13742 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13743 | if (needs_modeset(crtc->state) || |
| 13744 | to_intel_crtc_state(crtc->state)->update_pipe) { |
| 13745 | hw_check = true; |
| 13746 | |
| 13747 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 13748 | modeset_get_crtc_power_domains(crtc, |
| 13749 | to_intel_crtc_state(crtc->state)); |
| 13750 | } |
| 13751 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13752 | if (!needs_modeset(crtc->state)) |
| 13753 | continue; |
| 13754 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13755 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13756 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13757 | if (old_crtc_state->active) { |
| 13758 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13759 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13760 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13761 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13762 | intel_disable_shared_dpll(intel_crtc); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13763 | |
| 13764 | /* |
| 13765 | * Underruns don't always raise |
| 13766 | * interrupts, so check manually. |
| 13767 | */ |
| 13768 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13769 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13770 | |
| 13771 | if (!crtc->state->active) |
| 13772 | intel_update_watermarks(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13773 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13774 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13775 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13776 | /* Only after disabling all output pipelines that will be changed can we |
| 13777 | * update the the output configuration. */ |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13778 | intel_modeset_update_crtc_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13779 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13780 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13781 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13782 | |
| 13783 | if (dev_priv->display.modeset_commit_cdclk && |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 13784 | (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 13785 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco)) |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13786 | dev_priv->display.modeset_commit_cdclk(state); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 13787 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13788 | intel_modeset_verify_disabled(dev); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13789 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13790 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13791 | /* 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] | 13792 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13793 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13794 | bool modeset = needs_modeset(crtc->state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13795 | struct intel_crtc_state *pipe_config = |
| 13796 | to_intel_crtc_state(crtc->state); |
| 13797 | bool update_pipe = !modeset && pipe_config->update_pipe; |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 13798 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13799 | if (modeset && crtc->state->active) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13800 | update_scanline_offset(to_intel_crtc(crtc)); |
| 13801 | dev_priv->display.crtc_enable(crtc); |
| 13802 | } |
| 13803 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13804 | if (!modeset) |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13805 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13806 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13807 | if (crtc->state->active && |
| 13808 | drm_atomic_get_existing_plane_state(state, crtc->primary)) |
| 13809 | intel_fbc_enable(intel_crtc); |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13810 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13811 | if (crtc->state->active && |
| 13812 | (crtc->state->planes_changed || update_pipe)) |
| 13813 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 13814 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13815 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) |
| 13816 | crtc_vblank_mask |= 1 << i; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13817 | } |
| 13818 | |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 13819 | /* FIXME: add subpixel order */ |
| 13820 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13821 | if (!state->legacy_cursor_update) |
| 13822 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); |
| 13823 | |
| 13824 | /* |
| 13825 | * Now that the vblank has passed, we can go ahead and program the |
| 13826 | * optimal watermarks on platforms that need two-step watermark |
| 13827 | * programming. |
| 13828 | * |
| 13829 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13830 | */ |
| 13831 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 13832 | intel_cstate = to_intel_crtc_state(crtc->state); |
| 13833 | |
| 13834 | if (dev_priv->display.optimize_watermarks) |
| 13835 | dev_priv->display.optimize_watermarks(intel_cstate); |
| 13836 | } |
| 13837 | |
| 13838 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 13839 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13840 | |
| 13841 | if (put_domains[i]) |
| 13842 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13843 | |
| 13844 | intel_modeset_verify_crtc(crtc, old_crtc_state, crtc->state); |
| 13845 | } |
| 13846 | |
| 13847 | if (intel_state->modeset) |
| 13848 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
| 13849 | |
| 13850 | mutex_lock(&dev->struct_mutex); |
| 13851 | drm_atomic_helper_cleanup_planes(dev, state); |
| 13852 | mutex_unlock(&dev->struct_mutex); |
| 13853 | |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 13854 | drm_atomic_state_free(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 13855 | |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13856 | /* As one of the primary mmio accessors, KMS has a high likelihood |
| 13857 | * of triggering bugs in unclaimed access. After we finish |
| 13858 | * modesetting, see if an error has been flagged, and if so |
| 13859 | * enable debugging for the next modeset - and hope we catch |
| 13860 | * the culprit. |
| 13861 | * |
| 13862 | * XXX note that we assume display power is on at this point. |
| 13863 | * This might hold true now but we need to add pm helper to check |
| 13864 | * unclaimed only when the hardware is on, as atomic commits |
| 13865 | * can happen also when the device is completely off. |
| 13866 | */ |
| 13867 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
| 13868 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13869 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13870 | } |
| 13871 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13872 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 13873 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13874 | struct drm_device *dev = crtc->dev; |
| 13875 | struct drm_atomic_state *state; |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13876 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13877 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13878 | |
| 13879 | state = drm_atomic_state_alloc(dev); |
| 13880 | if (!state) { |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13881 | 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] | 13882 | crtc->base.id); |
| 13883 | return; |
| 13884 | } |
| 13885 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13886 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13887 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13888 | retry: |
| 13889 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13890 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 13891 | if (!ret) { |
| 13892 | if (!crtc_state->active) |
| 13893 | goto out; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13894 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13895 | crtc_state->mode_changed = true; |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13896 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13897 | } |
| 13898 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13899 | if (ret == -EDEADLK) { |
| 13900 | drm_atomic_state_clear(state); |
| 13901 | drm_modeset_backoff(state->acquire_ctx); |
| 13902 | goto retry; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 13903 | } |
| 13904 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13905 | if (ret) |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13906 | out: |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13907 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13908 | } |
| 13909 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 13910 | #undef for_each_intel_crtc_masked |
| 13911 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13912 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13913 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13914 | .set_config = drm_atomic_helper_set_config, |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13915 | .set_property = drm_atomic_helper_crtc_set_property, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13916 | .destroy = intel_crtc_destroy, |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13917 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13918 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13919 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13920 | }; |
| 13921 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13922 | /** |
| 13923 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13924 | * @plane: drm plane to prepare for |
| 13925 | * @fb: framebuffer to prepare for presentation |
| 13926 | * |
| 13927 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13928 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13929 | * bits. Some older platforms need special physical address handling for |
| 13930 | * cursor planes. |
| 13931 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13932 | * Must be called with struct_mutex held. |
| 13933 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13934 | * Returns 0 on success, negative error code on failure. |
| 13935 | */ |
| 13936 | int |
| 13937 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13938 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13939 | { |
| 13940 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13941 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13942 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13943 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13944 | 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] | 13945 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13946 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13947 | if (!obj && !old_obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13948 | return 0; |
| 13949 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13950 | if (old_obj) { |
| 13951 | struct drm_crtc_state *crtc_state = |
| 13952 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); |
| 13953 | |
| 13954 | /* Big Hammer, we also need to ensure that any pending |
| 13955 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13956 | * current scanout is retired before unpinning the old |
| 13957 | * framebuffer. Note that we rely on userspace rendering |
| 13958 | * into the buffer attached to the pipe they are waiting |
| 13959 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13960 | * point to the MI_WAIT_FOR_EVENT. |
| 13961 | * |
| 13962 | * This should only fail upon a hung GPU, in which case we |
| 13963 | * can safely continue. |
| 13964 | */ |
| 13965 | if (needs_modeset(crtc_state)) |
| 13966 | ret = i915_gem_object_wait_rendering(old_obj, true); |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13967 | if (ret) { |
| 13968 | /* GPU hangs should have been swallowed by the wait */ |
| 13969 | WARN_ON(ret == -EIO); |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13970 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13971 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13972 | } |
| 13973 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13974 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 13975 | if (obj && obj->base.dma_buf) { |
| 13976 | long lret; |
| 13977 | |
| 13978 | lret = reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 13979 | false, true, |
| 13980 | MAX_SCHEDULE_TIMEOUT); |
| 13981 | if (lret == -ERESTARTSYS) |
| 13982 | return lret; |
| 13983 | |
| 13984 | WARN(lret < 0, "waiting returns %li\n", lret); |
| 13985 | } |
| 13986 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13987 | if (!obj) { |
| 13988 | ret = 0; |
| 13989 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13990 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 13991 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 13992 | ret = i915_gem_object_attach_phys(obj, align); |
| 13993 | if (ret) |
| 13994 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 13995 | } else { |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 13996 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13997 | } |
| 13998 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13999 | if (ret == 0) { |
| 14000 | if (obj) { |
| 14001 | struct intel_plane_state *plane_state = |
| 14002 | to_intel_plane_state(new_state); |
| 14003 | |
| 14004 | i915_gem_request_assign(&plane_state->wait_req, |
| 14005 | obj->last_write_req); |
| 14006 | } |
| 14007 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 14008 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14009 | } |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14010 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14011 | return ret; |
| 14012 | } |
| 14013 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14014 | /** |
| 14015 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 14016 | * @plane: drm plane to clean up for |
| 14017 | * @fb: old framebuffer that was on plane |
| 14018 | * |
| 14019 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14020 | * |
| 14021 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14022 | */ |
| 14023 | void |
| 14024 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 14025 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14026 | { |
| 14027 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14028 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14029 | struct intel_plane_state *old_intel_state; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14030 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
| 14031 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14032 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14033 | old_intel_state = to_intel_plane_state(old_state); |
| 14034 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14035 | if (!obj && !old_obj) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14036 | return; |
| 14037 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14038 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 14039 | !INTEL_INFO(dev)->cursor_needs_physical)) |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 14040 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14041 | |
| 14042 | /* prepare_fb aborted? */ |
| 14043 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || |
| 14044 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) |
| 14045 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14046 | |
| 14047 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14048 | } |
| 14049 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14050 | int |
| 14051 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 14052 | { |
| 14053 | int max_scale; |
| 14054 | struct drm_device *dev; |
| 14055 | struct drm_i915_private *dev_priv; |
| 14056 | int crtc_clock, cdclk; |
| 14057 | |
Maarten Lankhorst | bf8a0af | 2015-11-24 11:29:02 +0100 | [diff] [blame] | 14058 | if (!intel_crtc || !crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14059 | return DRM_PLANE_HELPER_NO_SCALING; |
| 14060 | |
| 14061 | dev = intel_crtc->base.dev; |
| 14062 | dev_priv = dev->dev_private; |
| 14063 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14064 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14065 | |
Tvrtko Ursulin | 54bf1ce | 2015-10-20 17:17:07 +0100 | [diff] [blame] | 14066 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14067 | return DRM_PLANE_HELPER_NO_SCALING; |
| 14068 | |
| 14069 | /* |
| 14070 | * skl max scale is lower of: |
| 14071 | * close to 3 but not 3, -1 is for that purpose |
| 14072 | * or |
| 14073 | * cdclk/crtc_clock |
| 14074 | */ |
| 14075 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 14076 | |
| 14077 | return max_scale; |
| 14078 | } |
| 14079 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14080 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14081 | intel_check_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14082 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14083 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14084 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14085 | struct drm_crtc *crtc = state->base.crtc; |
| 14086 | struct drm_framebuffer *fb = state->base.fb; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14087 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14088 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 14089 | bool can_position = false; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14090 | |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 14091 | if (INTEL_INFO(plane->dev)->gen >= 9) { |
| 14092 | /* use scaler when colorkey is not required */ |
| 14093 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { |
| 14094 | min_scale = 1; |
| 14095 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); |
| 14096 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 14097 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14098 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 14099 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14100 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 14101 | &state->dst, &state->clip, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14102 | min_scale, max_scale, |
| 14103 | can_position, true, |
| 14104 | &state->visible); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14105 | } |
| 14106 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14107 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 14108 | struct drm_crtc_state *old_crtc_state) |
| 14109 | { |
| 14110 | struct drm_device *dev = crtc->dev; |
| 14111 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14112 | struct intel_crtc_state *old_intel_state = |
| 14113 | to_intel_crtc_state(old_crtc_state); |
| 14114 | bool modeset = needs_modeset(crtc->state); |
| 14115 | |
| 14116 | /* Perform vblank evasion around commit operation */ |
| 14117 | intel_pipe_update_start(intel_crtc); |
| 14118 | |
| 14119 | if (modeset) |
| 14120 | return; |
| 14121 | |
| 14122 | if (crtc->state->color_mgmt_changed || to_intel_crtc_state(crtc->state)->update_pipe) { |
| 14123 | intel_color_set_csc(crtc->state); |
| 14124 | intel_color_load_luts(crtc->state); |
| 14125 | } |
| 14126 | |
| 14127 | if (to_intel_crtc_state(crtc->state)->update_pipe) |
| 14128 | intel_update_pipe_config(intel_crtc, old_intel_state); |
| 14129 | else if (INTEL_INFO(dev)->gen >= 9) |
| 14130 | skl_detach_scalers(intel_crtc); |
| 14131 | } |
| 14132 | |
| 14133 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 14134 | struct drm_crtc_state *old_crtc_state) |
| 14135 | { |
| 14136 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14137 | |
| 14138 | intel_pipe_update_end(intel_crtc, NULL); |
| 14139 | } |
| 14140 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14141 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14142 | * intel_plane_destroy - destroy a plane |
| 14143 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14144 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14145 | * Common destruction function for all types of planes (primary, cursor, |
| 14146 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14147 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14148 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14149 | { |
| 14150 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 14151 | drm_plane_cleanup(plane); |
| 14152 | kfree(intel_plane); |
| 14153 | } |
| 14154 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 14155 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 14156 | .update_plane = drm_atomic_helper_update_plane, |
| 14157 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14158 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 14159 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 14160 | .atomic_get_property = intel_plane_atomic_get_property, |
| 14161 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14162 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 14163 | .atomic_destroy_state = intel_plane_destroy_state, |
| 14164 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14165 | }; |
| 14166 | |
| 14167 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 14168 | int pipe) |
| 14169 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14170 | struct intel_plane *primary = NULL; |
| 14171 | struct intel_plane_state *state = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14172 | const uint32_t *intel_primary_formats; |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 14173 | unsigned int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14174 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14175 | |
| 14176 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14177 | if (!primary) |
| 14178 | goto fail; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14179 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14180 | state = intel_create_plane_state(&primary->base); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14181 | if (!state) |
| 14182 | goto fail; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14183 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14184 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14185 | primary->can_scale = false; |
| 14186 | primary->max_downscale = 1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14187 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14188 | primary->can_scale = true; |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 14189 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14190 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14191 | primary->pipe = pipe; |
| 14192 | primary->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 14193 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 14194 | primary->check_plane = intel_check_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14195 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 14196 | primary->plane = !pipe; |
| 14197 | |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14198 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14199 | intel_primary_formats = skl_primary_formats; |
| 14200 | num_formats = ARRAY_SIZE(skl_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14201 | |
| 14202 | primary->update_plane = skylake_update_primary_plane; |
| 14203 | primary->disable_plane = skylake_disable_primary_plane; |
| 14204 | } else if (HAS_PCH_SPLIT(dev)) { |
| 14205 | intel_primary_formats = i965_primary_formats; |
| 14206 | num_formats = ARRAY_SIZE(i965_primary_formats); |
| 14207 | |
| 14208 | primary->update_plane = ironlake_update_primary_plane; |
| 14209 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14210 | } else if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 14211 | intel_primary_formats = i965_primary_formats; |
| 14212 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14213 | |
| 14214 | primary->update_plane = i9xx_update_primary_plane; |
| 14215 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14216 | } else { |
| 14217 | intel_primary_formats = i8xx_primary_formats; |
| 14218 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14219 | |
| 14220 | primary->update_plane = i9xx_update_primary_plane; |
| 14221 | primary->disable_plane = i9xx_disable_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14222 | } |
| 14223 | |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14224 | ret = drm_universal_plane_init(dev, &primary->base, 0, |
| 14225 | &intel_plane_funcs, |
| 14226 | intel_primary_formats, num_formats, |
| 14227 | DRM_PLANE_TYPE_PRIMARY, NULL); |
| 14228 | if (ret) |
| 14229 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14230 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 14231 | if (INTEL_INFO(dev)->gen >= 4) |
| 14232 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14233 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14234 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 14235 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14236 | return &primary->base; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14237 | |
| 14238 | fail: |
| 14239 | kfree(state); |
| 14240 | kfree(primary); |
| 14241 | |
| 14242 | return NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14243 | } |
| 14244 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 14245 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 14246 | { |
| 14247 | if (!dev->mode_config.rotation_property) { |
| 14248 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 14249 | BIT(DRM_ROTATE_180); |
| 14250 | |
| 14251 | if (INTEL_INFO(dev)->gen >= 9) |
| 14252 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 14253 | |
| 14254 | dev->mode_config.rotation_property = |
| 14255 | drm_mode_create_rotation_property(dev, flags); |
| 14256 | } |
| 14257 | if (dev->mode_config.rotation_property) |
| 14258 | drm_object_attach_property(&plane->base.base, |
| 14259 | dev->mode_config.rotation_property, |
| 14260 | plane->base.state->rotation); |
| 14261 | } |
| 14262 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14263 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14264 | intel_check_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14265 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14266 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14267 | { |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14268 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14269 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14270 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 14271 | enum pipe pipe = to_intel_plane(plane)->pipe; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14272 | unsigned stride; |
| 14273 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14274 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14275 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 14276 | &state->dst, &state->clip, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14277 | DRM_PLANE_HELPER_NO_SCALING, |
| 14278 | DRM_PLANE_HELPER_NO_SCALING, |
| 14279 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14280 | if (ret) |
| 14281 | return ret; |
| 14282 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14283 | /* if we want to turn off the cursor ignore width and height */ |
| 14284 | if (!obj) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14285 | return 0; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14286 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14287 | /* Check for which cursor types we support */ |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14288 | 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] | 14289 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 14290 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14291 | return -EINVAL; |
| 14292 | } |
| 14293 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14294 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 14295 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14296 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 14297 | return -ENOMEM; |
| 14298 | } |
| 14299 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 14300 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14301 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14302 | return -EINVAL; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14303 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14304 | |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 14305 | /* |
| 14306 | * There's something wrong with the cursor on CHV pipe C. |
| 14307 | * If it straddles the left edge of the screen then |
| 14308 | * moving it away from the edge or disabling it often |
| 14309 | * results in a pipe underrun, and often that can lead to |
| 14310 | * dead pipe (constant underrun reported, and it scans |
| 14311 | * out just a solid color). To recover from that, the |
| 14312 | * display power well must be turned off and on again. |
| 14313 | * Refuse the put the cursor into that compromised position. |
| 14314 | */ |
| 14315 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && |
| 14316 | state->visible && state->base.crtc_x < 0) { |
| 14317 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 14318 | return -EINVAL; |
| 14319 | } |
| 14320 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14321 | return 0; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14322 | } |
| 14323 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14324 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14325 | intel_disable_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 14326 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14327 | { |
Maarten Lankhorst | f285802 | 2016-01-07 11:54:09 +0100 | [diff] [blame] | 14328 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14329 | |
| 14330 | intel_crtc->cursor_addr = 0; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14331 | intel_crtc_update_cursor(crtc, NULL); |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14332 | } |
| 14333 | |
| 14334 | static void |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14335 | intel_update_cursor_plane(struct drm_plane *plane, |
| 14336 | const struct intel_crtc_state *crtc_state, |
| 14337 | const struct intel_plane_state *state) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14338 | { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14339 | struct drm_crtc *crtc = crtc_state->base.crtc; |
| 14340 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14341 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14342 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14343 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14344 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14345 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14346 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14347 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14348 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14349 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14350 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14351 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14352 | intel_crtc->cursor_addr = addr; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14353 | intel_crtc_update_cursor(crtc, state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14354 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14355 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14356 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 14357 | int pipe) |
| 14358 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14359 | struct intel_plane *cursor = NULL; |
| 14360 | struct intel_plane_state *state = NULL; |
| 14361 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14362 | |
| 14363 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14364 | if (!cursor) |
| 14365 | goto fail; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14366 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14367 | state = intel_create_plane_state(&cursor->base); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14368 | if (!state) |
| 14369 | goto fail; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14370 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14371 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14372 | cursor->can_scale = false; |
| 14373 | cursor->max_downscale = 1; |
| 14374 | cursor->pipe = pipe; |
| 14375 | cursor->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 14376 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 14377 | cursor->check_plane = intel_check_cursor_plane; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14378 | cursor->update_plane = intel_update_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14379 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14380 | |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14381 | ret = drm_universal_plane_init(dev, &cursor->base, 0, |
| 14382 | &intel_plane_funcs, |
| 14383 | intel_cursor_formats, |
| 14384 | ARRAY_SIZE(intel_cursor_formats), |
| 14385 | DRM_PLANE_TYPE_CURSOR, NULL); |
| 14386 | if (ret) |
| 14387 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14388 | |
| 14389 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14390 | if (!dev->mode_config.rotation_property) |
| 14391 | dev->mode_config.rotation_property = |
| 14392 | drm_mode_create_rotation_property(dev, |
| 14393 | BIT(DRM_ROTATE_0) | |
| 14394 | BIT(DRM_ROTATE_180)); |
| 14395 | if (dev->mode_config.rotation_property) |
| 14396 | drm_object_attach_property(&cursor->base.base, |
| 14397 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14398 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14399 | } |
| 14400 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 14401 | if (INTEL_INFO(dev)->gen >=9) |
| 14402 | state->scaler_id = -1; |
| 14403 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14404 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14405 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14406 | return &cursor->base; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14407 | |
| 14408 | fail: |
| 14409 | kfree(state); |
| 14410 | kfree(cursor); |
| 14411 | |
| 14412 | return NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14413 | } |
| 14414 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14415 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 14416 | struct intel_crtc_state *crtc_state) |
| 14417 | { |
| 14418 | int i; |
| 14419 | struct intel_scaler *intel_scaler; |
| 14420 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 14421 | |
| 14422 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 14423 | intel_scaler = &scaler_state->scalers[i]; |
| 14424 | intel_scaler->in_use = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14425 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 14426 | } |
| 14427 | |
| 14428 | scaler_state->scaler_id = -1; |
| 14429 | } |
| 14430 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 14431 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14432 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14433 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14434 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14435 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14436 | struct drm_plane *primary = NULL; |
| 14437 | struct drm_plane *cursor = NULL; |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14438 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14439 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14440 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14441 | if (intel_crtc == NULL) |
| 14442 | return; |
| 14443 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14444 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 14445 | if (!crtc_state) |
| 14446 | goto fail; |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14447 | intel_crtc->config = crtc_state; |
| 14448 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14449 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14450 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14451 | /* initialize shared scalers */ |
| 14452 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14453 | if (pipe == PIPE_C) |
| 14454 | intel_crtc->num_scalers = 1; |
| 14455 | else |
| 14456 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 14457 | |
| 14458 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 14459 | } |
| 14460 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14461 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14462 | if (!primary) |
| 14463 | goto fail; |
| 14464 | |
| 14465 | cursor = intel_cursor_plane_create(dev, pipe); |
| 14466 | if (!cursor) |
| 14467 | goto fail; |
| 14468 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14469 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 14470 | cursor, &intel_crtc_funcs, NULL); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14471 | if (ret) |
| 14472 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14473 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 14474 | /* |
| 14475 | * 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] | 14476 | * 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] | 14477 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14478 | intel_crtc->pipe = pipe; |
| 14479 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 14480 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14481 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 14482 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14483 | } |
| 14484 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 14485 | intel_crtc->cursor_base = ~0; |
| 14486 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14487 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 14488 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 14489 | intel_crtc->wm.cxsr_allowed = true; |
| 14490 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14491 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14492 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 14493 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 14494 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 14495 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14496 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14497 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14498 | intel_color_init(&intel_crtc->base); |
| 14499 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14500 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14501 | return; |
| 14502 | |
| 14503 | fail: |
| 14504 | if (primary) |
| 14505 | drm_plane_cleanup(primary); |
| 14506 | if (cursor) |
| 14507 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14508 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14509 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14510 | } |
| 14511 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14512 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 14513 | { |
| 14514 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14515 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14516 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 14517 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14518 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 14519 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14520 | return INVALID_PIPE; |
| 14521 | |
| 14522 | return to_intel_crtc(encoder->crtc)->pipe; |
| 14523 | } |
| 14524 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14525 | 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] | 14526 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14527 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14528 | 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] | 14529 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14530 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14531 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14532 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14533 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14534 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14535 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14536 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14537 | } |
| 14538 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14539 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14540 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14541 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14542 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14543 | } |
| 14544 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14545 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14546 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14547 | struct drm_device *dev = encoder->base.dev; |
| 14548 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14549 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14550 | int entry = 0; |
| 14551 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14552 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14553 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14554 | index_mask |= (1 << entry); |
| 14555 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14556 | entry++; |
| 14557 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14558 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14559 | return index_mask; |
| 14560 | } |
| 14561 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14562 | static bool has_edp_a(struct drm_device *dev) |
| 14563 | { |
| 14564 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14565 | |
| 14566 | if (!IS_MOBILE(dev)) |
| 14567 | return false; |
| 14568 | |
| 14569 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14570 | return false; |
| 14571 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 14572 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14573 | return false; |
| 14574 | |
| 14575 | return true; |
| 14576 | } |
| 14577 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14578 | static bool intel_crt_present(struct drm_device *dev) |
| 14579 | { |
| 14580 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14581 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14582 | if (INTEL_INFO(dev)->gen >= 9) |
| 14583 | return false; |
| 14584 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 14585 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14586 | return false; |
| 14587 | |
| 14588 | if (IS_CHERRYVIEW(dev)) |
| 14589 | return false; |
| 14590 | |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14591 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
| 14592 | return false; |
| 14593 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14594 | /* DDI E can't be used if DDI A requires 4 lanes */ |
| 14595 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
| 14596 | return false; |
| 14597 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14598 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14599 | return false; |
| 14600 | |
| 14601 | return true; |
| 14602 | } |
| 14603 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14604 | static void intel_setup_outputs(struct drm_device *dev) |
| 14605 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14606 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14607 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14608 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14609 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 14610 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14611 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14612 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 14613 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14614 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14615 | if (IS_BROXTON(dev)) { |
| 14616 | /* |
| 14617 | * FIXME: Broxton doesn't support port detection via the |
| 14618 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14619 | * detect the ports. |
| 14620 | */ |
| 14621 | intel_ddi_init(dev, PORT_A); |
| 14622 | intel_ddi_init(dev, PORT_B); |
| 14623 | intel_ddi_init(dev, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14624 | |
| 14625 | intel_dsi_init(dev); |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14626 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14627 | int found; |
| 14628 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14629 | /* |
| 14630 | * Haswell uses DDI functions to detect digital outputs. |
| 14631 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14632 | * it's there. |
| 14633 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14634 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14635 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14636 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14637 | intel_ddi_init(dev, PORT_A); |
| 14638 | |
| 14639 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 14640 | * register */ |
| 14641 | found = I915_READ(SFUSE_STRAP); |
| 14642 | |
| 14643 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 14644 | intel_ddi_init(dev, PORT_B); |
| 14645 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 14646 | intel_ddi_init(dev, PORT_C); |
| 14647 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 14648 | intel_ddi_init(dev, PORT_D); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14649 | /* |
| 14650 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14651 | */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14652 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14653 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14654 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14655 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
| 14656 | intel_ddi_init(dev, PORT_E); |
| 14657 | |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14658 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14659 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 14660 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14661 | |
| 14662 | if (has_edp_a(dev)) |
| 14663 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14664 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14665 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14666 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14667 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14668 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14669 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14670 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14671 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14672 | } |
| 14673 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14674 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14675 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14676 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14677 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14678 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14679 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14680 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14681 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14682 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14683 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14684 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14685 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14686 | /* |
| 14687 | * The DP_DETECTED bit is the latched state of the DDC |
| 14688 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14689 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14690 | * eDP ports may have been muxed to an alternate function. |
| 14691 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14692 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14693 | * detect eDP ports. |
| 14694 | */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14695 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14696 | !intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14697 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
| 14698 | if (I915_READ(VLV_DP_B) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14699 | intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14700 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14701 | |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14702 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14703 | !intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14704 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
| 14705 | if (I915_READ(VLV_DP_C) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14706 | intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14707 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14708 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14709 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14710 | /* eDP not supported on port D, so don't check VBT */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14711 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
| 14712 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); |
| 14713 | if (I915_READ(CHV_DP_D) & DP_DETECTED) |
| 14714 | intel_dp_init(dev, CHV_DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14715 | } |
| 14716 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 14717 | intel_dsi_init(dev); |
Daniel Vetter | 09da55d | 2015-07-07 11:44:32 +0200 | [diff] [blame] | 14718 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14719 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14720 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14721 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14722 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14723 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14724 | if (!found && IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14725 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14726 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14727 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14728 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14729 | if (!found && IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14730 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14731 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14732 | |
| 14733 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14734 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14735 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14736 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14737 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14738 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14739 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14740 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14741 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14742 | if (IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14743 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14744 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14745 | } |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14746 | if (IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14747 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14748 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14749 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14750 | if (IS_G4X(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 14751 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14752 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 14753 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14754 | intel_dvo_init(dev); |
| 14755 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 14756 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14757 | intel_tv_init(dev); |
| 14758 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 14759 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14760 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14761 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14762 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14763 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14764 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14765 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14766 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 14767 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14768 | |
| 14769 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14770 | } |
| 14771 | |
| 14772 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14773 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14774 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14775 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14776 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14777 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14778 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14779 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14780 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 14781 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14782 | kfree(intel_fb); |
| 14783 | } |
| 14784 | |
| 14785 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14786 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14787 | unsigned int *handle) |
| 14788 | { |
| 14789 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14790 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14791 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14792 | if (obj->userptr.mm) { |
| 14793 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14794 | return -EINVAL; |
| 14795 | } |
| 14796 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14797 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14798 | } |
| 14799 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14800 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14801 | struct drm_file *file, |
| 14802 | unsigned flags, unsigned color, |
| 14803 | struct drm_clip_rect *clips, |
| 14804 | unsigned num_clips) |
| 14805 | { |
| 14806 | struct drm_device *dev = fb->dev; |
| 14807 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 14808 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 14809 | |
| 14810 | mutex_lock(&dev->struct_mutex); |
Paulo Zanoni | 74b4ea1 | 2015-07-14 16:29:14 -0300 | [diff] [blame] | 14811 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14812 | mutex_unlock(&dev->struct_mutex); |
| 14813 | |
| 14814 | return 0; |
| 14815 | } |
| 14816 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14817 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14818 | .destroy = intel_user_framebuffer_destroy, |
| 14819 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14820 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14821 | }; |
| 14822 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14823 | static |
| 14824 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 14825 | uint32_t pixel_format) |
| 14826 | { |
| 14827 | u32 gen = INTEL_INFO(dev)->gen; |
| 14828 | |
| 14829 | if (gen >= 9) { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14830 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 14831 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14832 | /* "The stride in bytes must not exceed the of the size of 8K |
| 14833 | * pixels and 32K bytes." |
| 14834 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14835 | return min(8192 * cpp, 32768); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14836 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14837 | return 32*1024; |
| 14838 | } else if (gen >= 4) { |
| 14839 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14840 | return 16*1024; |
| 14841 | else |
| 14842 | return 32*1024; |
| 14843 | } else if (gen >= 3) { |
| 14844 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14845 | return 8*1024; |
| 14846 | else |
| 14847 | return 16*1024; |
| 14848 | } else { |
| 14849 | /* XXX DSPC is limited to 4k tiled */ |
| 14850 | return 8*1024; |
| 14851 | } |
| 14852 | } |
| 14853 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 14854 | static int intel_framebuffer_init(struct drm_device *dev, |
| 14855 | struct intel_framebuffer *intel_fb, |
| 14856 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 14857 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14858 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14859 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 14860 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14861 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14862 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14863 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14864 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 14865 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14866 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 14867 | /* Enforce that fb modifier and tiling mode match, but only for |
| 14868 | * X-tiled. This is needed for FBC. */ |
| 14869 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 14870 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 14871 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 14872 | return -EINVAL; |
| 14873 | } |
| 14874 | } else { |
| 14875 | if (obj->tiling_mode == I915_TILING_X) |
| 14876 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 14877 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 14878 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 14879 | return -EINVAL; |
| 14880 | } |
| 14881 | } |
| 14882 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14883 | /* Passed in modifier sanity checking. */ |
| 14884 | switch (mode_cmd->modifier[0]) { |
| 14885 | case I915_FORMAT_MOD_Y_TILED: |
| 14886 | case I915_FORMAT_MOD_Yf_TILED: |
| 14887 | if (INTEL_INFO(dev)->gen < 9) { |
| 14888 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 14889 | mode_cmd->modifier[0]); |
| 14890 | return -EINVAL; |
| 14891 | } |
| 14892 | case DRM_FORMAT_MOD_NONE: |
| 14893 | case I915_FORMAT_MOD_X_TILED: |
| 14894 | break; |
| 14895 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 14896 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 14897 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14898 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14899 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14900 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14901 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
| 14902 | mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14903 | mode_cmd->pixel_format); |
| 14904 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 14905 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 14906 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14907 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14908 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14909 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14910 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 14911 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14912 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14913 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 14914 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14915 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14916 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14917 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14918 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14919 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14920 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14921 | mode_cmd->pitches[0] != obj->stride) { |
| 14922 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 14923 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14924 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14925 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14926 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14927 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14928 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14929 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14930 | case DRM_FORMAT_RGB565: |
| 14931 | case DRM_FORMAT_XRGB8888: |
| 14932 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14933 | break; |
| 14934 | case DRM_FORMAT_XRGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14935 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14936 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14937 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14938 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14939 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14940 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14941 | case DRM_FORMAT_ABGR8888: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14942 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
| 14943 | INTEL_INFO(dev)->gen < 9) { |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14944 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14945 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14946 | return -EINVAL; |
| 14947 | } |
| 14948 | break; |
| 14949 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14950 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14951 | case DRM_FORMAT_XBGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14952 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14953 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14954 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14955 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14956 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14957 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14958 | case DRM_FORMAT_ABGR2101010: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14959 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14960 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14961 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14962 | return -EINVAL; |
| 14963 | } |
| 14964 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14965 | case DRM_FORMAT_YUYV: |
| 14966 | case DRM_FORMAT_UYVY: |
| 14967 | case DRM_FORMAT_YVYU: |
| 14968 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14969 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14970 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14971 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14972 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14973 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14974 | break; |
| 14975 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14976 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14977 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14978 | return -EINVAL; |
| 14979 | } |
| 14980 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14981 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14982 | if (mode_cmd->offsets[0] != 0) |
| 14983 | return -EINVAL; |
| 14984 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 14985 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 14986 | mode_cmd->pixel_format, |
| 14987 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 14988 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 14989 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 14990 | return -EINVAL; |
| 14991 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14992 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 14993 | intel_fb->obj = obj; |
| 14994 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14995 | intel_fill_fb_info(dev_priv, &intel_fb->base); |
| 14996 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14997 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 14998 | if (ret) { |
| 14999 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 15000 | return ret; |
| 15001 | } |
| 15002 | |
Ville Syrjälä | 0b05e1e | 2016-01-14 15:22:09 +0200 | [diff] [blame] | 15003 | intel_fb->obj->framebuffer_references++; |
| 15004 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15005 | return 0; |
| 15006 | } |
| 15007 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15008 | static struct drm_framebuffer * |
| 15009 | intel_user_framebuffer_create(struct drm_device *dev, |
| 15010 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 15011 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15012 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 15013 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 15014 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 15015 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15016 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 15017 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 15018 | mode_cmd.handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 15019 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 15020 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15021 | |
Daniel Vetter | 92907cb | 2015-11-23 09:04:05 +0100 | [diff] [blame] | 15022 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 15023 | if (IS_ERR(fb)) |
| 15024 | drm_gem_object_unreference_unlocked(&obj->base); |
| 15025 | |
| 15026 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15027 | } |
| 15028 | |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 15029 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 15030 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 15031 | { |
| 15032 | } |
| 15033 | #endif |
| 15034 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15035 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15036 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 15037 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 15038 | .atomic_check = intel_atomic_check, |
| 15039 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 15040 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 15041 | .atomic_state_clear = intel_atomic_state_clear, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15042 | }; |
| 15043 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15044 | /** |
| 15045 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 15046 | * @dev_priv: device private |
| 15047 | */ |
| 15048 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15049 | { |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15050 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15051 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15052 | dev_priv->display.get_initial_plane_config = |
| 15053 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15054 | dev_priv->display.crtc_compute_clock = |
| 15055 | haswell_crtc_compute_clock; |
| 15056 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15057 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15058 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15059 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15060 | dev_priv->display.get_initial_plane_config = |
| 15061 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 15062 | dev_priv->display.crtc_compute_clock = |
| 15063 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 15064 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15065 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15066 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15067 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15068 | dev_priv->display.get_initial_plane_config = |
| 15069 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 15070 | dev_priv->display.crtc_compute_clock = |
| 15071 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15072 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 15073 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15074 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15075 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15076 | dev_priv->display.get_initial_plane_config = |
| 15077 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15078 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 15079 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15080 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 15081 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 15082 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15083 | dev_priv->display.get_initial_plane_config = |
| 15084 | i9xx_get_initial_plane_config; |
| 15085 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15086 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15087 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 15088 | } else if (IS_G4X(dev_priv)) { |
| 15089 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15090 | dev_priv->display.get_initial_plane_config = |
| 15091 | i9xx_get_initial_plane_config; |
| 15092 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 15093 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15094 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 15095 | } else if (IS_PINEVIEW(dev_priv)) { |
| 15096 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15097 | dev_priv->display.get_initial_plane_config = |
| 15098 | i9xx_get_initial_plane_config; |
| 15099 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 15100 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15101 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 15102 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15103 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15104 | dev_priv->display.get_initial_plane_config = |
| 15105 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 15106 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15107 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15108 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 15109 | } else { |
| 15110 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15111 | dev_priv->display.get_initial_plane_config = |
| 15112 | i9xx_get_initial_plane_config; |
| 15113 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 15114 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15115 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 15116 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15117 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15118 | /* Returns the core display clock speed */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15119 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 15120 | dev_priv->display.get_display_clock_speed = |
| 15121 | skylake_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15122 | else if (IS_BROXTON(dev_priv)) |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 15123 | dev_priv->display.get_display_clock_speed = |
| 15124 | broxton_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15125 | else if (IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 15126 | dev_priv->display.get_display_clock_speed = |
| 15127 | broadwell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15128 | else if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 15129 | dev_priv->display.get_display_clock_speed = |
| 15130 | haswell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15131 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 15132 | dev_priv->display.get_display_clock_speed = |
| 15133 | valleyview_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15134 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 15135 | dev_priv->display.get_display_clock_speed = |
| 15136 | ilk_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15137 | else if (IS_I945G(dev_priv) || IS_BROADWATER(dev_priv) || |
| 15138 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15139 | dev_priv->display.get_display_clock_speed = |
| 15140 | i945_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15141 | else if (IS_GM45(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 15142 | dev_priv->display.get_display_clock_speed = |
| 15143 | gm45_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15144 | else if (IS_CRESTLINE(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 15145 | dev_priv->display.get_display_clock_speed = |
| 15146 | i965gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15147 | else if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 15148 | dev_priv->display.get_display_clock_speed = |
| 15149 | pnv_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15150 | else if (IS_G33(dev_priv) || IS_G4X(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 15151 | dev_priv->display.get_display_clock_speed = |
| 15152 | g33_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15153 | else if (IS_I915G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15154 | dev_priv->display.get_display_clock_speed = |
| 15155 | i915_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15156 | else if (IS_I945GM(dev_priv) || IS_845G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15157 | dev_priv->display.get_display_clock_speed = |
| 15158 | i9xx_misc_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15159 | else if (IS_I915GM(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15160 | dev_priv->display.get_display_clock_speed = |
| 15161 | i915gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15162 | else if (IS_I865G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15163 | dev_priv->display.get_display_clock_speed = |
| 15164 | i865_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15165 | else if (IS_I85X(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15166 | dev_priv->display.get_display_clock_speed = |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 15167 | i85x_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 15168 | else { /* 830 */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15169 | WARN(!IS_I830(dev_priv), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15170 | dev_priv->display.get_display_clock_speed = |
| 15171 | i830_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 15172 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15173 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15174 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15175 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15176 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15177 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15178 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15179 | /* FIXME: detect B0+ stepping and use auto training */ |
| 15180 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15181 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15182 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 15183 | } |
| 15184 | |
| 15185 | if (IS_BROADWELL(dev_priv)) { |
| 15186 | dev_priv->display.modeset_commit_cdclk = |
| 15187 | broadwell_modeset_commit_cdclk; |
| 15188 | dev_priv->display.modeset_calc_cdclk = |
| 15189 | broadwell_modeset_calc_cdclk; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15190 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 15191 | dev_priv->display.modeset_commit_cdclk = |
| 15192 | valleyview_modeset_commit_cdclk; |
| 15193 | dev_priv->display.modeset_calc_cdclk = |
| 15194 | valleyview_modeset_calc_cdclk; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15195 | } else if (IS_BROXTON(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 15196 | dev_priv->display.modeset_commit_cdclk = |
| 15197 | broxton_modeset_commit_cdclk; |
| 15198 | dev_priv->display.modeset_calc_cdclk = |
| 15199 | broxton_modeset_calc_cdclk; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 15200 | } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 15201 | dev_priv->display.modeset_commit_cdclk = |
| 15202 | skl_modeset_commit_cdclk; |
| 15203 | dev_priv->display.modeset_calc_cdclk = |
| 15204 | skl_modeset_calc_cdclk; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15205 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 15206 | |
| 15207 | switch (INTEL_INFO(dev_priv)->gen) { |
| 15208 | case 2: |
| 15209 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 15210 | break; |
| 15211 | |
| 15212 | case 3: |
| 15213 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 15214 | break; |
| 15215 | |
| 15216 | case 4: |
| 15217 | case 5: |
| 15218 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 15219 | break; |
| 15220 | |
| 15221 | case 6: |
| 15222 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 15223 | break; |
| 15224 | case 7: |
| 15225 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
| 15226 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 15227 | break; |
| 15228 | case 9: |
| 15229 | /* Drop through - unsupported since execlist only. */ |
| 15230 | default: |
| 15231 | /* Default just returns -ENODEV to indicate unsupported */ |
| 15232 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 15233 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15234 | } |
| 15235 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15236 | /* |
| 15237 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 15238 | * resume, or other times. This quirk makes sure that's the case for |
| 15239 | * affected systems. |
| 15240 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 15241 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15242 | { |
| 15243 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15244 | |
| 15245 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15246 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15247 | } |
| 15248 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 15249 | static void quirk_pipeb_force(struct drm_device *dev) |
| 15250 | { |
| 15251 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15252 | |
| 15253 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 15254 | DRM_INFO("applying pipe b force quirk\n"); |
| 15255 | } |
| 15256 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15257 | /* |
| 15258 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 15259 | */ |
| 15260 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 15261 | { |
| 15262 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15263 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15264 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15265 | } |
| 15266 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 15267 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 15268 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 15269 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 15270 | */ |
| 15271 | static void quirk_invert_brightness(struct drm_device *dev) |
| 15272 | { |
| 15273 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15274 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15275 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15276 | } |
| 15277 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 15278 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 15279 | static void quirk_backlight_present(struct drm_device *dev) |
| 15280 | { |
| 15281 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15282 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 15283 | DRM_INFO("applying backlight present quirk\n"); |
| 15284 | } |
| 15285 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15286 | struct intel_quirk { |
| 15287 | int device; |
| 15288 | int subsystem_vendor; |
| 15289 | int subsystem_device; |
| 15290 | void (*hook)(struct drm_device *dev); |
| 15291 | }; |
| 15292 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 15293 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 15294 | struct intel_dmi_quirk { |
| 15295 | void (*hook)(struct drm_device *dev); |
| 15296 | const struct dmi_system_id (*dmi_id_list)[]; |
| 15297 | }; |
| 15298 | |
| 15299 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 15300 | { |
| 15301 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 15302 | return 1; |
| 15303 | } |
| 15304 | |
| 15305 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 15306 | { |
| 15307 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 15308 | { |
| 15309 | .callback = intel_dmi_reverse_brightness, |
| 15310 | .ident = "NCR Corporation", |
| 15311 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 15312 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 15313 | }, |
| 15314 | }, |
| 15315 | { } /* terminating entry */ |
| 15316 | }, |
| 15317 | .hook = quirk_invert_brightness, |
| 15318 | }, |
| 15319 | }; |
| 15320 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 15321 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15322 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 15323 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 15324 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15325 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 15326 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 15327 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 15328 | /* 830 needs to leave pipe A & dpll A up */ |
| 15329 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 15330 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 15331 | /* 830 needs to leave pipe B & dpll B up */ |
| 15332 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 15333 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15334 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 15335 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 15336 | |
| 15337 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 15338 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 15339 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 15340 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 15341 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 15342 | |
| 15343 | /* Acer/eMachines G725 */ |
| 15344 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 15345 | |
| 15346 | /* Acer/eMachines e725 */ |
| 15347 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 15348 | |
| 15349 | /* Acer/Packard Bell NCL20 */ |
| 15350 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 15351 | |
| 15352 | /* Acer Aspire 4736Z */ |
| 15353 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 15354 | |
| 15355 | /* Acer Aspire 5336 */ |
| 15356 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 15357 | |
| 15358 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 15359 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15360 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 15361 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 15362 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 15363 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 15364 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 15365 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 15366 | |
Jani Nikula | 1b9448b0 | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 15367 | /* Apple Macbook 4,1 */ |
| 15368 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 15369 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15370 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 15371 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 15372 | |
| 15373 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 15374 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 15375 | |
| 15376 | /* Dell Chromebook 11 */ |
| 15377 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 15378 | |
| 15379 | /* Dell Chromebook 11 (2015 version) */ |
| 15380 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15381 | }; |
| 15382 | |
| 15383 | static void intel_init_quirks(struct drm_device *dev) |
| 15384 | { |
| 15385 | struct pci_dev *d = dev->pdev; |
| 15386 | int i; |
| 15387 | |
| 15388 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 15389 | struct intel_quirk *q = &intel_quirks[i]; |
| 15390 | |
| 15391 | if (d->device == q->device && |
| 15392 | (d->subsystem_vendor == q->subsystem_vendor || |
| 15393 | q->subsystem_vendor == PCI_ANY_ID) && |
| 15394 | (d->subsystem_device == q->subsystem_device || |
| 15395 | q->subsystem_device == PCI_ANY_ID)) |
| 15396 | q->hook(dev); |
| 15397 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 15398 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 15399 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 15400 | intel_dmi_quirks[i].hook(dev); |
| 15401 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15402 | } |
| 15403 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15404 | /* Disable the VGA plane that we never use */ |
| 15405 | static void i915_disable_vga(struct drm_device *dev) |
| 15406 | { |
| 15407 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15408 | u8 sr1; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15409 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15410 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 15411 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15412 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 15413 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15414 | sr1 = inb(VGA_SR_DATA); |
| 15415 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 15416 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 15417 | udelay(300); |
| 15418 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 15419 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15420 | POSTING_READ(vga_reg); |
| 15421 | } |
| 15422 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15423 | void intel_modeset_init_hw(struct drm_device *dev) |
| 15424 | { |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15425 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15426 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 15427 | intel_update_cdclk(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15428 | |
| 15429 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; |
| 15430 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15431 | intel_init_clock_gating(dev); |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 15432 | intel_enable_gt_powersave(dev_priv); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15433 | } |
| 15434 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15435 | /* |
| 15436 | * Calculate what we think the watermarks should be for the state we've read |
| 15437 | * out of the hardware and then immediately program those watermarks so that |
| 15438 | * we ensure the hardware settings match our internal state. |
| 15439 | * |
| 15440 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 15441 | * current state (which was constructed during hardware readout) and running it |
| 15442 | * through the atomic check code to calculate new watermark values in the |
| 15443 | * state object. |
| 15444 | */ |
| 15445 | static void sanitize_watermarks(struct drm_device *dev) |
| 15446 | { |
| 15447 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15448 | struct drm_atomic_state *state; |
| 15449 | struct drm_crtc *crtc; |
| 15450 | struct drm_crtc_state *cstate; |
| 15451 | struct drm_modeset_acquire_ctx ctx; |
| 15452 | int ret; |
| 15453 | int i; |
| 15454 | |
| 15455 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15456 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15457 | return; |
| 15458 | |
| 15459 | /* |
| 15460 | * We need to hold connection_mutex before calling duplicate_state so |
| 15461 | * that the connector loop is protected. |
| 15462 | */ |
| 15463 | drm_modeset_acquire_init(&ctx, 0); |
| 15464 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15465 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15466 | if (ret == -EDEADLK) { |
| 15467 | drm_modeset_backoff(&ctx); |
| 15468 | goto retry; |
| 15469 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15470 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15471 | } |
| 15472 | |
| 15473 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15474 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15475 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15476 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15477 | /* |
| 15478 | * Hardware readout is the only time we don't want to calculate |
| 15479 | * intermediate watermarks (since we don't trust the current |
| 15480 | * watermarks). |
| 15481 | */ |
| 15482 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
| 15483 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15484 | ret = intel_atomic_check(dev, state); |
| 15485 | if (ret) { |
| 15486 | /* |
| 15487 | * If we fail here, it means that the hardware appears to be |
| 15488 | * programmed in a way that shouldn't be possible, given our |
| 15489 | * understanding of watermark requirements. This might mean a |
| 15490 | * mistake in the hardware readout code or a mistake in the |
| 15491 | * watermark calculations for a given platform. Raise a WARN |
| 15492 | * so that this is noticeable. |
| 15493 | * |
| 15494 | * If this actually happens, we'll have to just leave the |
| 15495 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15496 | */ |
| 15497 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15498 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15499 | } |
| 15500 | |
| 15501 | /* Write calculated watermark values back */ |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15502 | for_each_crtc_in_state(state, crtc, cstate, i) { |
| 15503 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15504 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15505 | cs->wm.need_postvbl_update = true; |
| 15506 | dev_priv->display.optimize_watermarks(cs); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15507 | } |
| 15508 | |
| 15509 | drm_atomic_state_free(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15510 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15511 | drm_modeset_drop_locks(&ctx); |
| 15512 | drm_modeset_acquire_fini(&ctx); |
| 15513 | } |
| 15514 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15515 | void intel_modeset_init(struct drm_device *dev) |
| 15516 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15517 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15518 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15519 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15520 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15521 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15522 | |
| 15523 | drm_mode_config_init(dev); |
| 15524 | |
| 15525 | dev->mode_config.min_width = 0; |
| 15526 | dev->mode_config.min_height = 0; |
| 15527 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15528 | dev->mode_config.preferred_depth = 24; |
| 15529 | dev->mode_config.prefer_shadow = 1; |
| 15530 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15531 | dev->mode_config.allow_fb_modifiers = true; |
| 15532 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15533 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15534 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15535 | intel_init_quirks(dev); |
| 15536 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15537 | intel_init_pm(dev); |
| 15538 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 15539 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 15540 | return; |
| 15541 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15542 | /* |
| 15543 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15544 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15545 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15546 | * indicates as much. |
| 15547 | */ |
| 15548 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { |
| 15549 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15550 | DREF_SSC1_ENABLE); |
| 15551 | |
| 15552 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15553 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15554 | bios_lvds_use_ssc ? "en" : "dis", |
| 15555 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15556 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15557 | } |
| 15558 | } |
| 15559 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15560 | if (IS_GEN2(dev)) { |
| 15561 | dev->mode_config.max_width = 2048; |
| 15562 | dev->mode_config.max_height = 2048; |
| 15563 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15564 | dev->mode_config.max_width = 4096; |
| 15565 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15566 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15567 | dev->mode_config.max_width = 8192; |
| 15568 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15569 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15570 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15571 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 15572 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 15573 | dev->mode_config.cursor_height = 1023; |
| 15574 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15575 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 15576 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 15577 | } else { |
| 15578 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 15579 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 15580 | } |
| 15581 | |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15582 | dev->mode_config.fb_base = ggtt->mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15583 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15584 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15585 | INTEL_INFO(dev)->num_pipes, |
| 15586 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15587 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15588 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15589 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 15590 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15591 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15592 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 15593 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15594 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15595 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15596 | } |
| 15597 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 15598 | intel_update_czclk(dev_priv); |
| 15599 | intel_update_cdclk(dev); |
| 15600 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15601 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15602 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15603 | if (dev_priv->max_cdclk_freq == 0) |
| 15604 | intel_update_max_cdclk(dev); |
| 15605 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15606 | /* Just disable it once at startup */ |
| 15607 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15608 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15609 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15610 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15611 | intel_modeset_setup_hw_state(dev); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15612 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15613 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15614 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15615 | struct intel_initial_plane_config plane_config = {}; |
| 15616 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15617 | if (!crtc->active) |
| 15618 | continue; |
| 15619 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15620 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15621 | * Note that reserving the BIOS fb up front prevents us |
| 15622 | * from stuffing other stolen allocations like the ring |
| 15623 | * on top. This prevents some ugliness at boot time, and |
| 15624 | * can even allow for smooth boot transitions if the BIOS |
| 15625 | * fb is large enough for the active pipe configuration. |
| 15626 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15627 | dev_priv->display.get_initial_plane_config(crtc, |
| 15628 | &plane_config); |
| 15629 | |
| 15630 | /* |
| 15631 | * If the fb is shared between multiple heads, we'll |
| 15632 | * just get the first one. |
| 15633 | */ |
| 15634 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15635 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15636 | |
| 15637 | /* |
| 15638 | * Make sure hardware watermarks really match the state we read out. |
| 15639 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15640 | * since the watermark calculation done here will use pstate->fb. |
| 15641 | */ |
| 15642 | sanitize_watermarks(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15643 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15644 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15645 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 15646 | { |
| 15647 | struct intel_connector *connector; |
| 15648 | struct drm_connector *crt = NULL; |
| 15649 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15650 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15651 | |
| 15652 | /* We can't just switch on the pipe A, we need to set things up with a |
| 15653 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 15654 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15655 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15656 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 15657 | crt = &connector->base; |
| 15658 | break; |
| 15659 | } |
| 15660 | } |
| 15661 | |
| 15662 | if (!crt) |
| 15663 | return; |
| 15664 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15665 | 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] | 15666 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15667 | } |
| 15668 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15669 | static bool |
| 15670 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 15671 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15672 | struct drm_device *dev = crtc->base.dev; |
| 15673 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15674 | u32 val; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15675 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15676 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15677 | return true; |
| 15678 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15679 | val = I915_READ(DSPCNTR(!crtc->plane)); |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15680 | |
| 15681 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 15682 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 15683 | return false; |
| 15684 | |
| 15685 | return true; |
| 15686 | } |
| 15687 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15688 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15689 | { |
| 15690 | struct drm_device *dev = crtc->base.dev; |
| 15691 | struct intel_encoder *encoder; |
| 15692 | |
| 15693 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15694 | return true; |
| 15695 | |
| 15696 | return false; |
| 15697 | } |
| 15698 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15699 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) |
| 15700 | { |
| 15701 | struct drm_device *dev = encoder->base.dev; |
| 15702 | struct intel_connector *connector; |
| 15703 | |
| 15704 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15705 | return true; |
| 15706 | |
| 15707 | return false; |
| 15708 | } |
| 15709 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15710 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 15711 | { |
| 15712 | struct drm_device *dev = crtc->base.dev; |
| 15713 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15714 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15715 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15716 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15717 | if (!transcoder_is_dsi(cpu_transcoder)) { |
| 15718 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15719 | |
| 15720 | I915_WRITE(reg, |
| 15721 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15722 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15723 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15724 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15725 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 15726 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15727 | struct intel_plane *plane; |
| 15728 | |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15729 | drm_crtc_vblank_on(&crtc->base); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15730 | |
| 15731 | /* Disable everything but the primary plane */ |
| 15732 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 15733 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 15734 | continue; |
| 15735 | |
| 15736 | plane->disable_plane(&plane->base, &crtc->base); |
| 15737 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15738 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15739 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15740 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15741 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 15742 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 15743 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15744 | bool plane; |
| 15745 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15746 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 15747 | crtc->base.base.id); |
| 15748 | |
| 15749 | /* Pipe has the wrong plane attached and the plane is active. |
| 15750 | * Temporarily change the plane mapping and disable everything |
| 15751 | * ... */ |
| 15752 | plane = crtc->plane; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15753 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15754 | crtc->plane = !plane; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15755 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15756 | crtc->plane = plane; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15757 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15758 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15759 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 15760 | crtc->pipe == PIPE_A && !crtc->active) { |
| 15761 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 15762 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 15763 | * call below we restore the pipe to the right state, but leave |
| 15764 | * the required bits on. */ |
| 15765 | intel_enable_pipe_a(dev); |
| 15766 | } |
| 15767 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15768 | /* Adjust the state of the output pipe according to whether we |
| 15769 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 15770 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15771 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15772 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 15773 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15774 | /* |
| 15775 | * We start out with underrun reporting disabled to avoid races. |
| 15776 | * For correct bookkeeping mark this on active crtcs. |
| 15777 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15778 | * Also on gmch platforms we dont have any hardware bits to |
| 15779 | * disable the underrun reporting. Which means we need to start |
| 15780 | * out with underrun reporting disabled also on inactive pipes, |
| 15781 | * since otherwise we'll complain about the garbage we read when |
| 15782 | * e.g. coming up after runtime pm. |
| 15783 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15784 | * No protection against concurrent access is required - at |
| 15785 | * worst a fifo underrun happens which also sets this to false. |
| 15786 | */ |
| 15787 | crtc->cpu_fifo_underrun_disabled = true; |
| 15788 | crtc->pch_fifo_underrun_disabled = true; |
| 15789 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15790 | } |
| 15791 | |
| 15792 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15793 | { |
| 15794 | struct intel_connector *connector; |
| 15795 | struct drm_device *dev = encoder->base.dev; |
| 15796 | |
| 15797 | /* We need to check both for a crtc link (meaning that the |
| 15798 | * encoder is active and trying to read from a pipe) and the |
| 15799 | * pipe itself being active. */ |
| 15800 | bool has_active_crtc = encoder->base.crtc && |
| 15801 | to_intel_crtc(encoder->base.crtc)->active; |
| 15802 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15803 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15804 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15805 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15806 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15807 | |
| 15808 | /* Connector is active, but has no active pipe. This is |
| 15809 | * fallout from our resume register restoring. Disable |
| 15810 | * the encoder manually again. */ |
| 15811 | if (encoder->base.crtc) { |
| 15812 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15813 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15814 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15815 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15816 | if (encoder->post_disable) |
| 15817 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15818 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15819 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15820 | |
| 15821 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15822 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15823 | * in our code, like the register restore mess on resume. Clamp |
| 15824 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15825 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15826 | if (connector->encoder != encoder) |
| 15827 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15828 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15829 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15830 | } |
| 15831 | } |
| 15832 | /* Enabled encoders without active connectors will be fixed in |
| 15833 | * the crtc fixup. */ |
| 15834 | } |
| 15835 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15836 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15837 | { |
| 15838 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15839 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15840 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15841 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15842 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 15843 | i915_disable_vga(dev); |
| 15844 | } |
| 15845 | } |
| 15846 | |
| 15847 | void i915_redisable_vga(struct drm_device *dev) |
| 15848 | { |
| 15849 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15850 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15851 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15852 | * at a very early point in our resume sequence, where the power well |
| 15853 | * structures are not yet restored. Since this function is at a very |
| 15854 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15855 | * level, just check if the power well is enabled instead of trying to |
| 15856 | * follow the "don't touch the power well if we don't need it" policy |
| 15857 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15858 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15859 | return; |
| 15860 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15861 | i915_redisable_vga_power_on(dev); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15862 | |
| 15863 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15864 | } |
| 15865 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15866 | static bool primary_get_hw_state(struct intel_plane *plane) |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15867 | { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15868 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15869 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15870 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15871 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15872 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15873 | /* FIXME read out full plane state for all planes */ |
| 15874 | static void readout_plane_state(struct intel_crtc *crtc) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15875 | { |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15876 | struct drm_plane *primary = crtc->base.primary; |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15877 | struct intel_plane_state *plane_state = |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15878 | to_intel_plane_state(primary->state); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15879 | |
Matt Roper | 19b8d38 | 2015-09-24 15:53:17 -0700 | [diff] [blame] | 15880 | plane_state->visible = crtc->active && |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15881 | primary_get_hw_state(to_intel_plane(primary)); |
| 15882 | |
| 15883 | if (plane_state->visible) |
| 15884 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15885 | } |
| 15886 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15887 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15888 | { |
| 15889 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15890 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15891 | struct intel_crtc *crtc; |
| 15892 | struct intel_encoder *encoder; |
| 15893 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15894 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15895 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15896 | dev_priv->active_crtcs = 0; |
| 15897 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15898 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15899 | struct intel_crtc_state *crtc_state = crtc->config; |
| 15900 | int pixclk = 0; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15901 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15902 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, &crtc_state->base); |
| 15903 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15904 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15905 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15906 | crtc_state->base.active = crtc_state->base.enable = |
| 15907 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15908 | |
| 15909 | crtc->base.enabled = crtc_state->base.enable; |
| 15910 | crtc->active = crtc_state->base.active; |
| 15911 | |
| 15912 | if (crtc_state->base.active) { |
| 15913 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15914 | |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 15915 | if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15916 | pixclk = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | 9558d15 | 2016-05-13 23:41:20 +0300 | [diff] [blame] | 15917 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15918 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; |
| 15919 | else |
| 15920 | WARN_ON(dev_priv->display.modeset_calc_cdclk); |
Ville Syrjälä | 9558d15 | 2016-05-13 23:41:20 +0300 | [diff] [blame] | 15921 | |
| 15922 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 15923 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
| 15924 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15925 | } |
| 15926 | |
| 15927 | dev_priv->min_pixclk[crtc->pipe] = pixclk; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15928 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15929 | readout_plane_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15930 | |
| 15931 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 15932 | crtc->base.base.id, |
| 15933 | crtc->active ? "enabled" : "disabled"); |
| 15934 | } |
| 15935 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15936 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15937 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15938 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 15939 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
| 15940 | &pll->config.hw_state); |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15941 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15942 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15943 | if (crtc->active && crtc->config->shared_dpll == pll) |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15944 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15945 | } |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15946 | pll->active_mask = pll->config.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15947 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15948 | 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] | 15949 | pll->name, pll->config.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15950 | } |
| 15951 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15952 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15953 | pipe = 0; |
| 15954 | |
| 15955 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15956 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15957 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15958 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15959 | } else { |
| 15960 | encoder->base.crtc = NULL; |
| 15961 | } |
| 15962 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15963 | 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] | 15964 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15965 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15966 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15967 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15968 | } |
| 15969 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15970 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15971 | if (connector->get_hw_state(connector)) { |
| 15972 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15973 | |
| 15974 | encoder = connector->encoder; |
| 15975 | connector->base.encoder = &encoder->base; |
| 15976 | |
| 15977 | if (encoder->base.crtc && |
| 15978 | encoder->base.crtc->state->active) { |
| 15979 | /* |
| 15980 | * This has to be done during hardware readout |
| 15981 | * because anything calling .crtc_disable may |
| 15982 | * rely on the connector_mask being accurate. |
| 15983 | */ |
| 15984 | encoder->base.crtc->state->connector_mask |= |
| 15985 | 1 << drm_connector_index(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15986 | encoder->base.crtc->state->encoder_mask |= |
| 15987 | 1 << drm_encoder_index(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15988 | } |
| 15989 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15990 | } else { |
| 15991 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15992 | connector->base.encoder = NULL; |
| 15993 | } |
| 15994 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 15995 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 15996 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15997 | connector->base.encoder ? "enabled" : "disabled"); |
| 15998 | } |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15999 | |
| 16000 | for_each_intel_crtc(dev, crtc) { |
| 16001 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
| 16002 | |
| 16003 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
| 16004 | if (crtc->base.state->active) { |
| 16005 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); |
| 16006 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); |
| 16007 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 16008 | |
| 16009 | /* |
| 16010 | * The initial mode needs to be set in order to keep |
| 16011 | * the atomic core happy. It wants a valid mode if the |
| 16012 | * crtc's enabled, so we do the above call. |
| 16013 | * |
| 16014 | * At this point some state updated by the connectors |
| 16015 | * in their ->detect() callback has not run yet, so |
| 16016 | * no recalculation can be done yet. |
| 16017 | * |
| 16018 | * Even if we could do a recalculation and modeset |
| 16019 | * right now it would cause a double modeset if |
| 16020 | * fbdev or userspace chooses a different initial mode. |
| 16021 | * |
| 16022 | * If that happens, someone indicated they wanted a |
| 16023 | * mode change, which means it's safe to do a full |
| 16024 | * recalculation. |
| 16025 | */ |
| 16026 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 16027 | |
| 16028 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
| 16029 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16030 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 16031 | |
| 16032 | intel_pipe_config_sanity_check(dev_priv, crtc->config); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16033 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16034 | } |
| 16035 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16036 | /* Scan out the current hw modeset state, |
| 16037 | * and sanitizes it to the current state |
| 16038 | */ |
| 16039 | static void |
| 16040 | intel_modeset_setup_hw_state(struct drm_device *dev) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16041 | { |
| 16042 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 16043 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16044 | struct intel_crtc *crtc; |
| 16045 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16046 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16047 | |
| 16048 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16049 | |
| 16050 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 16051 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16052 | intel_sanitize_encoder(encoder); |
| 16053 | } |
| 16054 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16055 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16056 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 16057 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 16058 | intel_dump_pipe_config(crtc, crtc->config, |
| 16059 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16060 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 16061 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 16062 | intel_modeset_update_connector_atomic_state(dev); |
| 16063 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16064 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 16065 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 16066 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 16067 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16068 | continue; |
| 16069 | |
| 16070 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 16071 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 16072 | pll->funcs.disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16073 | pll->on = false; |
| 16074 | } |
| 16075 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 16076 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 16077 | vlv_wm_get_hw_state(dev); |
| 16078 | else if (IS_GEN9(dev)) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 16079 | skl_wm_get_hw_state(dev); |
| 16080 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 16081 | ilk_wm_get_hw_state(dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16082 | |
| 16083 | for_each_intel_crtc(dev, crtc) { |
| 16084 | unsigned long put_domains; |
| 16085 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 16086 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16087 | if (WARN_ON(put_domains)) |
| 16088 | modeset_put_power_domains(dev_priv, put_domains); |
| 16089 | } |
| 16090 | intel_display_set_init_power(dev_priv, false); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 16091 | |
| 16092 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16093 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 16094 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16095 | void intel_display_resume(struct drm_device *dev) |
| 16096 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16097 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 16098 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 16099 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16100 | int ret; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16101 | bool setup = false; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 16102 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16103 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16104 | |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 16105 | /* |
| 16106 | * This is a cludge because with real atomic modeset mode_config.mutex |
| 16107 | * won't be taken. Unfortunately some probed state like |
| 16108 | * audio_codec_enable is still protected by mode_config.mutex, so lock |
| 16109 | * it here for now. |
| 16110 | */ |
| 16111 | mutex_lock(&dev->mode_config.mutex); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16112 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16113 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16114 | retry: |
| 16115 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16116 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16117 | if (ret == 0 && !setup) { |
| 16118 | setup = true; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16119 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16120 | intel_modeset_setup_hw_state(dev); |
| 16121 | i915_redisable_vga(dev); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 16122 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 16123 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16124 | if (ret == 0 && state) { |
| 16125 | struct drm_crtc_state *crtc_state; |
| 16126 | struct drm_crtc *crtc; |
| 16127 | int i; |
| 16128 | |
| 16129 | state->acquire_ctx = &ctx; |
| 16130 | |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 16131 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
| 16132 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
| 16133 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16134 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 16135 | /* |
| 16136 | * Force recalculation even if we restore |
| 16137 | * current state. With fast modeset this may not result |
| 16138 | * in a modeset when the state is compatible. |
| 16139 | */ |
| 16140 | crtc_state->mode_changed = true; |
| 16141 | } |
| 16142 | |
| 16143 | ret = drm_atomic_commit(state); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16144 | } |
| 16145 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16146 | if (ret == -EDEADLK) { |
| 16147 | drm_modeset_backoff(&ctx); |
| 16148 | goto retry; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16149 | } |
| 16150 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16151 | drm_modeset_drop_locks(&ctx); |
| 16152 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 16153 | mutex_unlock(&dev->mode_config.mutex); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16154 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16155 | if (ret) { |
| 16156 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 16157 | drm_atomic_state_free(state); |
| 16158 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 16159 | } |
| 16160 | |
| 16161 | void intel_modeset_gem_init(struct drm_device *dev) |
| 16162 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 16163 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16164 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 16165 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 16166 | int ret; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16167 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 16168 | intel_init_gt_powersave(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16169 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 16170 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 16171 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 16172 | intel_setup_overlay(dev_priv); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16173 | |
| 16174 | /* |
| 16175 | * Make sure any fbs we allocated at startup are properly |
| 16176 | * pinned & fenced. When we do the allocation it's too early |
| 16177 | * for this. |
| 16178 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 16179 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 16180 | obj = intel_fb_obj(c->primary->fb); |
| 16181 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16182 | continue; |
| 16183 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 16184 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 16185 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, |
| 16186 | c->primary->state->rotation); |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 16187 | mutex_unlock(&dev->struct_mutex); |
| 16188 | if (ret) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16189 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 16190 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 16191 | drm_framebuffer_unreference(c->primary->fb); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 16192 | c->primary->fb = NULL; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 16193 | c->primary->crtc = c->primary->state->crtc = NULL; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 16194 | update_state_fb(c->primary); |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 16195 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 16196 | } |
| 16197 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 16198 | |
| 16199 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16200 | } |
| 16201 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 16202 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 16203 | { |
| 16204 | struct drm_connector *connector = &intel_connector->base; |
| 16205 | |
| 16206 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 16207 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 16208 | } |
| 16209 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16210 | void intel_modeset_cleanup(struct drm_device *dev) |
| 16211 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 16212 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 16213 | struct intel_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 16214 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 16215 | intel_disable_gt_powersave(dev_priv); |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 16216 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 16217 | intel_backlight_unregister(dev); |
| 16218 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16219 | /* |
| 16220 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 16221 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16222 | * experience fancy races otherwise. |
| 16223 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 16224 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 16225 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16226 | /* |
| 16227 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 16228 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 16229 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 16230 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16231 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 16232 | intel_unregister_dsm_handler(); |
| 16233 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 16234 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 16235 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 16236 | /* flush any delayed tasks or pending work */ |
| 16237 | flush_scheduled_work(); |
| 16238 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 16239 | /* destroy the backlight and sysfs files before encoders/connectors */ |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 16240 | for_each_intel_connector(dev, connector) |
| 16241 | connector->unregister(connector); |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 16242 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16243 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 16244 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 16245 | intel_cleanup_overlay(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16246 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 16247 | intel_cleanup_gt_powersave(dev_priv); |
Daniel Vetter | f594914 | 2016-01-13 11:55:28 +0100 | [diff] [blame] | 16248 | |
| 16249 | intel_teardown_gmbus(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16250 | } |
| 16251 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16252 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 16253 | * Return which encoder is currently attached for connector. |
| 16254 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16255 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16256 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16257 | return &intel_attached_encoder(connector)->base; |
| 16258 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16259 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16260 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 16261 | struct intel_encoder *encoder) |
| 16262 | { |
| 16263 | connector->encoder = encoder; |
| 16264 | drm_mode_connector_attach_encoder(&connector->base, |
| 16265 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16266 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16267 | |
| 16268 | /* |
| 16269 | * set vga decode state - true == enable VGA decode |
| 16270 | */ |
| 16271 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 16272 | { |
| 16273 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 16274 | 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] | 16275 | u16 gmch_ctrl; |
| 16276 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16277 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 16278 | DRM_ERROR("failed to read control word\n"); |
| 16279 | return -EIO; |
| 16280 | } |
| 16281 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 16282 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16283 | return 0; |
| 16284 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16285 | if (state) |
| 16286 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16287 | else |
| 16288 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16289 | |
| 16290 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16291 | DRM_ERROR("failed to write control word\n"); |
| 16292 | return -EIO; |
| 16293 | } |
| 16294 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16295 | return 0; |
| 16296 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16297 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16298 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16299 | |
| 16300 | u32 power_well_driver; |
| 16301 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16302 | int num_transcoders; |
| 16303 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16304 | struct intel_cursor_error_state { |
| 16305 | u32 control; |
| 16306 | u32 position; |
| 16307 | u32 base; |
| 16308 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16309 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16310 | |
| 16311 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16312 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16313 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16314 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16315 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16316 | |
| 16317 | struct intel_plane_error_state { |
| 16318 | u32 control; |
| 16319 | u32 stride; |
| 16320 | u32 size; |
| 16321 | u32 pos; |
| 16322 | u32 addr; |
| 16323 | u32 surface; |
| 16324 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16325 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16326 | |
| 16327 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16328 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16329 | enum transcoder cpu_transcoder; |
| 16330 | |
| 16331 | u32 conf; |
| 16332 | |
| 16333 | u32 htotal; |
| 16334 | u32 hblank; |
| 16335 | u32 hsync; |
| 16336 | u32 vtotal; |
| 16337 | u32 vblank; |
| 16338 | u32 vsync; |
| 16339 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16340 | }; |
| 16341 | |
| 16342 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16343 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16344 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16345 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16346 | int transcoders[] = { |
| 16347 | TRANSCODER_A, |
| 16348 | TRANSCODER_B, |
| 16349 | TRANSCODER_C, |
| 16350 | TRANSCODER_EDP, |
| 16351 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16352 | int i; |
| 16353 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16354 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16355 | return NULL; |
| 16356 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16357 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16358 | if (error == NULL) |
| 16359 | return NULL; |
| 16360 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16361 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16362 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 16363 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16364 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16365 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16366 | __intel_display_power_is_enabled(dev_priv, |
| 16367 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16368 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16369 | continue; |
| 16370 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16371 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16372 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16373 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16374 | |
| 16375 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16376 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16377 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16378 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16379 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16380 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16381 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16382 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16383 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16384 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16385 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16386 | } |
| 16387 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16388 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16389 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16390 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16391 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16392 | } |
| 16393 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16394 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16395 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16396 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16397 | error->num_transcoders++; /* Account for eDP. */ |
| 16398 | |
| 16399 | for (i = 0; i < error->num_transcoders; i++) { |
| 16400 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16401 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16402 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16403 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16404 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16405 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16406 | continue; |
| 16407 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16408 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16409 | |
| 16410 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16411 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16412 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16413 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16414 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16415 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16416 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16417 | } |
| 16418 | |
| 16419 | return error; |
| 16420 | } |
| 16421 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16422 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16423 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16424 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16425 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16426 | struct drm_device *dev, |
| 16427 | struct intel_display_error_state *error) |
| 16428 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16429 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16430 | int i; |
| 16431 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16432 | if (!error) |
| 16433 | return; |
| 16434 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16435 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 16436 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16437 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16438 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16439 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16440 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16441 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16442 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16443 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16444 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16445 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16446 | err_printf(m, "Plane [%d]:\n", i); |
| 16447 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16448 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16449 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16450 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16451 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16452 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 16453 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16454 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16455 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16456 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16457 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16458 | } |
| 16459 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16460 | err_printf(m, "Cursor [%d]:\n", i); |
| 16461 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16462 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16463 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16464 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16465 | |
| 16466 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16467 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16468 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16469 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16470 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16471 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16472 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16473 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16474 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16475 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16476 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16477 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16478 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16479 | } |