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