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