Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 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 DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Keith Packard <keithp@keithp.com> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 30 | #include "drmP.h" |
| 31 | #include "drm.h" |
| 32 | #include "drm_crtc.h" |
| 33 | #include "drm_crtc_helper.h" |
| 34 | #include "intel_drv.h" |
| 35 | #include "i915_drm.h" |
| 36 | #include "i915_drv.h" |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 37 | #include "drm_dp_helper.h" |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 38 | |
Zhao Yakui | ae266c9 | 2009-11-24 09:48:46 +0800 | [diff] [blame] | 39 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 40 | #define DP_LINK_STATUS_SIZE 6 |
| 41 | #define DP_LINK_CHECK_TIMEOUT (10 * 1000) |
| 42 | |
| 43 | #define DP_LINK_CONFIGURATION_SIZE 9 |
| 44 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 45 | struct intel_dp { |
| 46 | struct intel_encoder base; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 47 | uint32_t output_reg; |
| 48 | uint32_t DP; |
| 49 | uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 50 | bool has_audio; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 51 | int force_audio; |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 52 | uint32_t color_range; |
Keith Packard | d2b996a | 2011-07-25 22:37:51 -0700 | [diff] [blame] | 53 | int dpms_mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 54 | uint8_t link_bw; |
| 55 | uint8_t lane_count; |
Adam Jackson | 9de88e6 | 2011-07-12 17:38:02 -0400 | [diff] [blame] | 56 | uint8_t dpcd[8]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 57 | struct i2c_adapter adapter; |
| 58 | struct i2c_algo_dp_aux_data algo; |
Adam Jackson | f091737 | 2010-07-16 14:46:27 -0400 | [diff] [blame] | 59 | bool is_pch_edp; |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 60 | uint8_t train_set[4]; |
| 61 | uint8_t link_status[DP_LINK_STATUS_SIZE]; |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 62 | int panel_power_up_delay; |
| 63 | int panel_power_down_delay; |
| 64 | int panel_power_cycle_delay; |
| 65 | int backlight_on_delay; |
| 66 | int backlight_off_delay; |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 67 | struct drm_display_mode *panel_fixed_mode; /* for eDP */ |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 68 | struct delayed_work panel_vdd_work; |
| 69 | bool want_panel_vdd; |
| 70 | unsigned long panel_off_jiffies; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 73 | /** |
| 74 | * is_edp - is the given port attached to an eDP panel (either CPU or PCH) |
| 75 | * @intel_dp: DP struct |
| 76 | * |
| 77 | * If a CPU or PCH DP output is attached to an eDP panel, this function |
| 78 | * will return true, and false otherwise. |
| 79 | */ |
| 80 | static bool is_edp(struct intel_dp *intel_dp) |
| 81 | { |
| 82 | return intel_dp->base.type == INTEL_OUTPUT_EDP; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * is_pch_edp - is the port on the PCH and attached to an eDP panel? |
| 87 | * @intel_dp: DP struct |
| 88 | * |
| 89 | * Returns true if the given DP struct corresponds to a PCH DP port attached |
| 90 | * to an eDP panel, false otherwise. Helpful for determining whether we |
| 91 | * may need FDI resources for a given DP output or not. |
| 92 | */ |
| 93 | static bool is_pch_edp(struct intel_dp *intel_dp) |
| 94 | { |
| 95 | return intel_dp->is_pch_edp; |
| 96 | } |
| 97 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 98 | static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder) |
| 99 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 100 | return container_of(encoder, struct intel_dp, base.base); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 101 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 102 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 103 | static struct intel_dp *intel_attached_dp(struct drm_connector *connector) |
| 104 | { |
| 105 | return container_of(intel_attached_encoder(connector), |
| 106 | struct intel_dp, base); |
| 107 | } |
| 108 | |
Jesse Barnes | 814948a | 2010-10-07 16:01:09 -0700 | [diff] [blame] | 109 | /** |
| 110 | * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP? |
| 111 | * @encoder: DRM encoder |
| 112 | * |
| 113 | * Return true if @encoder corresponds to a PCH attached eDP panel. Needed |
| 114 | * by intel_display.c. |
| 115 | */ |
| 116 | bool intel_encoder_is_pch_edp(struct drm_encoder *encoder) |
| 117 | { |
| 118 | struct intel_dp *intel_dp; |
| 119 | |
| 120 | if (!encoder) |
| 121 | return false; |
| 122 | |
| 123 | intel_dp = enc_to_intel_dp(encoder); |
| 124 | |
| 125 | return is_pch_edp(intel_dp); |
| 126 | } |
| 127 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 128 | static void intel_dp_start_link_train(struct intel_dp *intel_dp); |
| 129 | static void intel_dp_complete_link_train(struct intel_dp *intel_dp); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 130 | static void intel_dp_link_down(struct intel_dp *intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 131 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 132 | void |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 133 | intel_edp_link_config (struct intel_encoder *intel_encoder, |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 134 | int *lane_num, int *link_bw) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 135 | { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 136 | struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 137 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 138 | *lane_num = intel_dp->lane_count; |
| 139 | if (intel_dp->link_bw == DP_LINK_BW_1_62) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 140 | *link_bw = 162000; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 141 | else if (intel_dp->link_bw == DP_LINK_BW_2_7) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 142 | *link_bw = 270000; |
| 143 | } |
| 144 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 145 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 146 | intel_dp_max_lane_count(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 147 | { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 148 | int max_lane_count = 4; |
| 149 | |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 150 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { |
| 151 | max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 152 | switch (max_lane_count) { |
| 153 | case 1: case 2: case 4: |
| 154 | break; |
| 155 | default: |
| 156 | max_lane_count = 4; |
| 157 | } |
| 158 | } |
| 159 | return max_lane_count; |
| 160 | } |
| 161 | |
| 162 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 163 | intel_dp_max_link_bw(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 164 | { |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 165 | int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE]; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 166 | |
| 167 | switch (max_link_bw) { |
| 168 | case DP_LINK_BW_1_62: |
| 169 | case DP_LINK_BW_2_7: |
| 170 | break; |
| 171 | default: |
| 172 | max_link_bw = DP_LINK_BW_1_62; |
| 173 | break; |
| 174 | } |
| 175 | return max_link_bw; |
| 176 | } |
| 177 | |
| 178 | static int |
| 179 | intel_dp_link_clock(uint8_t link_bw) |
| 180 | { |
| 181 | if (link_bw == DP_LINK_BW_2_7) |
| 182 | return 270000; |
| 183 | else |
| 184 | return 162000; |
| 185 | } |
| 186 | |
| 187 | /* I think this is a fiction */ |
| 188 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 189 | intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 190 | { |
Jesse Barnes | 89c6143 | 2011-06-24 12:19:28 -0700 | [diff] [blame] | 191 | struct drm_crtc *crtc = intel_dp->base.base.crtc; |
| 192 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 193 | int bpp = 24; |
Zhenyu Wang | 885a5fb | 2010-01-12 05:38:31 +0800 | [diff] [blame] | 194 | |
Jesse Barnes | 89c6143 | 2011-06-24 12:19:28 -0700 | [diff] [blame] | 195 | if (intel_crtc) |
| 196 | bpp = intel_crtc->bpp; |
| 197 | |
| 198 | return (pixel_clock * bpp + 7) / 8; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 202 | intel_dp_max_data_rate(int max_link_clock, int max_lanes) |
| 203 | { |
| 204 | return (max_link_clock * max_lanes * 8) / 10; |
| 205 | } |
| 206 | |
| 207 | static int |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 208 | intel_dp_mode_valid(struct drm_connector *connector, |
| 209 | struct drm_display_mode *mode) |
| 210 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 211 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 212 | int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp)); |
| 213 | int max_lanes = intel_dp_max_lane_count(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 214 | |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 215 | if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) { |
| 216 | if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 217 | return MODE_PANEL; |
| 218 | |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 219 | if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay) |
Zhao Yakui | 7de56f4 | 2010-07-19 09:43:14 +0100 | [diff] [blame] | 220 | return MODE_PANEL; |
| 221 | } |
| 222 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 223 | /* only refuse the mode on non eDP since we have seen some weird eDP panels |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 224 | which are outside spec tolerances but somehow work by magic */ |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 225 | if (!is_edp(intel_dp) && |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 226 | (intel_dp_link_required(connector->dev, intel_dp, mode->clock) |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 227 | > intel_dp_max_data_rate(max_link_clock, max_lanes))) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 228 | return MODE_CLOCK_HIGH; |
| 229 | |
| 230 | if (mode->clock < 10000) |
| 231 | return MODE_CLOCK_LOW; |
| 232 | |
| 233 | return MODE_OK; |
| 234 | } |
| 235 | |
| 236 | static uint32_t |
| 237 | pack_aux(uint8_t *src, int src_bytes) |
| 238 | { |
| 239 | int i; |
| 240 | uint32_t v = 0; |
| 241 | |
| 242 | if (src_bytes > 4) |
| 243 | src_bytes = 4; |
| 244 | for (i = 0; i < src_bytes; i++) |
| 245 | v |= ((uint32_t) src[i]) << ((3-i) * 8); |
| 246 | return v; |
| 247 | } |
| 248 | |
| 249 | static void |
| 250 | unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes) |
| 251 | { |
| 252 | int i; |
| 253 | if (dst_bytes > 4) |
| 254 | dst_bytes = 4; |
| 255 | for (i = 0; i < dst_bytes; i++) |
| 256 | dst[i] = src >> ((3-i) * 8); |
| 257 | } |
| 258 | |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 259 | /* hrawclock is 1/4 the FSB frequency */ |
| 260 | static int |
| 261 | intel_hrawclk(struct drm_device *dev) |
| 262 | { |
| 263 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 264 | uint32_t clkcfg; |
| 265 | |
| 266 | clkcfg = I915_READ(CLKCFG); |
| 267 | switch (clkcfg & CLKCFG_FSB_MASK) { |
| 268 | case CLKCFG_FSB_400: |
| 269 | return 100; |
| 270 | case CLKCFG_FSB_533: |
| 271 | return 133; |
| 272 | case CLKCFG_FSB_667: |
| 273 | return 166; |
| 274 | case CLKCFG_FSB_800: |
| 275 | return 200; |
| 276 | case CLKCFG_FSB_1067: |
| 277 | return 266; |
| 278 | case CLKCFG_FSB_1333: |
| 279 | return 333; |
| 280 | /* these two are just a guess; one of them might be right */ |
| 281 | case CLKCFG_FSB_1600: |
| 282 | case CLKCFG_FSB_1600_ALT: |
| 283 | return 400; |
| 284 | default: |
| 285 | return 133; |
| 286 | } |
| 287 | } |
| 288 | |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 289 | static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp) |
| 290 | { |
| 291 | struct drm_device *dev = intel_dp->base.base.dev; |
| 292 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 293 | |
| 294 | return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0; |
| 295 | } |
| 296 | |
| 297 | static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp) |
| 298 | { |
| 299 | struct drm_device *dev = intel_dp->base.base.dev; |
| 300 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 301 | |
| 302 | return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0; |
| 303 | } |
| 304 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 305 | static void |
| 306 | intel_dp_check_edp(struct intel_dp *intel_dp) |
| 307 | { |
| 308 | struct drm_device *dev = intel_dp->base.base.dev; |
| 309 | struct drm_i915_private *dev_priv = dev->dev_private; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 310 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 311 | if (!is_edp(intel_dp)) |
| 312 | return; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 313 | if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) { |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 314 | WARN(1, "eDP powered off while attempting aux channel communication.\n"); |
| 315 | DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n", |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 316 | I915_READ(PCH_PP_STATUS), |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 317 | I915_READ(PCH_PP_CONTROL)); |
| 318 | } |
| 319 | } |
| 320 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 321 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 322 | intel_dp_aux_ch(struct intel_dp *intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 323 | uint8_t *send, int send_bytes, |
| 324 | uint8_t *recv, int recv_size) |
| 325 | { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 326 | uint32_t output_reg = intel_dp->output_reg; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 327 | struct drm_device *dev = intel_dp->base.base.dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 329 | uint32_t ch_ctl = output_reg + 0x10; |
| 330 | uint32_t ch_data = ch_ctl + 4; |
| 331 | int i; |
| 332 | int recv_bytes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 333 | uint32_t status; |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 334 | uint32_t aux_clock_divider; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 335 | int try, precharge; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 336 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 337 | intel_dp_check_edp(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 338 | /* The clock divider is based off the hrawclk, |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 339 | * and would like to run at 2MHz. So, take the |
| 340 | * hrawclk value and divide by 2 and use that |
Jesse Barnes | 6176b8f | 2010-09-08 12:42:00 -0700 | [diff] [blame] | 341 | * |
| 342 | * Note that PCH attached eDP panels should use a 125MHz input |
| 343 | * clock divider. |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 344 | */ |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 345 | if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 346 | if (IS_GEN6(dev)) |
| 347 | aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */ |
| 348 | else |
| 349 | aux_clock_divider = 225; /* eDP input clock at 450Mhz */ |
| 350 | } else if (HAS_PCH_SPLIT(dev)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 351 | aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 352 | else |
| 353 | aux_clock_divider = intel_hrawclk(dev) / 2; |
| 354 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 355 | if (IS_GEN6(dev)) |
| 356 | precharge = 3; |
| 357 | else |
| 358 | precharge = 5; |
| 359 | |
Jesse Barnes | 11bee43 | 2011-08-01 15:02:20 -0700 | [diff] [blame] | 360 | /* Try to wait for any previous AUX channel activity */ |
| 361 | for (try = 0; try < 3; try++) { |
| 362 | status = I915_READ(ch_ctl); |
| 363 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 364 | break; |
| 365 | msleep(1); |
| 366 | } |
| 367 | |
| 368 | if (try == 3) { |
| 369 | WARN(1, "dp_aux_ch not started status 0x%08x\n", |
| 370 | I915_READ(ch_ctl)); |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 371 | return -EBUSY; |
| 372 | } |
| 373 | |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 374 | /* Must try at least 3 times according to DP spec */ |
| 375 | for (try = 0; try < 5; try++) { |
| 376 | /* Load the send data into the aux channel data registers */ |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 377 | for (i = 0; i < send_bytes; i += 4) |
| 378 | I915_WRITE(ch_data + i, |
| 379 | pack_aux(send + i, send_bytes - i)); |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 380 | |
| 381 | /* Send the command and wait for it to complete */ |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 382 | I915_WRITE(ch_ctl, |
| 383 | DP_AUX_CH_CTL_SEND_BUSY | |
| 384 | DP_AUX_CH_CTL_TIME_OUT_400us | |
| 385 | (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 386 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
| 387 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) | |
| 388 | DP_AUX_CH_CTL_DONE | |
| 389 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 390 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 391 | for (;;) { |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 392 | status = I915_READ(ch_ctl); |
| 393 | if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0) |
| 394 | break; |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 395 | udelay(100); |
Keith Packard | fb0f8fb | 2009-06-11 22:31:31 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* Clear done status and any errors */ |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 399 | I915_WRITE(ch_ctl, |
| 400 | status | |
| 401 | DP_AUX_CH_CTL_DONE | |
| 402 | DP_AUX_CH_CTL_TIME_OUT_ERROR | |
| 403 | DP_AUX_CH_CTL_RECEIVE_ERROR); |
| 404 | if (status & DP_AUX_CH_CTL_DONE) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 408 | if ((status & DP_AUX_CH_CTL_DONE) == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 409 | DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status); |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 410 | return -EBUSY; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* Check for timeout or receive error. |
| 414 | * Timeouts occur when the sink is not connected |
| 415 | */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 416 | if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 417 | DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status); |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 418 | return -EIO; |
| 419 | } |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 420 | |
| 421 | /* Timeouts occur when the device isn't connected, so they're |
| 422 | * "normal" -- don't fill the kernel log with these */ |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 423 | if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 424 | DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status); |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 425 | return -ETIMEDOUT; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* Unload any bytes sent back from the other side */ |
| 429 | recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >> |
| 430 | DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 431 | if (recv_bytes > recv_size) |
| 432 | recv_bytes = recv_size; |
| 433 | |
Chris Wilson | 4f7f7b7 | 2010-08-18 18:12:56 +0100 | [diff] [blame] | 434 | for (i = 0; i < recv_bytes; i += 4) |
| 435 | unpack_aux(I915_READ(ch_data + i), |
| 436 | recv + i, recv_bytes - i); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 437 | |
| 438 | return recv_bytes; |
| 439 | } |
| 440 | |
| 441 | /* Write data to the aux channel in native mode */ |
| 442 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 443 | intel_dp_aux_native_write(struct intel_dp *intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 444 | uint16_t address, uint8_t *send, int send_bytes) |
| 445 | { |
| 446 | int ret; |
| 447 | uint8_t msg[20]; |
| 448 | int msg_bytes; |
| 449 | uint8_t ack; |
| 450 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 451 | intel_dp_check_edp(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 452 | if (send_bytes > 16) |
| 453 | return -1; |
| 454 | msg[0] = AUX_NATIVE_WRITE << 4; |
| 455 | msg[1] = address >> 8; |
Zhenyu Wang | eebc863 | 2009-07-24 01:00:30 +0800 | [diff] [blame] | 456 | msg[2] = address & 0xff; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 457 | msg[3] = send_bytes - 1; |
| 458 | memcpy(&msg[4], send, send_bytes); |
| 459 | msg_bytes = send_bytes + 4; |
| 460 | for (;;) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 461 | ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 462 | if (ret < 0) |
| 463 | return ret; |
| 464 | if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) |
| 465 | break; |
| 466 | else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER) |
| 467 | udelay(100); |
| 468 | else |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 469 | return -EIO; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 470 | } |
| 471 | return send_bytes; |
| 472 | } |
| 473 | |
| 474 | /* Write a single byte to the aux channel in native mode */ |
| 475 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 476 | intel_dp_aux_native_write_1(struct intel_dp *intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 477 | uint16_t address, uint8_t byte) |
| 478 | { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 479 | return intel_dp_aux_native_write(intel_dp, address, &byte, 1); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* read bytes from a native aux channel */ |
| 483 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 484 | intel_dp_aux_native_read(struct intel_dp *intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 485 | uint16_t address, uint8_t *recv, int recv_bytes) |
| 486 | { |
| 487 | uint8_t msg[4]; |
| 488 | int msg_bytes; |
| 489 | uint8_t reply[20]; |
| 490 | int reply_bytes; |
| 491 | uint8_t ack; |
| 492 | int ret; |
| 493 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 494 | intel_dp_check_edp(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 495 | msg[0] = AUX_NATIVE_READ << 4; |
| 496 | msg[1] = address >> 8; |
| 497 | msg[2] = address & 0xff; |
| 498 | msg[3] = recv_bytes - 1; |
| 499 | |
| 500 | msg_bytes = 4; |
| 501 | reply_bytes = recv_bytes + 1; |
| 502 | |
| 503 | for (;;) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 504 | ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 505 | reply, reply_bytes); |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 506 | if (ret == 0) |
| 507 | return -EPROTO; |
| 508 | if (ret < 0) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 509 | return ret; |
| 510 | ack = reply[0]; |
| 511 | if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) { |
| 512 | memcpy(recv, reply + 1, ret - 1); |
| 513 | return ret - 1; |
| 514 | } |
| 515 | else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER) |
| 516 | udelay(100); |
| 517 | else |
Keith Packard | a5b3da5 | 2009-06-11 22:30:32 -0700 | [diff] [blame] | 518 | return -EIO; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | static int |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 523 | intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, |
| 524 | uint8_t write_byte, uint8_t *read_byte) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 525 | { |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 526 | struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 527 | struct intel_dp *intel_dp = container_of(adapter, |
| 528 | struct intel_dp, |
| 529 | adapter); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 530 | uint16_t address = algo_data->address; |
| 531 | uint8_t msg[5]; |
| 532 | uint8_t reply[2]; |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 533 | unsigned retry; |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 534 | int msg_bytes; |
| 535 | int reply_bytes; |
| 536 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 537 | |
Keith Packard | 9b984da | 2011-09-19 13:54:47 -0700 | [diff] [blame] | 538 | intel_dp_check_edp(intel_dp); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 539 | /* Set up the command byte */ |
| 540 | if (mode & MODE_I2C_READ) |
| 541 | msg[0] = AUX_I2C_READ << 4; |
| 542 | else |
| 543 | msg[0] = AUX_I2C_WRITE << 4; |
| 544 | |
| 545 | if (!(mode & MODE_I2C_STOP)) |
| 546 | msg[0] |= AUX_I2C_MOT << 4; |
| 547 | |
| 548 | msg[1] = address >> 8; |
| 549 | msg[2] = address; |
| 550 | |
| 551 | switch (mode) { |
| 552 | case MODE_I2C_WRITE: |
| 553 | msg[3] = 0; |
| 554 | msg[4] = write_byte; |
| 555 | msg_bytes = 5; |
| 556 | reply_bytes = 1; |
| 557 | break; |
| 558 | case MODE_I2C_READ: |
| 559 | msg[3] = 0; |
| 560 | msg_bytes = 4; |
| 561 | reply_bytes = 2; |
| 562 | break; |
| 563 | default: |
| 564 | msg_bytes = 3; |
| 565 | reply_bytes = 1; |
| 566 | break; |
| 567 | } |
| 568 | |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 569 | for (retry = 0; retry < 5; retry++) { |
| 570 | ret = intel_dp_aux_ch(intel_dp, |
| 571 | msg, msg_bytes, |
| 572 | reply, reply_bytes); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 573 | if (ret < 0) { |
Dave Airlie | 3ff9916 | 2009-12-08 14:03:47 +1000 | [diff] [blame] | 574 | DRM_DEBUG_KMS("aux_ch failed %d\n", ret); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 575 | return ret; |
| 576 | } |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 577 | |
| 578 | switch (reply[0] & AUX_NATIVE_REPLY_MASK) { |
| 579 | case AUX_NATIVE_REPLY_ACK: |
| 580 | /* I2C-over-AUX Reply field is only valid |
| 581 | * when paired with AUX ACK. |
| 582 | */ |
| 583 | break; |
| 584 | case AUX_NATIVE_REPLY_NACK: |
| 585 | DRM_DEBUG_KMS("aux_ch native nack\n"); |
| 586 | return -EREMOTEIO; |
| 587 | case AUX_NATIVE_REPLY_DEFER: |
| 588 | udelay(100); |
| 589 | continue; |
| 590 | default: |
| 591 | DRM_ERROR("aux_ch invalid native reply 0x%02x\n", |
| 592 | reply[0]); |
| 593 | return -EREMOTEIO; |
| 594 | } |
| 595 | |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 596 | switch (reply[0] & AUX_I2C_REPLY_MASK) { |
| 597 | case AUX_I2C_REPLY_ACK: |
| 598 | if (mode == MODE_I2C_READ) { |
| 599 | *read_byte = reply[1]; |
| 600 | } |
| 601 | return reply_bytes - 1; |
| 602 | case AUX_I2C_REPLY_NACK: |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 603 | DRM_DEBUG_KMS("aux_i2c nack\n"); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 604 | return -EREMOTEIO; |
| 605 | case AUX_I2C_REPLY_DEFER: |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 606 | DRM_DEBUG_KMS("aux_i2c defer\n"); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 607 | udelay(100); |
| 608 | break; |
| 609 | default: |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 610 | DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]); |
Dave Airlie | ab2c067 | 2009-12-04 10:55:24 +1000 | [diff] [blame] | 611 | return -EREMOTEIO; |
| 612 | } |
| 613 | } |
David Flynn | 8316f33 | 2010-12-08 16:10:21 +0000 | [diff] [blame] | 614 | |
| 615 | DRM_ERROR("too many retries, giving up\n"); |
| 616 | return -EREMOTEIO; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Keith Packard | 0b5c541 | 2011-09-28 16:41:05 -0700 | [diff] [blame] | 619 | static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 620 | static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync); |
Keith Packard | 0b5c541 | 2011-09-28 16:41:05 -0700 | [diff] [blame] | 621 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 622 | static int |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 623 | intel_dp_i2c_init(struct intel_dp *intel_dp, |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 624 | struct intel_connector *intel_connector, const char *name) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 625 | { |
Keith Packard | 0b5c541 | 2011-09-28 16:41:05 -0700 | [diff] [blame] | 626 | int ret; |
| 627 | |
Zhenyu Wang | d54e9d2 | 2009-10-19 15:43:51 +0800 | [diff] [blame] | 628 | DRM_DEBUG_KMS("i2c_init %s\n", name); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 629 | intel_dp->algo.running = false; |
| 630 | intel_dp->algo.address = 0; |
| 631 | intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 632 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 633 | memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter)); |
| 634 | intel_dp->adapter.owner = THIS_MODULE; |
| 635 | intel_dp->adapter.class = I2C_CLASS_DDC; |
| 636 | strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1); |
| 637 | intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0'; |
| 638 | intel_dp->adapter.algo_data = &intel_dp->algo; |
| 639 | intel_dp->adapter.dev.parent = &intel_connector->base.kdev; |
| 640 | |
Keith Packard | 0b5c541 | 2011-09-28 16:41:05 -0700 | [diff] [blame] | 641 | ironlake_edp_panel_vdd_on(intel_dp); |
| 642 | ret = i2c_dp_aux_add_bus(&intel_dp->adapter); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 643 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Keith Packard | 0b5c541 | 2011-09-28 16:41:05 -0700 | [diff] [blame] | 644 | return ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static bool |
| 648 | intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 649 | struct drm_display_mode *adjusted_mode) |
| 650 | { |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 651 | struct drm_device *dev = encoder->dev; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 652 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 653 | int lane_count, clock; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 654 | int max_lane_count = intel_dp_max_lane_count(intel_dp); |
| 655 | int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 656 | static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; |
| 657 | |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 658 | if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) { |
| 659 | intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode); |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 660 | intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN, |
| 661 | mode, adjusted_mode); |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 662 | /* |
| 663 | * the mode->clock is used to calculate the Data&Link M/N |
| 664 | * of the pipe. For the eDP the fixed clock should be used. |
| 665 | */ |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 666 | mode->clock = intel_dp->panel_fixed_mode->clock; |
Zhao Yakui | 0d3a1be | 2010-07-19 09:43:13 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 669 | for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { |
| 670 | for (clock = 0; clock <= max_clock; clock++) { |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 671 | int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 672 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 673 | if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock) |
Zhenyu Wang | 885a5fb | 2010-01-12 05:38:31 +0800 | [diff] [blame] | 674 | <= link_avail) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 675 | intel_dp->link_bw = bws[clock]; |
| 676 | intel_dp->lane_count = lane_count; |
| 677 | adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw); |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 678 | DRM_DEBUG_KMS("Display port link bw %02x lane " |
| 679 | "count %d clock %d\n", |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 680 | intel_dp->link_bw, intel_dp->lane_count, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 681 | adjusted_mode->clock); |
| 682 | return true; |
| 683 | } |
| 684 | } |
| 685 | } |
Dave Airlie | fe27d53 | 2010-06-30 11:46:17 +1000 | [diff] [blame] | 686 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 687 | if (is_edp(intel_dp)) { |
| 688 | /* okay we failed just pick the highest */ |
| 689 | intel_dp->lane_count = max_lane_count; |
| 690 | intel_dp->link_bw = bws[max_clock]; |
| 691 | adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw); |
| 692 | DRM_DEBUG_KMS("Force picking display port link bw %02x lane " |
| 693 | "count %d clock %d\n", |
| 694 | intel_dp->link_bw, intel_dp->lane_count, |
| 695 | adjusted_mode->clock); |
| 696 | |
| 697 | return true; |
| 698 | } |
| 699 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 700 | return false; |
| 701 | } |
| 702 | |
| 703 | struct intel_dp_m_n { |
| 704 | uint32_t tu; |
| 705 | uint32_t gmch_m; |
| 706 | uint32_t gmch_n; |
| 707 | uint32_t link_m; |
| 708 | uint32_t link_n; |
| 709 | }; |
| 710 | |
| 711 | static void |
| 712 | intel_reduce_ratio(uint32_t *num, uint32_t *den) |
| 713 | { |
| 714 | while (*num > 0xffffff || *den > 0xffffff) { |
| 715 | *num >>= 1; |
| 716 | *den >>= 1; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | static void |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 721 | intel_dp_compute_m_n(int bpp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 722 | int nlanes, |
| 723 | int pixel_clock, |
| 724 | int link_clock, |
| 725 | struct intel_dp_m_n *m_n) |
| 726 | { |
| 727 | m_n->tu = 64; |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 728 | m_n->gmch_m = (pixel_clock * bpp) >> 3; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 729 | m_n->gmch_n = link_clock * nlanes; |
| 730 | intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); |
| 731 | m_n->link_m = pixel_clock; |
| 732 | m_n->link_n = link_clock; |
| 733 | intel_reduce_ratio(&m_n->link_m, &m_n->link_n); |
| 734 | } |
| 735 | |
| 736 | void |
| 737 | intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 738 | struct drm_display_mode *adjusted_mode) |
| 739 | { |
| 740 | struct drm_device *dev = crtc->dev; |
| 741 | struct drm_mode_config *mode_config = &dev->mode_config; |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 742 | struct drm_encoder *encoder; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 743 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 744 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 858fa035 | 2011-06-24 12:19:24 -0700 | [diff] [blame] | 745 | int lane_count = 4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 746 | struct intel_dp_m_n m_n; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 747 | int pipe = intel_crtc->pipe; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 748 | |
| 749 | /* |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 750 | * Find the lane count in the intel_encoder private |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 751 | */ |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 752 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 753 | struct intel_dp *intel_dp; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 754 | |
Dan Carpenter | d8201ab | 2010-05-07 10:39:00 +0200 | [diff] [blame] | 755 | if (encoder->crtc != crtc) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 756 | continue; |
| 757 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 758 | intel_dp = enc_to_intel_dp(encoder); |
| 759 | if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) { |
| 760 | lane_count = intel_dp->lane_count; |
Jesse Barnes | 5119066 | 2010-10-07 16:01:08 -0700 | [diff] [blame] | 761 | break; |
| 762 | } else if (is_edp(intel_dp)) { |
| 763 | lane_count = dev_priv->edp.lanes; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 764 | break; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /* |
| 769 | * Compute the GMCH and Link ratios. The '3' here is |
| 770 | * the number of bytes_per_pixel post-LUT, which we always |
| 771 | * set up for 8-bits of R/G/B, or 3 bytes total. |
| 772 | */ |
Jesse Barnes | 858fa035 | 2011-06-24 12:19:24 -0700 | [diff] [blame] | 773 | intel_dp_compute_m_n(intel_crtc->bpp, lane_count, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 774 | mode->clock, adjusted_mode->clock, &m_n); |
| 775 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 776 | if (HAS_PCH_SPLIT(dev)) { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 777 | I915_WRITE(TRANSDATA_M1(pipe), |
| 778 | ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) | |
| 779 | m_n.gmch_m); |
| 780 | I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n); |
| 781 | I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m); |
| 782 | I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 783 | } else { |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 784 | I915_WRITE(PIPE_GMCH_DATA_M(pipe), |
| 785 | ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) | |
| 786 | m_n.gmch_m); |
| 787 | I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n); |
| 788 | I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m); |
| 789 | I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 793 | static void ironlake_edp_pll_on(struct drm_encoder *encoder); |
| 794 | static void ironlake_edp_pll_off(struct drm_encoder *encoder); |
| 795 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 796 | static void |
| 797 | intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 798 | struct drm_display_mode *adjusted_mode) |
| 799 | { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 800 | struct drm_device *dev = encoder->dev; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 801 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 802 | struct drm_crtc *crtc = intel_dp->base.base.crtc; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 803 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 804 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 805 | /* Turn on the eDP PLL if needed */ |
| 806 | if (is_edp(intel_dp)) { |
| 807 | if (!is_pch_edp(intel_dp)) |
| 808 | ironlake_edp_pll_on(encoder); |
| 809 | else |
| 810 | ironlake_edp_pll_off(encoder); |
| 811 | } |
| 812 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 813 | intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; |
| 814 | intel_dp->DP |= intel_dp->color_range; |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 815 | |
| 816 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 817 | intel_dp->DP |= DP_SYNC_HS_HIGH; |
Adam Jackson | 9c9e792 | 2010-04-05 17:57:59 -0400 | [diff] [blame] | 818 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 819 | intel_dp->DP |= DP_SYNC_VS_HIGH; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 820 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 821 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 822 | intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 823 | else |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 824 | intel_dp->DP |= DP_LINK_TRAIN_OFF; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 825 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 826 | switch (intel_dp->lane_count) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 827 | case 1: |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 828 | intel_dp->DP |= DP_PORT_WIDTH_1; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 829 | break; |
| 830 | case 2: |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 831 | intel_dp->DP |= DP_PORT_WIDTH_2; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 832 | break; |
| 833 | case 4: |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 834 | intel_dp->DP |= DP_PORT_WIDTH_4; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 835 | break; |
| 836 | } |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 837 | if (intel_dp->has_audio) |
| 838 | intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 839 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 840 | memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE); |
| 841 | intel_dp->link_configuration[0] = intel_dp->link_bw; |
| 842 | intel_dp->link_configuration[1] = intel_dp->lane_count; |
Adam Jackson | a2cab1b | 2011-07-12 17:38:05 -0400 | [diff] [blame] | 843 | intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 844 | |
| 845 | /* |
Adam Jackson | 9962c92 | 2010-05-13 14:45:42 -0400 | [diff] [blame] | 846 | * Check for DPCD version > 1.1 and enhanced framing support |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 847 | */ |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 848 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && |
| 849 | (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 850 | intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; |
| 851 | intel_dp->DP |= DP_ENHANCED_FRAMING; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 854 | /* CPT DP's pipe select is decided in TRANS_DP_CTL */ |
| 855 | if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev)) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 856 | intel_dp->DP |= DP_PIPEB_SELECT; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 857 | |
Jesse Barnes | 895692b | 2010-10-07 16:01:23 -0700 | [diff] [blame] | 858 | if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 859 | /* don't miss out required setting for eDP */ |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 860 | intel_dp->DP |= DP_PLL_ENABLE; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 861 | if (adjusted_mode->clock < 200000) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 862 | intel_dp->DP |= DP_PLL_FREQ_160MHZ; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 863 | else |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 864 | intel_dp->DP |= DP_PLL_FREQ_270MHZ; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 865 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 868 | static void ironlake_wait_panel_off(struct intel_dp *intel_dp) |
| 869 | { |
| 870 | unsigned long off_time; |
| 871 | unsigned long delay; |
Keith Packard | 32ce697 | 2011-09-29 16:51:26 -0700 | [diff] [blame^] | 872 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 873 | DRM_DEBUG_KMS("Wait for panel power off time\n"); |
Keith Packard | 32ce697 | 2011-09-29 16:51:26 -0700 | [diff] [blame^] | 874 | |
| 875 | if (ironlake_edp_have_panel_power(intel_dp) || |
| 876 | ironlake_edp_have_panel_vdd(intel_dp)) |
| 877 | { |
| 878 | DRM_DEBUG_KMS("Panel still on, no delay needed\n"); |
| 879 | return; |
| 880 | } |
| 881 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 882 | off_time = intel_dp->panel_off_jiffies + msecs_to_jiffies(intel_dp->panel_power_down_delay); |
| 883 | if (time_after(jiffies, off_time)) { |
| 884 | DRM_DEBUG_KMS("Time already passed"); |
| 885 | return; |
| 886 | } |
| 887 | delay = jiffies_to_msecs(off_time - jiffies); |
| 888 | if (delay > intel_dp->panel_power_down_delay) |
| 889 | delay = intel_dp->panel_power_down_delay; |
| 890 | DRM_DEBUG_KMS("Waiting an additional %ld ms\n", delay); |
| 891 | msleep(delay); |
| 892 | } |
| 893 | |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 894 | static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp) |
| 895 | { |
| 896 | struct drm_device *dev = intel_dp->base.base.dev; |
| 897 | struct drm_i915_private *dev_priv = dev->dev_private; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 898 | u32 pp; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 899 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 900 | if (!is_edp(intel_dp)) |
| 901 | return; |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 902 | DRM_DEBUG_KMS("Turn eDP VDD on\n"); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 903 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 904 | WARN(intel_dp->want_panel_vdd, |
| 905 | "eDP VDD already requested on\n"); |
| 906 | |
| 907 | intel_dp->want_panel_vdd = true; |
| 908 | if (ironlake_edp_have_panel_vdd(intel_dp)) { |
| 909 | DRM_DEBUG_KMS("eDP VDD already on\n"); |
| 910 | return; |
| 911 | } |
| 912 | |
| 913 | ironlake_wait_panel_off(intel_dp); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 914 | pp = I915_READ(PCH_PP_CONTROL); |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 915 | pp &= ~PANEL_UNLOCK_MASK; |
| 916 | pp |= PANEL_UNLOCK_REGS; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 917 | pp |= EDP_FORCE_VDD; |
| 918 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 919 | POSTING_READ(PCH_PP_CONTROL); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 920 | DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n", |
| 921 | I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL)); |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 922 | |
| 923 | /* |
| 924 | * If the panel wasn't on, delay before accessing aux channel |
| 925 | */ |
| 926 | if (!ironlake_edp_have_panel_power(intel_dp)) { |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 927 | DRM_DEBUG_KMS("eDP was not running\n"); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 928 | msleep(intel_dp->panel_power_up_delay); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 929 | } |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 930 | } |
| 931 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 932 | static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp) |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 933 | { |
| 934 | struct drm_device *dev = intel_dp->base.base.dev; |
| 935 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 936 | u32 pp; |
| 937 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 938 | if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) { |
| 939 | pp = I915_READ(PCH_PP_CONTROL); |
| 940 | pp &= ~PANEL_UNLOCK_MASK; |
| 941 | pp |= PANEL_UNLOCK_REGS; |
| 942 | pp &= ~EDP_FORCE_VDD; |
| 943 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 944 | POSTING_READ(PCH_PP_CONTROL); |
| 945 | |
| 946 | /* Make sure sequencer is idle before allowing subsequent activity */ |
| 947 | DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n", |
| 948 | I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL)); |
| 949 | intel_dp->panel_off_jiffies = jiffies; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | static void ironlake_panel_vdd_work(struct work_struct *__work) |
| 954 | { |
| 955 | struct intel_dp *intel_dp = container_of(to_delayed_work(__work), |
| 956 | struct intel_dp, panel_vdd_work); |
| 957 | struct drm_device *dev = intel_dp->base.base.dev; |
| 958 | |
| 959 | mutex_lock(&dev->struct_mutex); |
| 960 | ironlake_panel_vdd_off_sync(intel_dp); |
| 961 | mutex_unlock(&dev->struct_mutex); |
| 962 | } |
| 963 | |
| 964 | static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync) |
| 965 | { |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 966 | if (!is_edp(intel_dp)) |
| 967 | return; |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 968 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 969 | DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd); |
| 970 | WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on"); |
| 971 | |
| 972 | intel_dp->want_panel_vdd = false; |
| 973 | |
| 974 | if (sync) { |
| 975 | ironlake_panel_vdd_off_sync(intel_dp); |
| 976 | } else { |
| 977 | /* |
| 978 | * Queue the timer to fire a long |
| 979 | * time from now (relative to the power down delay) |
| 980 | * to keep the panel power up across a sequence of operations |
| 981 | */ |
| 982 | schedule_delayed_work(&intel_dp->panel_vdd_work, |
| 983 | msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5)); |
| 984 | } |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 985 | } |
| 986 | |
Jesse Barnes | 7eaf554 | 2010-09-08 12:41:59 -0700 | [diff] [blame] | 987 | /* Returns true if the panel was already on when called */ |
Keith Packard | 7d639f3 | 2011-09-29 16:05:34 -0700 | [diff] [blame] | 988 | static void ironlake_edp_panel_on (struct intel_dp *intel_dp) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 989 | { |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 990 | struct drm_device *dev = intel_dp->base.base.dev; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 991 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 992 | u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 993 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 994 | if (!is_edp(intel_dp)) |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 995 | return; |
Keith Packard | ebf33b1 | 2011-09-29 15:53:27 -0700 | [diff] [blame] | 996 | if (ironlake_edp_have_panel_power(intel_dp)) |
Keith Packard | 7d639f3 | 2011-09-29 16:05:34 -0700 | [diff] [blame] | 997 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 998 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 999 | ironlake_wait_panel_off(intel_dp); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1000 | pp = I915_READ(PCH_PP_CONTROL); |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 1001 | pp &= ~PANEL_UNLOCK_MASK; |
| 1002 | pp |= PANEL_UNLOCK_REGS; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 1003 | |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 1004 | if (IS_GEN5(dev)) { |
| 1005 | /* ILK workaround: disable reset around power sequence */ |
| 1006 | pp &= ~PANEL_POWER_RESET; |
| 1007 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1008 | POSTING_READ(PCH_PP_CONTROL); |
| 1009 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 1010 | |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 1011 | pp |= POWER_TARGET_ON; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1012 | I915_WRITE(PCH_PP_CONTROL, pp); |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1013 | POSTING_READ(PCH_PP_CONTROL); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1014 | |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1015 | if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask, |
| 1016 | 5000)) |
Chris Wilson | 913d8d1 | 2010-08-07 11:01:35 +0100 | [diff] [blame] | 1017 | DRM_ERROR("panel on wait timed out: 0x%08x\n", |
| 1018 | I915_READ(PCH_PP_STATUS)); |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1019 | |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 1020 | if (IS_GEN5(dev)) { |
| 1021 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
| 1022 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1023 | POSTING_READ(PCH_PP_CONTROL); |
| 1024 | } |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1027 | static void ironlake_edp_panel_off(struct drm_encoder *encoder) |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1028 | { |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1029 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1030 | struct drm_device *dev = encoder->dev; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1031 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1032 | u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK | |
| 1033 | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1034 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1035 | if (!is_edp(intel_dp)) |
| 1036 | return; |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1037 | pp = I915_READ(PCH_PP_CONTROL); |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 1038 | pp &= ~PANEL_UNLOCK_MASK; |
| 1039 | pp |= PANEL_UNLOCK_REGS; |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 1040 | |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 1041 | if (IS_GEN5(dev)) { |
| 1042 | /* ILK workaround: disable reset around power sequence */ |
| 1043 | pp &= ~PANEL_POWER_RESET; |
| 1044 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1045 | POSTING_READ(PCH_PP_CONTROL); |
| 1046 | } |
Jesse Barnes | 37c6c9b | 2010-08-11 10:04:43 -0700 | [diff] [blame] | 1047 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1048 | intel_dp->panel_off_jiffies = jiffies; |
Keith Packard | 05ce1a4 | 2011-09-29 16:33:01 -0700 | [diff] [blame] | 1049 | |
| 1050 | if (IS_GEN5(dev)) { |
| 1051 | pp &= ~POWER_TARGET_ON; |
| 1052 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1053 | POSTING_READ(PCH_PP_CONTROL); |
| 1054 | pp &= ~POWER_TARGET_ON; |
| 1055 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1056 | POSTING_READ(PCH_PP_CONTROL); |
| 1057 | msleep(intel_dp->panel_power_cycle_delay); |
| 1058 | |
| 1059 | if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000)) |
| 1060 | DRM_ERROR("panel off wait timed out: 0x%08x\n", |
| 1061 | I915_READ(PCH_PP_STATUS)); |
| 1062 | |
| 1063 | pp |= PANEL_POWER_RESET; /* restore panel reset bit */ |
| 1064 | I915_WRITE(PCH_PP_CONTROL, pp); |
| 1065 | POSTING_READ(PCH_PP_CONTROL); |
| 1066 | } |
Jesse Barnes | 9934c13 | 2010-07-22 13:18:19 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1069 | static void ironlake_edp_backlight_on (struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1070 | { |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1071 | struct drm_device *dev = intel_dp->base.base.dev; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1072 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1073 | u32 pp; |
| 1074 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1075 | if (!is_edp(intel_dp)) |
| 1076 | return; |
| 1077 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1078 | DRM_DEBUG_KMS("\n"); |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1079 | /* |
| 1080 | * If we enable the backlight right away following a panel power |
| 1081 | * on, we may see slight flicker as the panel syncs with the eDP |
| 1082 | * link. So delay a bit to make sure the image is solid before |
| 1083 | * allowing it to appear. |
| 1084 | */ |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1085 | msleep(intel_dp->backlight_on_delay); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1086 | pp = I915_READ(PCH_PP_CONTROL); |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 1087 | pp &= ~PANEL_UNLOCK_MASK; |
| 1088 | pp |= PANEL_UNLOCK_REGS; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1089 | pp |= EDP_BLC_ENABLE; |
| 1090 | I915_WRITE(PCH_PP_CONTROL, pp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1091 | POSTING_READ(PCH_PP_CONTROL); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1094 | static void ironlake_edp_backlight_off (struct intel_dp *intel_dp) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1095 | { |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1096 | struct drm_device *dev = intel_dp->base.base.dev; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1097 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1098 | u32 pp; |
| 1099 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1100 | if (!is_edp(intel_dp)) |
| 1101 | return; |
| 1102 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1103 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1104 | pp = I915_READ(PCH_PP_CONTROL); |
Keith Packard | 1c0ae80 | 2011-09-19 13:59:29 -0700 | [diff] [blame] | 1105 | pp &= ~PANEL_UNLOCK_MASK; |
| 1106 | pp |= PANEL_UNLOCK_REGS; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1107 | pp &= ~EDP_BLC_ENABLE; |
| 1108 | I915_WRITE(PCH_PP_CONTROL, pp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1109 | POSTING_READ(PCH_PP_CONTROL); |
| 1110 | msleep(intel_dp->backlight_off_delay); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1111 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1112 | |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1113 | static void ironlake_edp_pll_on(struct drm_encoder *encoder) |
| 1114 | { |
| 1115 | struct drm_device *dev = encoder->dev; |
| 1116 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1117 | u32 dpa_ctl; |
| 1118 | |
| 1119 | DRM_DEBUG_KMS("\n"); |
| 1120 | dpa_ctl = I915_READ(DP_A); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 1121 | dpa_ctl |= DP_PLL_ENABLE; |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1122 | I915_WRITE(DP_A, dpa_ctl); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 1123 | POSTING_READ(DP_A); |
| 1124 | udelay(200); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static void ironlake_edp_pll_off(struct drm_encoder *encoder) |
| 1128 | { |
| 1129 | struct drm_device *dev = encoder->dev; |
| 1130 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1131 | u32 dpa_ctl; |
| 1132 | |
| 1133 | dpa_ctl = I915_READ(DP_A); |
Jesse Barnes | 298b0b3 | 2010-10-07 16:01:24 -0700 | [diff] [blame] | 1134 | dpa_ctl &= ~DP_PLL_ENABLE; |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1135 | I915_WRITE(DP_A, dpa_ctl); |
Chris Wilson | 1af5fa1 | 2010-09-08 21:07:28 +0100 | [diff] [blame] | 1136 | POSTING_READ(DP_A); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1137 | udelay(200); |
| 1138 | } |
| 1139 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1140 | /* If the sink supports it, try to set the power state appropriately */ |
| 1141 | static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode) |
| 1142 | { |
| 1143 | int ret, i; |
| 1144 | |
| 1145 | /* Should have a valid DPCD by this point */ |
| 1146 | if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) |
| 1147 | return; |
| 1148 | |
| 1149 | if (mode != DRM_MODE_DPMS_ON) { |
| 1150 | ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER, |
| 1151 | DP_SET_POWER_D3); |
| 1152 | if (ret != 1) |
| 1153 | DRM_DEBUG_DRIVER("failed to write sink power state\n"); |
| 1154 | } else { |
| 1155 | /* |
| 1156 | * When turning on, we need to retry for 1ms to give the sink |
| 1157 | * time to wake up. |
| 1158 | */ |
| 1159 | for (i = 0; i < 3; i++) { |
| 1160 | ret = intel_dp_aux_native_write_1(intel_dp, |
| 1161 | DP_SET_POWER, |
| 1162 | DP_SET_POWER_D0); |
| 1163 | if (ret == 1) |
| 1164 | break; |
| 1165 | msleep(1); |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1170 | static void intel_dp_prepare(struct drm_encoder *encoder) |
| 1171 | { |
| 1172 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1173 | |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1174 | /* Wake up the sink first */ |
Keith Packard | f58ff85 | 2011-09-28 16:44:14 -0700 | [diff] [blame] | 1175 | ironlake_edp_panel_vdd_on(intel_dp); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1176 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1177 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1178 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1179 | /* Make sure the panel is off before trying to |
| 1180 | * change the mode |
| 1181 | */ |
| 1182 | ironlake_edp_backlight_off(intel_dp); |
Jesse Barnes | 736085b | 2010-10-08 10:35:55 -0700 | [diff] [blame] | 1183 | intel_dp_link_down(intel_dp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1184 | ironlake_edp_panel_off(encoder); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static void intel_dp_commit(struct drm_encoder *encoder) |
| 1188 | { |
| 1189 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1190 | |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1191 | ironlake_edp_panel_vdd_on(intel_dp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1192 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1193 | intel_dp_start_link_train(intel_dp); |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1194 | ironlake_edp_panel_on(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1195 | ironlake_edp_panel_vdd_off(intel_dp, true); |
| 1196 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1197 | intel_dp_complete_link_train(intel_dp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1198 | ironlake_edp_backlight_on(intel_dp); |
Keith Packard | d2b996a | 2011-07-25 22:37:51 -0700 | [diff] [blame] | 1199 | |
| 1200 | intel_dp->dpms_mode = DRM_MODE_DPMS_ON; |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1203 | static void |
| 1204 | intel_dp_dpms(struct drm_encoder *encoder, int mode) |
| 1205 | { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1206 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 1207 | struct drm_device *dev = encoder->dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1208 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1209 | uint32_t dp_reg = I915_READ(intel_dp->output_reg); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1210 | |
| 1211 | if (mode != DRM_MODE_DPMS_ON) { |
Keith Packard | 245e270 | 2011-10-05 19:53:09 -0700 | [diff] [blame] | 1212 | ironlake_edp_panel_vdd_on(intel_dp); |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1213 | if (is_edp(intel_dp)) |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1214 | ironlake_edp_backlight_off(intel_dp); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1215 | intel_dp_sink_dpms(intel_dp, mode); |
Jesse Barnes | 736085b | 2010-10-08 10:35:55 -0700 | [diff] [blame] | 1216 | intel_dp_link_down(intel_dp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1217 | ironlake_edp_panel_off(encoder); |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1218 | if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 1219 | ironlake_edp_pll_off(encoder); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1220 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1221 | } else { |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1222 | ironlake_edp_panel_vdd_on(intel_dp); |
Jesse Barnes | c7ad381 | 2011-07-07 11:11:03 -0700 | [diff] [blame] | 1223 | intel_dp_sink_dpms(intel_dp, mode); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1224 | if (!(dp_reg & DP_PORT_EN)) { |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1225 | intel_dp_start_link_train(intel_dp); |
Keith Packard | 97af61f57 | 2011-09-28 16:23:51 -0700 | [diff] [blame] | 1226 | ironlake_edp_panel_on(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1227 | ironlake_edp_panel_vdd_off(intel_dp, true); |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1228 | intel_dp_complete_link_train(intel_dp); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1229 | ironlake_edp_backlight_on(intel_dp); |
Keith Packard | bee7eb2 | 2011-09-28 16:28:00 -0700 | [diff] [blame] | 1230 | } else |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1231 | ironlake_edp_panel_vdd_off(intel_dp, false); |
| 1232 | ironlake_edp_backlight_on(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1233 | } |
Keith Packard | d2b996a | 2011-07-25 22:37:51 -0700 | [diff] [blame] | 1234 | intel_dp->dpms_mode = mode; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | /* |
Jesse Barnes | df0c237 | 2011-07-07 11:11:02 -0700 | [diff] [blame] | 1238 | * Native read with retry for link status and receiver capability reads for |
| 1239 | * cases where the sink may still be asleep. |
| 1240 | */ |
| 1241 | static bool |
| 1242 | intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address, |
| 1243 | uint8_t *recv, int recv_bytes) |
| 1244 | { |
| 1245 | int ret, i; |
| 1246 | |
| 1247 | /* |
| 1248 | * Sinks are *supposed* to come up within 1ms from an off state, |
| 1249 | * but we're also supposed to retry 3 times per the spec. |
| 1250 | */ |
| 1251 | for (i = 0; i < 3; i++) { |
| 1252 | ret = intel_dp_aux_native_read(intel_dp, address, recv, |
| 1253 | recv_bytes); |
| 1254 | if (ret == recv_bytes) |
| 1255 | return true; |
| 1256 | msleep(1); |
| 1257 | } |
| 1258 | |
| 1259 | return false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | /* |
| 1263 | * Fetch AUX CH registers 0x202 - 0x207 which contain |
| 1264 | * link status information |
| 1265 | */ |
| 1266 | static bool |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1267 | intel_dp_get_link_status(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1268 | { |
Jesse Barnes | df0c237 | 2011-07-07 11:11:02 -0700 | [diff] [blame] | 1269 | return intel_dp_aux_native_read_retry(intel_dp, |
| 1270 | DP_LANE0_1_STATUS, |
| 1271 | intel_dp->link_status, |
| 1272 | DP_LINK_STATUS_SIZE); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | static uint8_t |
| 1276 | intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE], |
| 1277 | int r) |
| 1278 | { |
| 1279 | return link_status[r - DP_LANE0_1_STATUS]; |
| 1280 | } |
| 1281 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1282 | static uint8_t |
| 1283 | intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE], |
| 1284 | int lane) |
| 1285 | { |
| 1286 | int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1); |
| 1287 | int s = ((lane & 1) ? |
| 1288 | DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT : |
| 1289 | DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT); |
| 1290 | uint8_t l = intel_dp_link_status(link_status, i); |
| 1291 | |
| 1292 | return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT; |
| 1293 | } |
| 1294 | |
| 1295 | static uint8_t |
| 1296 | intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE], |
| 1297 | int lane) |
| 1298 | { |
| 1299 | int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1); |
| 1300 | int s = ((lane & 1) ? |
| 1301 | DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT : |
| 1302 | DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT); |
| 1303 | uint8_t l = intel_dp_link_status(link_status, i); |
| 1304 | |
| 1305 | return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT; |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | #if 0 |
| 1310 | static char *voltage_names[] = { |
| 1311 | "0.4V", "0.6V", "0.8V", "1.2V" |
| 1312 | }; |
| 1313 | static char *pre_emph_names[] = { |
| 1314 | "0dB", "3.5dB", "6dB", "9.5dB" |
| 1315 | }; |
| 1316 | static char *link_train_names[] = { |
| 1317 | "pattern 1", "pattern 2", "idle", "off" |
| 1318 | }; |
| 1319 | #endif |
| 1320 | |
| 1321 | /* |
| 1322 | * These are source-specific values; current Intel hardware supports |
| 1323 | * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB |
| 1324 | */ |
| 1325 | #define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800 |
| 1326 | |
| 1327 | static uint8_t |
| 1328 | intel_dp_pre_emphasis_max(uint8_t voltage_swing) |
| 1329 | { |
| 1330 | switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { |
| 1331 | case DP_TRAIN_VOLTAGE_SWING_400: |
| 1332 | return DP_TRAIN_PRE_EMPHASIS_6; |
| 1333 | case DP_TRAIN_VOLTAGE_SWING_600: |
| 1334 | return DP_TRAIN_PRE_EMPHASIS_6; |
| 1335 | case DP_TRAIN_VOLTAGE_SWING_800: |
| 1336 | return DP_TRAIN_PRE_EMPHASIS_3_5; |
| 1337 | case DP_TRAIN_VOLTAGE_SWING_1200: |
| 1338 | default: |
| 1339 | return DP_TRAIN_PRE_EMPHASIS_0; |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | static void |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1344 | intel_get_adjust_train(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1345 | { |
| 1346 | uint8_t v = 0; |
| 1347 | uint8_t p = 0; |
| 1348 | int lane; |
| 1349 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1350 | for (lane = 0; lane < intel_dp->lane_count; lane++) { |
| 1351 | uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane); |
| 1352 | uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1353 | |
| 1354 | if (this_v > v) |
| 1355 | v = this_v; |
| 1356 | if (this_p > p) |
| 1357 | p = this_p; |
| 1358 | } |
| 1359 | |
| 1360 | if (v >= I830_DP_VOLTAGE_MAX) |
| 1361 | v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED; |
| 1362 | |
| 1363 | if (p >= intel_dp_pre_emphasis_max(v)) |
| 1364 | p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED; |
| 1365 | |
| 1366 | for (lane = 0; lane < 4; lane++) |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1367 | intel_dp->train_set[lane] = v | p; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static uint32_t |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1371 | intel_dp_signal_levels(uint8_t train_set, int lane_count) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1372 | { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1373 | uint32_t signal_levels = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1374 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1375 | switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1376 | case DP_TRAIN_VOLTAGE_SWING_400: |
| 1377 | default: |
| 1378 | signal_levels |= DP_VOLTAGE_0_4; |
| 1379 | break; |
| 1380 | case DP_TRAIN_VOLTAGE_SWING_600: |
| 1381 | signal_levels |= DP_VOLTAGE_0_6; |
| 1382 | break; |
| 1383 | case DP_TRAIN_VOLTAGE_SWING_800: |
| 1384 | signal_levels |= DP_VOLTAGE_0_8; |
| 1385 | break; |
| 1386 | case DP_TRAIN_VOLTAGE_SWING_1200: |
| 1387 | signal_levels |= DP_VOLTAGE_1_2; |
| 1388 | break; |
| 1389 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1390 | switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1391 | case DP_TRAIN_PRE_EMPHASIS_0: |
| 1392 | default: |
| 1393 | signal_levels |= DP_PRE_EMPHASIS_0; |
| 1394 | break; |
| 1395 | case DP_TRAIN_PRE_EMPHASIS_3_5: |
| 1396 | signal_levels |= DP_PRE_EMPHASIS_3_5; |
| 1397 | break; |
| 1398 | case DP_TRAIN_PRE_EMPHASIS_6: |
| 1399 | signal_levels |= DP_PRE_EMPHASIS_6; |
| 1400 | break; |
| 1401 | case DP_TRAIN_PRE_EMPHASIS_9_5: |
| 1402 | signal_levels |= DP_PRE_EMPHASIS_9_5; |
| 1403 | break; |
| 1404 | } |
| 1405 | return signal_levels; |
| 1406 | } |
| 1407 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1408 | /* Gen6's DP voltage swing and pre-emphasis control */ |
| 1409 | static uint32_t |
| 1410 | intel_gen6_edp_signal_levels(uint8_t train_set) |
| 1411 | { |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1412 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 1413 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 1414 | switch (signal_levels) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1415 | case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1416 | case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0: |
| 1417 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
| 1418 | case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5: |
| 1419 | return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1420 | case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1421 | case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6: |
| 1422 | return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1423 | case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1424 | case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5: |
| 1425 | return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1426 | case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1427 | case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0: |
| 1428 | return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1429 | default: |
Yuanhan Liu | 3c5a62b | 2011-01-06 18:26:08 +0800 | [diff] [blame] | 1430 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:" |
| 1431 | "0x%x\n", signal_levels); |
| 1432 | return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1436 | static uint8_t |
| 1437 | intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE], |
| 1438 | int lane) |
| 1439 | { |
| 1440 | int i = DP_LANE0_1_STATUS + (lane >> 1); |
| 1441 | int s = (lane & 1) * 4; |
| 1442 | uint8_t l = intel_dp_link_status(link_status, i); |
| 1443 | |
| 1444 | return (l >> s) & 0xf; |
| 1445 | } |
| 1446 | |
| 1447 | /* Check for clock recovery is done on all channels */ |
| 1448 | static bool |
| 1449 | intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count) |
| 1450 | { |
| 1451 | int lane; |
| 1452 | uint8_t lane_status; |
| 1453 | |
| 1454 | for (lane = 0; lane < lane_count; lane++) { |
| 1455 | lane_status = intel_get_lane_status(link_status, lane); |
| 1456 | if ((lane_status & DP_LANE_CR_DONE) == 0) |
| 1457 | return false; |
| 1458 | } |
| 1459 | return true; |
| 1460 | } |
| 1461 | |
| 1462 | /* Check to see if channel eq is done on all channels */ |
| 1463 | #define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\ |
| 1464 | DP_LANE_CHANNEL_EQ_DONE|\ |
| 1465 | DP_LANE_SYMBOL_LOCKED) |
| 1466 | static bool |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1467 | intel_channel_eq_ok(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1468 | { |
| 1469 | uint8_t lane_align; |
| 1470 | uint8_t lane_status; |
| 1471 | int lane; |
| 1472 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1473 | lane_align = intel_dp_link_status(intel_dp->link_status, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1474 | DP_LANE_ALIGN_STATUS_UPDATED); |
| 1475 | if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0) |
| 1476 | return false; |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1477 | for (lane = 0; lane < intel_dp->lane_count; lane++) { |
| 1478 | lane_status = intel_get_lane_status(intel_dp->link_status, lane); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1479 | if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS) |
| 1480 | return false; |
| 1481 | } |
| 1482 | return true; |
| 1483 | } |
| 1484 | |
| 1485 | static bool |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1486 | intel_dp_set_link_train(struct intel_dp *intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1487 | uint32_t dp_reg_value, |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1488 | uint8_t dp_train_pat) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1489 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1490 | struct drm_device *dev = intel_dp->base.base.dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1491 | struct drm_i915_private *dev_priv = dev->dev_private; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1492 | int ret; |
| 1493 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1494 | I915_WRITE(intel_dp->output_reg, dp_reg_value); |
| 1495 | POSTING_READ(intel_dp->output_reg); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1496 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1497 | intel_dp_aux_native_write_1(intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1498 | DP_TRAINING_PATTERN_SET, |
| 1499 | dp_train_pat); |
| 1500 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1501 | ret = intel_dp_aux_native_write(intel_dp, |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1502 | DP_TRAINING_LANE0_SET, |
| 1503 | intel_dp->train_set, 4); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1504 | if (ret != 4) |
| 1505 | return false; |
| 1506 | |
| 1507 | return true; |
| 1508 | } |
| 1509 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1510 | /* Enable corresponding port and start training pattern 1 */ |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1511 | static void |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1512 | intel_dp_start_link_train(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1513 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1514 | struct drm_device *dev = intel_dp->base.base.dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1515 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1516 | struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1517 | int i; |
| 1518 | uint8_t voltage; |
| 1519 | bool clock_recovery = false; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1520 | int tries; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1521 | u32 reg; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1522 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1523 | |
Adam Jackson | e851946 | 2011-07-21 17:48:38 -0400 | [diff] [blame] | 1524 | /* |
| 1525 | * On CPT we have to enable the port in training pattern 1, which |
| 1526 | * will happen below in intel_dp_set_link_train. Otherwise, enable |
| 1527 | * the port and wait for it to become active. |
| 1528 | */ |
| 1529 | if (!HAS_PCH_CPT(dev)) { |
| 1530 | I915_WRITE(intel_dp->output_reg, intel_dp->DP); |
| 1531 | POSTING_READ(intel_dp->output_reg); |
| 1532 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 1533 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1534 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1535 | /* Write the link configuration data */ |
| 1536 | intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, |
| 1537 | intel_dp->link_configuration, |
| 1538 | DP_LINK_CONFIGURATION_SIZE); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1539 | |
| 1540 | DP |= DP_PORT_EN; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1541 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1542 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
| 1543 | else |
| 1544 | DP &= ~DP_LINK_TRAIN_MASK; |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1545 | memset(intel_dp->train_set, 0, 4); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1546 | voltage = 0xff; |
| 1547 | tries = 0; |
| 1548 | clock_recovery = false; |
| 1549 | for (;;) { |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1550 | /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1551 | uint32_t signal_levels; |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1552 | if (IS_GEN6(dev) && is_edp(intel_dp)) { |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1553 | signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1554 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; |
| 1555 | } else { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1556 | signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1557 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; |
| 1558 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1559 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1560 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1561 | reg = DP | DP_LINK_TRAIN_PAT_1_CPT; |
| 1562 | else |
| 1563 | reg = DP | DP_LINK_TRAIN_PAT_1; |
| 1564 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1565 | if (!intel_dp_set_link_train(intel_dp, reg, |
Adam Jackson | 8105585 | 2011-07-21 17:48:37 -0400 | [diff] [blame] | 1566 | DP_TRAINING_PATTERN_1 | |
| 1567 | DP_LINK_SCRAMBLING_DISABLE)) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1568 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1569 | /* Set training pattern 1 */ |
| 1570 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1571 | udelay(100); |
| 1572 | if (!intel_dp_get_link_status(intel_dp)) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1573 | break; |
| 1574 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1575 | if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) { |
| 1576 | clock_recovery = true; |
| 1577 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1578 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1579 | |
| 1580 | /* Check to see if we've tried the max voltage */ |
| 1581 | for (i = 0; i < intel_dp->lane_count; i++) |
| 1582 | if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) |
| 1583 | break; |
| 1584 | if (i == intel_dp->lane_count) |
| 1585 | break; |
| 1586 | |
| 1587 | /* Check to see if we've tried the same voltage 5 times */ |
| 1588 | if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) { |
| 1589 | ++tries; |
| 1590 | if (tries == 5) |
| 1591 | break; |
| 1592 | } else |
| 1593 | tries = 0; |
| 1594 | voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; |
| 1595 | |
| 1596 | /* Compute new intel_dp->train_set as requested by target */ |
| 1597 | intel_get_adjust_train(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1600 | intel_dp->DP = DP; |
| 1601 | } |
| 1602 | |
| 1603 | static void |
| 1604 | intel_dp_complete_link_train(struct intel_dp *intel_dp) |
| 1605 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1606 | struct drm_device *dev = intel_dp->base.base.dev; |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1607 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1608 | bool channel_eq = false; |
Jesse Barnes | 37f8097 | 2011-01-05 14:45:24 -0800 | [diff] [blame] | 1609 | int tries, cr_tries; |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1610 | u32 reg; |
| 1611 | uint32_t DP = intel_dp->DP; |
| 1612 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1613 | /* channel equalization */ |
| 1614 | tries = 0; |
Jesse Barnes | 37f8097 | 2011-01-05 14:45:24 -0800 | [diff] [blame] | 1615 | cr_tries = 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1616 | channel_eq = false; |
| 1617 | for (;;) { |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1618 | /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1619 | uint32_t signal_levels; |
| 1620 | |
Jesse Barnes | 37f8097 | 2011-01-05 14:45:24 -0800 | [diff] [blame] | 1621 | if (cr_tries > 5) { |
| 1622 | DRM_ERROR("failed to train DP, aborting\n"); |
| 1623 | intel_dp_link_down(intel_dp); |
| 1624 | break; |
| 1625 | } |
| 1626 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1627 | if (IS_GEN6(dev) && is_edp(intel_dp)) { |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1628 | signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1629 | DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; |
| 1630 | } else { |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1631 | signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1632 | DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; |
| 1633 | } |
| 1634 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1635 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1636 | reg = DP | DP_LINK_TRAIN_PAT_2_CPT; |
| 1637 | else |
| 1638 | reg = DP | DP_LINK_TRAIN_PAT_2; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1639 | |
| 1640 | /* channel eq pattern */ |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1641 | if (!intel_dp_set_link_train(intel_dp, reg, |
Adam Jackson | 8105585 | 2011-07-21 17:48:37 -0400 | [diff] [blame] | 1642 | DP_TRAINING_PATTERN_2 | |
| 1643 | DP_LINK_SCRAMBLING_DISABLE)) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1644 | break; |
| 1645 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1646 | udelay(400); |
| 1647 | if (!intel_dp_get_link_status(intel_dp)) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1648 | break; |
Jesse Barnes | 869184a | 2010-10-07 16:01:22 -0700 | [diff] [blame] | 1649 | |
Jesse Barnes | 37f8097 | 2011-01-05 14:45:24 -0800 | [diff] [blame] | 1650 | /* Make sure clock is still ok */ |
| 1651 | if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) { |
| 1652 | intel_dp_start_link_train(intel_dp); |
| 1653 | cr_tries++; |
| 1654 | continue; |
| 1655 | } |
| 1656 | |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1657 | if (intel_channel_eq_ok(intel_dp)) { |
| 1658 | channel_eq = true; |
| 1659 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1660 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1661 | |
Jesse Barnes | 37f8097 | 2011-01-05 14:45:24 -0800 | [diff] [blame] | 1662 | /* Try 5 times, then try clock recovery if that fails */ |
| 1663 | if (tries > 5) { |
| 1664 | intel_dp_link_down(intel_dp); |
| 1665 | intel_dp_start_link_train(intel_dp); |
| 1666 | tries = 0; |
| 1667 | cr_tries++; |
| 1668 | continue; |
| 1669 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1670 | |
| 1671 | /* Compute new intel_dp->train_set as requested by target */ |
| 1672 | intel_get_adjust_train(intel_dp); |
| 1673 | ++tries; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1674 | } |
Chris Wilson | 3cf2efb | 2010-11-29 10:09:55 +0000 | [diff] [blame] | 1675 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1676 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1677 | reg = DP | DP_LINK_TRAIN_OFF_CPT; |
| 1678 | else |
| 1679 | reg = DP | DP_LINK_TRAIN_OFF; |
| 1680 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1681 | I915_WRITE(intel_dp->output_reg, reg); |
| 1682 | POSTING_READ(intel_dp->output_reg); |
| 1683 | intel_dp_aux_native_write_1(intel_dp, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1684 | DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE); |
| 1685 | } |
| 1686 | |
| 1687 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1688 | intel_dp_link_down(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1689 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1690 | struct drm_device *dev = intel_dp->base.base.dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1691 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1692 | uint32_t DP = intel_dp->DP; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1693 | |
Chris Wilson | 1b39d6f | 2010-12-06 11:20:45 +0000 | [diff] [blame] | 1694 | if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0) |
| 1695 | return; |
| 1696 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1697 | DRM_DEBUG_KMS("\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1698 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1699 | if (is_edp(intel_dp)) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1700 | DP &= ~DP_PLL_ENABLE; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1701 | I915_WRITE(intel_dp->output_reg, DP); |
| 1702 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1703 | udelay(100); |
| 1704 | } |
| 1705 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1706 | if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) { |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1707 | DP &= ~DP_LINK_TRAIN_MASK_CPT; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1708 | I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1709 | } else { |
| 1710 | DP &= ~DP_LINK_TRAIN_MASK; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1711 | I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE); |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 1712 | } |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 1713 | POSTING_READ(intel_dp->output_reg); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1714 | |
Chris Wilson | fe255d0 | 2010-09-11 21:37:48 +0100 | [diff] [blame] | 1715 | msleep(17); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1716 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 1717 | if (is_edp(intel_dp)) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1718 | DP |= DP_LINK_TRAIN_OFF; |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 1719 | |
Chris Wilson | 1b39d6f | 2010-12-06 11:20:45 +0000 | [diff] [blame] | 1720 | if (!HAS_PCH_CPT(dev) && |
| 1721 | I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) { |
Chris Wilson | 31acbcc | 2011-04-17 06:38:35 +0100 | [diff] [blame] | 1722 | struct drm_crtc *crtc = intel_dp->base.base.crtc; |
| 1723 | |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 1724 | /* Hardware workaround: leaving our transcoder select |
| 1725 | * set to transcoder B while it's off will prevent the |
| 1726 | * corresponding HDMI output on transcoder A. |
| 1727 | * |
| 1728 | * Combine this with another hardware workaround: |
| 1729 | * transcoder select bit can only be cleared while the |
| 1730 | * port is enabled. |
| 1731 | */ |
| 1732 | DP &= ~DP_PIPEB_SELECT; |
| 1733 | I915_WRITE(intel_dp->output_reg, DP); |
| 1734 | |
| 1735 | /* Changes to enable or select take place the vblank |
| 1736 | * after being written. |
| 1737 | */ |
Chris Wilson | 31acbcc | 2011-04-17 06:38:35 +0100 | [diff] [blame] | 1738 | if (crtc == NULL) { |
| 1739 | /* We can arrive here never having been attached |
| 1740 | * to a CRTC, for instance, due to inheriting |
| 1741 | * random state from the BIOS. |
| 1742 | * |
| 1743 | * If the pipe is not running, play safe and |
| 1744 | * wait for the clocks to stabilise before |
| 1745 | * continuing. |
| 1746 | */ |
| 1747 | POSTING_READ(intel_dp->output_reg); |
| 1748 | msleep(50); |
| 1749 | } else |
| 1750 | intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe); |
Eric Anholt | 5bddd17 | 2010-11-18 09:32:59 +0800 | [diff] [blame] | 1751 | } |
| 1752 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1753 | I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); |
| 1754 | POSTING_READ(intel_dp->output_reg); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 1755 | msleep(intel_dp->panel_power_down_delay); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1758 | static bool |
| 1759 | intel_dp_get_dpcd(struct intel_dp *intel_dp) |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1760 | { |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1761 | if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd, |
| 1762 | sizeof (intel_dp->dpcd)) && |
| 1763 | (intel_dp->dpcd[DP_DPCD_REV] != 0)) { |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1764 | return true; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1767 | return false; |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1770 | /* |
| 1771 | * According to DP spec |
| 1772 | * 5.1.2: |
| 1773 | * 1. Read DPCD |
| 1774 | * 2. Configure link according to Receiver Capabilities |
| 1775 | * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 |
| 1776 | * 4. Check link status on receipt of hot-plug interrupt |
| 1777 | */ |
| 1778 | |
| 1779 | static void |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1780 | intel_dp_check_link_status(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1781 | { |
Keith Packard | d2b996a | 2011-07-25 22:37:51 -0700 | [diff] [blame] | 1782 | if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON) |
| 1783 | return; |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 1784 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1785 | if (!intel_dp->base.base.crtc) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1786 | return; |
| 1787 | |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1788 | /* Try to read receiver status if the link appears to be up */ |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1789 | if (!intel_dp_get_link_status(intel_dp)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1790 | intel_dp_link_down(intel_dp); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1791 | return; |
| 1792 | } |
| 1793 | |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1794 | /* Now read the DPCD to see if it's actually running */ |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1795 | if (!intel_dp_get_dpcd(intel_dp)) { |
Jesse Barnes | 59cd09e | 2011-07-07 11:10:59 -0700 | [diff] [blame] | 1796 | intel_dp_link_down(intel_dp); |
| 1797 | return; |
| 1798 | } |
| 1799 | |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1800 | if (!intel_channel_eq_ok(intel_dp)) { |
Keith Packard | 92fd8fd | 2011-07-25 19:50:10 -0700 | [diff] [blame] | 1801 | DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", |
| 1802 | drm_get_encoder_name(&intel_dp->base.base)); |
Jesse Barnes | 33a34e4 | 2010-09-08 12:42:02 -0700 | [diff] [blame] | 1803 | intel_dp_start_link_train(intel_dp); |
| 1804 | intel_dp_complete_link_train(intel_dp); |
| 1805 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1806 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1807 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1808 | static enum drm_connector_status |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1809 | intel_dp_detect_dpcd(struct intel_dp *intel_dp) |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 1810 | { |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1811 | if (intel_dp_get_dpcd(intel_dp)) |
| 1812 | return connector_status_connected; |
| 1813 | return connector_status_disconnected; |
Adam Jackson | 71ba9000 | 2011-07-12 17:38:04 -0400 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static enum drm_connector_status |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1817 | ironlake_dp_detect(struct intel_dp *intel_dp) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1818 | { |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1819 | enum drm_connector_status status; |
| 1820 | |
Chris Wilson | fe16d94 | 2011-02-12 10:29:38 +0000 | [diff] [blame] | 1821 | /* Can't disconnect eDP, but you can close the lid... */ |
| 1822 | if (is_edp(intel_dp)) { |
| 1823 | status = intel_panel_detect(intel_dp->base.base.dev); |
| 1824 | if (status == connector_status_unknown) |
| 1825 | status = connector_status_connected; |
| 1826 | return status; |
| 1827 | } |
Jesse Barnes | 01cb9ea | 2010-10-07 16:01:12 -0700 | [diff] [blame] | 1828 | |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1829 | return intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1830 | } |
| 1831 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1832 | static enum drm_connector_status |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1833 | g4x_dp_detect(struct intel_dp *intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1834 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1835 | struct drm_device *dev = intel_dp->base.base.dev; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1836 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1837 | uint32_t temp, bit; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 1838 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1839 | switch (intel_dp->output_reg) { |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1840 | case DP_B: |
| 1841 | bit = DPB_HOTPLUG_INT_STATUS; |
| 1842 | break; |
| 1843 | case DP_C: |
| 1844 | bit = DPC_HOTPLUG_INT_STATUS; |
| 1845 | break; |
| 1846 | case DP_D: |
| 1847 | bit = DPD_HOTPLUG_INT_STATUS; |
| 1848 | break; |
| 1849 | default: |
| 1850 | return connector_status_unknown; |
| 1851 | } |
| 1852 | |
| 1853 | temp = I915_READ(PORT_HOTPLUG_STAT); |
| 1854 | |
| 1855 | if ((temp & bit) == 0) |
| 1856 | return connector_status_disconnected; |
| 1857 | |
Keith Packard | 26d61aa | 2011-07-25 20:01:09 -0700 | [diff] [blame] | 1858 | return intel_dp_detect_dpcd(intel_dp); |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1859 | } |
| 1860 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1861 | static struct edid * |
| 1862 | intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) |
| 1863 | { |
| 1864 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 1865 | struct edid *edid; |
| 1866 | |
| 1867 | ironlake_edp_panel_vdd_on(intel_dp); |
| 1868 | edid = drm_get_edid(connector, adapter); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1869 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1870 | return edid; |
| 1871 | } |
| 1872 | |
| 1873 | static int |
| 1874 | intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter) |
| 1875 | { |
| 1876 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 1877 | int ret; |
| 1878 | |
| 1879 | ironlake_edp_panel_vdd_on(intel_dp); |
| 1880 | ret = intel_ddc_get_modes(connector, adapter); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 1881 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1882 | return ret; |
| 1883 | } |
| 1884 | |
| 1885 | |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1886 | /** |
| 1887 | * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection. |
| 1888 | * |
| 1889 | * \return true if DP port is connected. |
| 1890 | * \return false if DP port is disconnected. |
| 1891 | */ |
| 1892 | static enum drm_connector_status |
| 1893 | intel_dp_detect(struct drm_connector *connector, bool force) |
| 1894 | { |
| 1895 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 1896 | struct drm_device *dev = intel_dp->base.base.dev; |
| 1897 | enum drm_connector_status status; |
| 1898 | struct edid *edid = NULL; |
| 1899 | |
| 1900 | intel_dp->has_audio = false; |
| 1901 | |
| 1902 | if (HAS_PCH_SPLIT(dev)) |
| 1903 | status = ironlake_dp_detect(intel_dp); |
| 1904 | else |
| 1905 | status = g4x_dp_detect(intel_dp); |
Adam Jackson | 1b9be9d | 2011-07-12 17:38:01 -0400 | [diff] [blame] | 1906 | |
Adam Jackson | ac66ae8 | 2011-07-12 17:38:03 -0400 | [diff] [blame] | 1907 | DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n", |
| 1908 | intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2], |
| 1909 | intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5], |
| 1910 | intel_dp->dpcd[6], intel_dp->dpcd[7]); |
Adam Jackson | 1b9be9d | 2011-07-12 17:38:01 -0400 | [diff] [blame] | 1911 | |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1912 | if (status != connector_status_connected) |
| 1913 | return status; |
| 1914 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 1915 | if (intel_dp->force_audio) { |
| 1916 | intel_dp->has_audio = intel_dp->force_audio > 0; |
| 1917 | } else { |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1918 | edid = intel_dp_get_edid(connector, &intel_dp->adapter); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 1919 | if (edid) { |
| 1920 | intel_dp->has_audio = drm_detect_monitor_audio(edid); |
| 1921 | connector->display_info.raw_edid = NULL; |
| 1922 | kfree(edid); |
| 1923 | } |
Zhenyu Wang | a9756bb | 2010-09-19 13:09:06 +0800 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | return connector_status_connected; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | static int intel_dp_get_modes(struct drm_connector *connector) |
| 1930 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 1931 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 1932 | struct drm_device *dev = intel_dp->base.base.dev; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1933 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1934 | int ret; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1935 | |
| 1936 | /* We should parse the EDID data and find out if it has an audio sink |
| 1937 | */ |
| 1938 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1939 | ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter); |
Zhao Yakui | b9efc48 | 2010-07-19 09:43:11 +0100 | [diff] [blame] | 1940 | if (ret) { |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1941 | if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) { |
Zhao Yakui | b9efc48 | 2010-07-19 09:43:11 +0100 | [diff] [blame] | 1942 | struct drm_display_mode *newmode; |
| 1943 | list_for_each_entry(newmode, &connector->probed_modes, |
| 1944 | head) { |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1945 | if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) { |
| 1946 | intel_dp->panel_fixed_mode = |
Zhao Yakui | b9efc48 | 2010-07-19 09:43:11 +0100 | [diff] [blame] | 1947 | drm_mode_duplicate(dev, newmode); |
| 1948 | break; |
| 1949 | } |
| 1950 | } |
| 1951 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1952 | return ret; |
Zhao Yakui | b9efc48 | 2010-07-19 09:43:11 +0100 | [diff] [blame] | 1953 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1954 | |
| 1955 | /* if eDP has no EDID, try to use fixed panel mode from VBT */ |
Jesse Barnes | 4d92646 | 2010-10-07 16:01:07 -0700 | [diff] [blame] | 1956 | if (is_edp(intel_dp)) { |
Keith Packard | 47f0eb2 | 2011-09-19 14:33:26 -0700 | [diff] [blame] | 1957 | /* initialize panel mode from VBT if available for eDP */ |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1958 | if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) { |
| 1959 | intel_dp->panel_fixed_mode = |
Keith Packard | 47f0eb2 | 2011-09-19 14:33:26 -0700 | [diff] [blame] | 1960 | drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode); |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1961 | if (intel_dp->panel_fixed_mode) { |
| 1962 | intel_dp->panel_fixed_mode->type |= |
Keith Packard | 47f0eb2 | 2011-09-19 14:33:26 -0700 | [diff] [blame] | 1963 | DRM_MODE_TYPE_PREFERRED; |
| 1964 | } |
| 1965 | } |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1966 | if (intel_dp->panel_fixed_mode) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1967 | struct drm_display_mode *mode; |
Keith Packard | d15456d | 2011-09-18 17:35:47 -0700 | [diff] [blame] | 1968 | mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1969 | drm_mode_probed_add(connector, mode); |
| 1970 | return 1; |
| 1971 | } |
| 1972 | } |
| 1973 | return 0; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 1976 | static bool |
| 1977 | intel_dp_detect_audio(struct drm_connector *connector) |
| 1978 | { |
| 1979 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 1980 | struct edid *edid; |
| 1981 | bool has_audio = false; |
| 1982 | |
Keith Packard | 8c241fe | 2011-09-28 16:38:44 -0700 | [diff] [blame] | 1983 | edid = intel_dp_get_edid(connector, &intel_dp->adapter); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 1984 | if (edid) { |
| 1985 | has_audio = drm_detect_monitor_audio(edid); |
| 1986 | |
| 1987 | connector->display_info.raw_edid = NULL; |
| 1988 | kfree(edid); |
| 1989 | } |
| 1990 | |
| 1991 | return has_audio; |
| 1992 | } |
| 1993 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 1994 | static int |
| 1995 | intel_dp_set_property(struct drm_connector *connector, |
| 1996 | struct drm_property *property, |
| 1997 | uint64_t val) |
| 1998 | { |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 1999 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2000 | struct intel_dp *intel_dp = intel_attached_dp(connector); |
| 2001 | int ret; |
| 2002 | |
| 2003 | ret = drm_connector_property_set_value(connector, property, val); |
| 2004 | if (ret) |
| 2005 | return ret; |
| 2006 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 2007 | if (property == dev_priv->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 2008 | int i = val; |
| 2009 | bool has_audio; |
| 2010 | |
| 2011 | if (i == intel_dp->force_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2012 | return 0; |
| 2013 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 2014 | intel_dp->force_audio = i; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2015 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 2016 | if (i == 0) |
| 2017 | has_audio = intel_dp_detect_audio(connector); |
| 2018 | else |
| 2019 | has_audio = i > 0; |
| 2020 | |
| 2021 | if (has_audio == intel_dp->has_audio) |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2022 | return 0; |
| 2023 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 2024 | intel_dp->has_audio = has_audio; |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2025 | goto done; |
| 2026 | } |
| 2027 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 2028 | if (property == dev_priv->broadcast_rgb_property) { |
| 2029 | if (val == !!intel_dp->color_range) |
| 2030 | return 0; |
| 2031 | |
| 2032 | intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0; |
| 2033 | goto done; |
| 2034 | } |
| 2035 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2036 | return -EINVAL; |
| 2037 | |
| 2038 | done: |
| 2039 | if (intel_dp->base.base.crtc) { |
| 2040 | struct drm_crtc *crtc = intel_dp->base.base.crtc; |
| 2041 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 2042 | crtc->x, crtc->y, |
| 2043 | crtc->fb); |
| 2044 | } |
| 2045 | |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2049 | static void |
| 2050 | intel_dp_destroy (struct drm_connector *connector) |
| 2051 | { |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 2052 | struct drm_device *dev = connector->dev; |
| 2053 | |
| 2054 | if (intel_dpd_is_edp(dev)) |
| 2055 | intel_panel_destroy_backlight(dev); |
| 2056 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2057 | drm_sysfs_connector_remove(connector); |
| 2058 | drm_connector_cleanup(connector); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2059 | kfree(connector); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 2062 | static void intel_dp_encoder_destroy(struct drm_encoder *encoder) |
| 2063 | { |
| 2064 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 2065 | |
| 2066 | i2c_del_adapter(&intel_dp->adapter); |
| 2067 | drm_encoder_cleanup(encoder); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2068 | if (is_edp(intel_dp)) { |
| 2069 | cancel_delayed_work_sync(&intel_dp->panel_vdd_work); |
| 2070 | ironlake_panel_vdd_off_sync(intel_dp); |
| 2071 | } |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 2072 | kfree(intel_dp); |
| 2073 | } |
| 2074 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2075 | static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { |
| 2076 | .dpms = intel_dp_dpms, |
| 2077 | .mode_fixup = intel_dp_mode_fixup, |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2078 | .prepare = intel_dp_prepare, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2079 | .mode_set = intel_dp_mode_set, |
Jesse Barnes | d240f20 | 2010-08-13 15:43:26 -0700 | [diff] [blame] | 2080 | .commit = intel_dp_commit, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2081 | }; |
| 2082 | |
| 2083 | static const struct drm_connector_funcs intel_dp_connector_funcs = { |
| 2084 | .dpms = drm_helper_connector_dpms, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2085 | .detect = intel_dp_detect, |
| 2086 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2087 | .set_property = intel_dp_set_property, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2088 | .destroy = intel_dp_destroy, |
| 2089 | }; |
| 2090 | |
| 2091 | static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { |
| 2092 | .get_modes = intel_dp_get_modes, |
| 2093 | .mode_valid = intel_dp_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 2094 | .best_encoder = intel_best_encoder, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2095 | }; |
| 2096 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2097 | static const struct drm_encoder_funcs intel_dp_enc_funcs = { |
Daniel Vetter | 24d0592 | 2010-08-20 18:08:28 +0200 | [diff] [blame] | 2098 | .destroy = intel_dp_encoder_destroy, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2099 | }; |
| 2100 | |
Chris Wilson | 995b676 | 2010-08-20 13:23:26 +0100 | [diff] [blame] | 2101 | static void |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2102 | intel_dp_hot_plug(struct intel_encoder *intel_encoder) |
Keith Packard | c8110e5 | 2009-05-06 11:51:10 -0700 | [diff] [blame] | 2103 | { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2104 | struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base); |
Keith Packard | c8110e5 | 2009-05-06 11:51:10 -0700 | [diff] [blame] | 2105 | |
Jesse Barnes | 885a501 | 2011-07-07 11:11:01 -0700 | [diff] [blame] | 2106 | intel_dp_check_link_status(intel_dp); |
Keith Packard | c8110e5 | 2009-05-06 11:51:10 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 2109 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 2110 | int |
| 2111 | intel_trans_dp_port_sel (struct drm_crtc *crtc) |
| 2112 | { |
| 2113 | struct drm_device *dev = crtc->dev; |
| 2114 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 2115 | struct drm_encoder *encoder; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 2116 | |
| 2117 | list_for_each_entry(encoder, &mode_config->encoder_list, head) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2118 | struct intel_dp *intel_dp; |
| 2119 | |
Dan Carpenter | d8201ab | 2010-05-07 10:39:00 +0200 | [diff] [blame] | 2120 | if (encoder->crtc != crtc) |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 2121 | continue; |
| 2122 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2123 | intel_dp = enc_to_intel_dp(encoder); |
| 2124 | if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) |
| 2125 | return intel_dp->output_reg; |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 2126 | } |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2127 | |
Zhenyu Wang | e3421a1 | 2010-04-08 09:43:27 +0800 | [diff] [blame] | 2128 | return -1; |
| 2129 | } |
| 2130 | |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 2131 | /* check the VBT to see whether the eDP is on DP-D port */ |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 2132 | bool intel_dpd_is_edp(struct drm_device *dev) |
Zhao Yakui | 36e83a1 | 2010-06-12 14:32:21 +0800 | [diff] [blame] | 2133 | { |
| 2134 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2135 | struct child_device_config *p_child; |
| 2136 | int i; |
| 2137 | |
| 2138 | if (!dev_priv->child_dev_num) |
| 2139 | return false; |
| 2140 | |
| 2141 | for (i = 0; i < dev_priv->child_dev_num; i++) { |
| 2142 | p_child = dev_priv->child_dev + i; |
| 2143 | |
| 2144 | if (p_child->dvo_port == PORT_IDPD && |
| 2145 | p_child->device_type == DEVICE_TYPE_eDP) |
| 2146 | return true; |
| 2147 | } |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2151 | static void |
| 2152 | intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector) |
| 2153 | { |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 2154 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 2155 | intel_attach_broadcast_rgb_property(connector); |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Keith Packard | c8110e5 | 2009-05-06 11:51:10 -0700 | [diff] [blame] | 2158 | void |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2159 | intel_dp_init(struct drm_device *dev, int output_reg) |
| 2160 | { |
| 2161 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2162 | struct drm_connector *connector; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2163 | struct intel_dp *intel_dp; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2164 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2165 | struct intel_connector *intel_connector; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2166 | const char *name = NULL; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 2167 | int type; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2168 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2169 | intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL); |
| 2170 | if (!intel_dp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2171 | return; |
| 2172 | |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 2173 | intel_dp->output_reg = output_reg; |
Keith Packard | d2b996a | 2011-07-25 22:37:51 -0700 | [diff] [blame] | 2174 | intel_dp->dpms_mode = -1; |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 2175 | |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2176 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 2177 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2178 | kfree(intel_dp); |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2179 | return; |
| 2180 | } |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2181 | intel_encoder = &intel_dp->base; |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2182 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2183 | if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D) |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 2184 | if (intel_dpd_is_edp(dev)) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 2185 | intel_dp->is_pch_edp = true; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 2186 | |
Jesse Barnes | cfcb0fc | 2010-10-07 16:01:06 -0700 | [diff] [blame] | 2187 | if (output_reg == DP_A || is_pch_edp(intel_dp)) { |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 2188 | type = DRM_MODE_CONNECTOR_eDP; |
| 2189 | intel_encoder->type = INTEL_OUTPUT_EDP; |
| 2190 | } else { |
| 2191 | type = DRM_MODE_CONNECTOR_DisplayPort; |
| 2192 | intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; |
| 2193 | } |
| 2194 | |
Zhenyu Wang | 55f78c4 | 2010-03-29 16:13:57 +0800 | [diff] [blame] | 2195 | connector = &intel_connector->base; |
Adam Jackson | b329530 | 2010-07-16 14:46:28 -0400 | [diff] [blame] | 2196 | drm_connector_init(dev, connector, &intel_dp_connector_funcs, type); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2197 | drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); |
| 2198 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2199 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 2200 | |
Zhao Yakui | 652af9d | 2009-12-02 10:03:33 +0800 | [diff] [blame] | 2201 | if (output_reg == DP_B || output_reg == PCH_DP_B) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2202 | intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT); |
Zhao Yakui | 652af9d | 2009-12-02 10:03:33 +0800 | [diff] [blame] | 2203 | else if (output_reg == DP_C || output_reg == PCH_DP_C) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2204 | intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT); |
Zhao Yakui | 652af9d | 2009-12-02 10:03:33 +0800 | [diff] [blame] | 2205 | else if (output_reg == DP_D || output_reg == PCH_DP_D) |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2206 | intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 2207 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2208 | if (is_edp(intel_dp)) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2209 | intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2210 | INIT_DELAYED_WORK(&intel_dp->panel_vdd_work, |
| 2211 | ironlake_panel_vdd_work); |
| 2212 | } |
Zhenyu Wang | 6251ec0 | 2010-01-12 05:38:32 +0800 | [diff] [blame] | 2213 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2214 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2215 | connector->interlace_allowed = true; |
| 2216 | connector->doublescan_allowed = 0; |
| 2217 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 2218 | drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs, |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2219 | DRM_MODE_ENCODER_TMDS); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 2220 | drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2221 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 2222 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2223 | drm_sysfs_connector_add(connector); |
| 2224 | |
| 2225 | /* Set up the DDC bus. */ |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2226 | switch (output_reg) { |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2227 | case DP_A: |
| 2228 | name = "DPDDC-A"; |
| 2229 | break; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2230 | case DP_B: |
| 2231 | case PCH_DP_B: |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2232 | dev_priv->hotplug_supported_mask |= |
| 2233 | HDMIB_HOTPLUG_INT_STATUS; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2234 | name = "DPDDC-B"; |
| 2235 | break; |
| 2236 | case DP_C: |
| 2237 | case PCH_DP_C: |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2238 | dev_priv->hotplug_supported_mask |= |
| 2239 | HDMIC_HOTPLUG_INT_STATUS; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2240 | name = "DPDDC-C"; |
| 2241 | break; |
| 2242 | case DP_D: |
| 2243 | case PCH_DP_D: |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 2244 | dev_priv->hotplug_supported_mask |= |
| 2245 | HDMID_HOTPLUG_INT_STATUS; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 2246 | name = "DPDDC-D"; |
| 2247 | break; |
| 2248 | } |
| 2249 | |
Jesse Barnes | 8966738 | 2010-10-07 16:01:21 -0700 | [diff] [blame] | 2250 | /* Cache some DPCD data in the eDP case */ |
| 2251 | if (is_edp(intel_dp)) { |
Keith Packard | 59f3e27 | 2011-07-25 20:01:56 -0700 | [diff] [blame] | 2252 | bool ret; |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2253 | struct edp_power_seq cur, vbt; |
| 2254 | u32 pp_on, pp_off, pp_div; |
Jesse Barnes | 8966738 | 2010-10-07 16:01:21 -0700 | [diff] [blame] | 2255 | |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2256 | pp_on = I915_READ(PCH_PP_ON_DELAYS); |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2257 | pp_off = I915_READ(PCH_PP_OFF_DELAYS); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2258 | pp_div = I915_READ(PCH_PP_DIVISOR); |
| 2259 | |
Keith Packard | f01eca2 | 2011-09-28 16:48:10 -0700 | [diff] [blame] | 2260 | /* Pull timing values out of registers */ |
| 2261 | cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >> |
| 2262 | PANEL_POWER_UP_DELAY_SHIFT; |
| 2263 | |
| 2264 | cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> |
| 2265 | PANEL_LIGHT_ON_DELAY_SHIFT; |
| 2266 | |
| 2267 | cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> |
| 2268 | PANEL_LIGHT_OFF_DELAY_SHIFT; |
| 2269 | |
| 2270 | cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >> |
| 2271 | PANEL_POWER_DOWN_DELAY_SHIFT; |
| 2272 | |
| 2273 | cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >> |
| 2274 | PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000; |
| 2275 | |
| 2276 | DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 2277 | cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12); |
| 2278 | |
| 2279 | vbt = dev_priv->edp.pps; |
| 2280 | |
| 2281 | DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n", |
| 2282 | vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12); |
| 2283 | |
| 2284 | #define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10) |
| 2285 | |
| 2286 | intel_dp->panel_power_up_delay = get_delay(t1_t3); |
| 2287 | intel_dp->backlight_on_delay = get_delay(t8); |
| 2288 | intel_dp->backlight_off_delay = get_delay(t9); |
| 2289 | intel_dp->panel_power_down_delay = get_delay(t10); |
| 2290 | intel_dp->panel_power_cycle_delay = get_delay(t11_t12); |
| 2291 | |
| 2292 | DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n", |
| 2293 | intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay, |
| 2294 | intel_dp->panel_power_cycle_delay); |
| 2295 | |
| 2296 | DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", |
| 2297 | intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2298 | |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2299 | intel_dp->panel_off_jiffies = jiffies - intel_dp->panel_power_down_delay; |
| 2300 | |
Jesse Barnes | 5d61350 | 2011-01-24 17:10:54 -0800 | [diff] [blame] | 2301 | ironlake_edp_panel_vdd_on(intel_dp); |
Keith Packard | 59f3e27 | 2011-07-25 20:01:56 -0700 | [diff] [blame] | 2302 | ret = intel_dp_get_dpcd(intel_dp); |
Keith Packard | bd94315 | 2011-09-18 23:09:52 -0700 | [diff] [blame] | 2303 | ironlake_edp_panel_vdd_off(intel_dp, false); |
Keith Packard | 59f3e27 | 2011-07-25 20:01:56 -0700 | [diff] [blame] | 2304 | if (ret) { |
Jesse Barnes | 7183dc2 | 2011-07-07 11:10:58 -0700 | [diff] [blame] | 2305 | if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) |
| 2306 | dev_priv->no_aux_handshake = |
| 2307 | intel_dp->dpcd[DP_MAX_DOWNSPREAD] & |
Jesse Barnes | 8966738 | 2010-10-07 16:01:21 -0700 | [diff] [blame] | 2308 | DP_NO_AUX_HANDSHAKE_LINK_TRAINING; |
| 2309 | } else { |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 2310 | /* if this fails, presume the device is a ghost */ |
Takashi Iwai | 48898b0 | 2011-03-18 09:06:49 +0000 | [diff] [blame] | 2311 | DRM_INFO("failed to retrieve link info, disabling eDP\n"); |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 2312 | intel_dp_encoder_destroy(&intel_dp->base.base); |
Takashi Iwai | 48898b0 | 2011-03-18 09:06:49 +0000 | [diff] [blame] | 2313 | intel_dp_destroy(&intel_connector->base); |
Chris Wilson | 3d3dc14 | 2011-02-12 10:33:12 +0000 | [diff] [blame] | 2314 | return; |
Jesse Barnes | 8966738 | 2010-10-07 16:01:21 -0700 | [diff] [blame] | 2315 | } |
Jesse Barnes | 8966738 | 2010-10-07 16:01:21 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Keith Packard | 552fb0b | 2011-09-28 16:31:53 -0700 | [diff] [blame] | 2318 | intel_dp_i2c_init(intel_dp, intel_connector, name); |
| 2319 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 2320 | intel_encoder->hot_plug = intel_dp_hot_plug; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2321 | |
Jesse Barnes | 4d92646 | 2010-10-07 16:01:07 -0700 | [diff] [blame] | 2322 | if (is_edp(intel_dp)) { |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 2323 | dev_priv->int_edp_connector = connector; |
| 2324 | intel_panel_setup_backlight(dev); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 2325 | } |
| 2326 | |
Chris Wilson | f684960 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 2327 | intel_dp_add_properties(intel_dp, connector); |
| 2328 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 2329 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 2330 | * 0xd. Failure to do so will result in spurious interrupts being |
| 2331 | * generated on the port when a cable is not attached. |
| 2332 | */ |
| 2333 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 2334 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 2335 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 2336 | } |
| 2337 | } |