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