Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 Dave Airlie <airlied@linux.ie> |
| 3 | * Copyright © 2006-2009 Intel Corporation |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Eric Anholt <eric@anholt.net> |
| 26 | * Jesse Barnes <jesse.barnes@intel.com> |
| 27 | */ |
| 28 | |
| 29 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 31 | #include <linux/delay.h> |
| 32 | #include "drmP.h" |
| 33 | #include "drm.h" |
| 34 | #include "drm_crtc.h" |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 35 | #include "drm_edid.h" |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
| 37 | #include "i915_drm.h" |
| 38 | #include "i915_drv.h" |
| 39 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 40 | struct intel_hdmi { |
| 41 | struct intel_encoder base; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 42 | u32 sdvox_reg; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 43 | int ddc_bus; |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 44 | uint32_t color_range; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 45 | bool has_hdmi_sink; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 46 | bool has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 47 | int force_audio; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 48 | void (*write_infoframe)(struct drm_encoder *encoder, |
| 49 | struct dip_infoframe *frame); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 52 | static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) |
| 53 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 54 | return container_of(encoder, struct intel_hdmi, base.base); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 57 | static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector) |
| 58 | { |
| 59 | return container_of(intel_attached_encoder(connector), |
| 60 | struct intel_hdmi, base); |
| 61 | } |
| 62 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 63 | void intel_dip_infoframe_csum(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 64 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 65 | uint8_t *data = (uint8_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 66 | uint8_t sum = 0; |
| 67 | unsigned i; |
| 68 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 69 | frame->checksum = 0; |
| 70 | frame->ecc = 0; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 71 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 72 | /* Header isn't part of the checksum */ |
| 73 | for (i = 5; i < frame->len; i++) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 74 | sum += data[i]; |
| 75 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 76 | frame->checksum = 0x100 - sum; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 79 | static u32 intel_infoframe_index(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 80 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 81 | u32 flags = 0; |
| 82 | |
| 83 | switch (frame->type) { |
| 84 | case DIP_TYPE_AVI: |
| 85 | flags |= VIDEO_DIP_SELECT_AVI; |
| 86 | break; |
| 87 | case DIP_TYPE_SPD: |
| 88 | flags |= VIDEO_DIP_SELECT_SPD; |
| 89 | break; |
| 90 | default: |
| 91 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | return flags; |
| 96 | } |
| 97 | |
| 98 | static u32 intel_infoframe_flags(struct dip_infoframe *frame) |
| 99 | { |
| 100 | u32 flags = 0; |
| 101 | |
| 102 | switch (frame->type) { |
| 103 | case DIP_TYPE_AVI: |
| 104 | flags |= VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 105 | break; |
| 106 | case DIP_TYPE_SPD: |
| 107 | flags |= VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_FREQ_2VSYNC; |
| 108 | break; |
| 109 | default: |
| 110 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | return flags; |
| 115 | } |
| 116 | |
| 117 | static void i9xx_write_infoframe(struct drm_encoder *encoder, |
| 118 | struct dip_infoframe *frame) |
| 119 | { |
| 120 | uint32_t *data = (uint32_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 121 | struct drm_device *dev = encoder->dev; |
| 122 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 123 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 124 | u32 port, flags, val = I915_READ(VIDEO_DIP_CTL); |
| 125 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 126 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 127 | |
| 128 | /* XXX first guess at handling video port, is this corrent? */ |
| 129 | if (intel_hdmi->sdvox_reg == SDVOB) |
| 130 | port = VIDEO_DIP_PORT_B; |
| 131 | else if (intel_hdmi->sdvox_reg == SDVOC) |
| 132 | port = VIDEO_DIP_PORT_C; |
| 133 | else |
| 134 | return; |
| 135 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 136 | flags = intel_infoframe_index(frame); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 137 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 138 | val &= ~VIDEO_DIP_SELECT_MASK; |
| 139 | |
| 140 | I915_WRITE(VIDEO_DIP_CTL, val | port | flags); |
| 141 | |
| 142 | for (i = 0; i < len; i += 4) { |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 143 | I915_WRITE(VIDEO_DIP_DATA, *data); |
| 144 | data++; |
| 145 | } |
| 146 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 147 | flags |= intel_infoframe_flags(frame); |
| 148 | |
| 149 | I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 152 | static void ironlake_write_infoframe(struct drm_encoder *encoder, |
| 153 | struct dip_infoframe *frame) |
| 154 | { |
| 155 | uint32_t *data = (uint32_t *)frame; |
| 156 | struct drm_device *dev = encoder->dev; |
| 157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 158 | struct drm_crtc *crtc = encoder->crtc; |
| 159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 160 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 161 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
| 162 | u32 flags, val = I915_READ(reg); |
| 163 | |
| 164 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 165 | |
| 166 | flags = intel_infoframe_index(frame); |
| 167 | |
| 168 | val &= ~VIDEO_DIP_SELECT_MASK; |
| 169 | |
| 170 | I915_WRITE(reg, val | flags); |
| 171 | |
| 172 | for (i = 0; i < len; i += 4) { |
| 173 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 174 | data++; |
| 175 | } |
| 176 | |
| 177 | flags |= intel_infoframe_flags(frame); |
| 178 | |
| 179 | I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags); |
| 180 | } |
| 181 | static void intel_set_infoframe(struct drm_encoder *encoder, |
| 182 | struct dip_infoframe *frame) |
| 183 | { |
| 184 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 185 | |
| 186 | if (!intel_hdmi->has_hdmi_sink) |
| 187 | return; |
| 188 | |
| 189 | intel_dip_infoframe_csum(frame); |
| 190 | intel_hdmi->write_infoframe(encoder, frame); |
| 191 | } |
| 192 | |
| 193 | static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder) |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 194 | { |
| 195 | struct dip_infoframe avi_if = { |
| 196 | .type = DIP_TYPE_AVI, |
| 197 | .ver = DIP_VERSION_AVI, |
| 198 | .len = DIP_LEN_AVI, |
| 199 | }; |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 200 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 201 | intel_set_infoframe(encoder, &avi_if); |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 204 | static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder) |
| 205 | { |
| 206 | struct dip_infoframe spd_if; |
| 207 | |
| 208 | memset(&spd_if, 0, sizeof(spd_if)); |
| 209 | spd_if.type = DIP_TYPE_SPD; |
| 210 | spd_if.ver = DIP_VERSION_SPD; |
| 211 | spd_if.len = DIP_LEN_SPD; |
| 212 | strcpy(spd_if.body.spd.vn, "Intel"); |
| 213 | strcpy(spd_if.body.spd.pd, "Integrated gfx"); |
| 214 | spd_if.body.spd.sdi = DIP_SPD_PC; |
| 215 | |
| 216 | intel_set_infoframe(encoder, &spd_if); |
| 217 | } |
| 218 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 219 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, |
| 220 | struct drm_display_mode *mode, |
| 221 | struct drm_display_mode *adjusted_mode) |
| 222 | { |
| 223 | struct drm_device *dev = encoder->dev; |
| 224 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 225 | struct drm_crtc *crtc = encoder->crtc; |
| 226 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 227 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 228 | u32 sdvox; |
| 229 | |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 230 | sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE; |
Jesse Barnes | 5d4fac9 | 2011-06-24 12:19:19 -0700 | [diff] [blame] | 231 | if (!HAS_PCH_SPLIT(dev)) |
| 232 | sdvox |= intel_hdmi->color_range; |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 233 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 234 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
| 235 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 236 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 237 | |
Jesse Barnes | 020f670 | 2011-06-24 12:19:25 -0700 | [diff] [blame] | 238 | if (intel_crtc->bpp > 24) |
| 239 | sdvox |= COLOR_FORMAT_12bpc; |
| 240 | else |
| 241 | sdvox |= COLOR_FORMAT_8bpc; |
| 242 | |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 243 | /* Required on CPT */ |
| 244 | if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev)) |
| 245 | sdvox |= HDMI_MODE_SELECT; |
| 246 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 247 | if (intel_hdmi->has_audio) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame^] | 248 | DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n", |
| 249 | pipe_name(intel_crtc->pipe)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 250 | sdvox |= SDVO_AUDIO_ENABLE; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 251 | sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame^] | 252 | intel_write_eld(encoder, adjusted_mode); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 253 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 254 | |
Zhenyu Wang | 0f22906 | 2010-04-07 16:15:57 +0800 | [diff] [blame] | 255 | if (intel_crtc->pipe == 1) { |
| 256 | if (HAS_PCH_CPT(dev)) |
| 257 | sdvox |= PORT_TRANS_B_SEL_CPT; |
| 258 | else |
| 259 | sdvox |= SDVO_PIPE_B_SELECT; |
| 260 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 261 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 262 | I915_WRITE(intel_hdmi->sdvox_reg, sdvox); |
| 263 | POSTING_READ(intel_hdmi->sdvox_reg); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 264 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 265 | intel_hdmi_set_avi_infoframe(encoder); |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 266 | intel_hdmi_set_spd_infoframe(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) |
| 270 | { |
| 271 | struct drm_device *dev = encoder->dev; |
| 272 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 273 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 274 | u32 temp; |
| 275 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 276 | temp = I915_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 277 | |
| 278 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 279 | * we do this anyway which shows more stable in testing. |
| 280 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 281 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 282 | I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE); |
| 283 | POSTING_READ(intel_hdmi->sdvox_reg); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 284 | } |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 285 | |
| 286 | if (mode != DRM_MODE_DPMS_ON) { |
| 287 | temp &= ~SDVO_ENABLE; |
| 288 | } else { |
| 289 | temp |= SDVO_ENABLE; |
| 290 | } |
| 291 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 292 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 293 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 294 | |
| 295 | /* HW workaround, need to write this twice for issue that may result |
| 296 | * in first write getting masked. |
| 297 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 298 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 299 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 300 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 301 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 304 | static int intel_hdmi_mode_valid(struct drm_connector *connector, |
| 305 | struct drm_display_mode *mode) |
| 306 | { |
| 307 | if (mode->clock > 165000) |
| 308 | return MODE_CLOCK_HIGH; |
| 309 | if (mode->clock < 20000) |
Nicolas Kaiser | 5cbba41 | 2011-05-30 12:48:26 +0200 | [diff] [blame] | 310 | return MODE_CLOCK_LOW; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 311 | |
| 312 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 313 | return MODE_NO_DBLESCAN; |
| 314 | |
| 315 | return MODE_OK; |
| 316 | } |
| 317 | |
| 318 | static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, |
| 319 | struct drm_display_mode *mode, |
| 320 | struct drm_display_mode *adjusted_mode) |
| 321 | { |
| 322 | return true; |
| 323 | } |
| 324 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 325 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 326 | intel_hdmi_detect(struct drm_connector *connector, bool force) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 327 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 328 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 329 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 330 | struct edid *edid; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 331 | enum drm_connector_status status = connector_status_disconnected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 332 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 333 | intel_hdmi->has_hdmi_sink = false; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 334 | intel_hdmi->has_audio = false; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 335 | edid = drm_get_edid(connector, |
| 336 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
ling.ma@intel.com | 2ded9e274 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 337 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 338 | if (edid) { |
Eric Anholt | be9f1c4 | 2009-06-21 22:14:55 -0700 | [diff] [blame] | 339 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 340 | status = connector_status_connected; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 341 | intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid); |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 342 | intel_hdmi->has_audio = drm_detect_monitor_audio(edid); |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 343 | } |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 344 | connector->display_info.raw_edid = NULL; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 345 | kfree(edid); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 346 | } |
ling.ma@intel.com | 2ded9e274 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 347 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 348 | if (status == connector_status_connected) { |
| 349 | if (intel_hdmi->force_audio) |
| 350 | intel_hdmi->has_audio = intel_hdmi->force_audio > 0; |
| 351 | } |
| 352 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 353 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 354 | } |
| 355 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 356 | static int intel_hdmi_get_modes(struct drm_connector *connector) |
| 357 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 358 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 359 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 360 | |
| 361 | /* We should parse the EDID data and find out if it's an HDMI sink so |
| 362 | * we can send audio to it. |
| 363 | */ |
| 364 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 365 | return intel_ddc_get_modes(connector, |
| 366 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 369 | static bool |
| 370 | intel_hdmi_detect_audio(struct drm_connector *connector) |
| 371 | { |
| 372 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 373 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 374 | struct edid *edid; |
| 375 | bool has_audio = false; |
| 376 | |
| 377 | edid = drm_get_edid(connector, |
| 378 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
| 379 | if (edid) { |
| 380 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 381 | has_audio = drm_detect_monitor_audio(edid); |
| 382 | |
| 383 | connector->display_info.raw_edid = NULL; |
| 384 | kfree(edid); |
| 385 | } |
| 386 | |
| 387 | return has_audio; |
| 388 | } |
| 389 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 390 | static int |
| 391 | intel_hdmi_set_property(struct drm_connector *connector, |
| 392 | struct drm_property *property, |
| 393 | uint64_t val) |
| 394 | { |
| 395 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 396 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 397 | int ret; |
| 398 | |
| 399 | ret = drm_connector_property_set_value(connector, property, val); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 403 | if (property == dev_priv->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 404 | int i = val; |
| 405 | bool has_audio; |
| 406 | |
| 407 | if (i == intel_hdmi->force_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 408 | return 0; |
| 409 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 410 | intel_hdmi->force_audio = i; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 411 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 412 | if (i == 0) |
| 413 | has_audio = intel_hdmi_detect_audio(connector); |
| 414 | else |
| 415 | has_audio = i > 0; |
| 416 | |
| 417 | if (has_audio == intel_hdmi->has_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 418 | return 0; |
| 419 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 420 | intel_hdmi->has_audio = has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 421 | goto done; |
| 422 | } |
| 423 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 424 | if (property == dev_priv->broadcast_rgb_property) { |
| 425 | if (val == !!intel_hdmi->color_range) |
| 426 | return 0; |
| 427 | |
| 428 | intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0; |
| 429 | goto done; |
| 430 | } |
| 431 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 432 | return -EINVAL; |
| 433 | |
| 434 | done: |
| 435 | if (intel_hdmi->base.base.crtc) { |
| 436 | struct drm_crtc *crtc = intel_hdmi->base.base.crtc; |
| 437 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 438 | crtc->x, crtc->y, |
| 439 | crtc->fb); |
| 440 | } |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 445 | static void intel_hdmi_destroy(struct drm_connector *connector) |
| 446 | { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 447 | drm_sysfs_connector_remove(connector); |
| 448 | drm_connector_cleanup(connector); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 449 | kfree(connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { |
| 453 | .dpms = intel_hdmi_dpms, |
| 454 | .mode_fixup = intel_hdmi_mode_fixup, |
| 455 | .prepare = intel_encoder_prepare, |
| 456 | .mode_set = intel_hdmi_mode_set, |
| 457 | .commit = intel_encoder_commit, |
| 458 | }; |
| 459 | |
| 460 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 461 | .dpms = drm_helper_connector_dpms, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 462 | .detect = intel_hdmi_detect, |
| 463 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 464 | .set_property = intel_hdmi_set_property, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 465 | .destroy = intel_hdmi_destroy, |
| 466 | }; |
| 467 | |
| 468 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { |
| 469 | .get_modes = intel_hdmi_get_modes, |
| 470 | .mode_valid = intel_hdmi_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 471 | .best_encoder = intel_best_encoder, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 472 | }; |
| 473 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 474 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 475 | .destroy = intel_encoder_destroy, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 476 | }; |
| 477 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 478 | static void |
| 479 | intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector) |
| 480 | { |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 481 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 482 | intel_attach_broadcast_rgb_property(connector); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 485 | void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) |
| 486 | { |
| 487 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 488 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 489 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 490 | struct intel_connector *intel_connector; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 491 | struct intel_hdmi *intel_hdmi; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 492 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 493 | intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL); |
| 494 | if (!intel_hdmi) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 495 | return; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 496 | |
| 497 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 498 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 499 | kfree(intel_hdmi); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 500 | return; |
| 501 | } |
| 502 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 503 | intel_encoder = &intel_hdmi->base; |
Chris Wilson | 373a3cf | 2010-09-15 12:03:59 +0100 | [diff] [blame] | 504 | drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs, |
| 505 | DRM_MODE_ENCODER_TMDS); |
| 506 | |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 507 | connector = &intel_connector->base; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 508 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, |
Adam Jackson | 8d91104 | 2009-09-23 15:08:29 -0400 | [diff] [blame] | 509 | DRM_MODE_CONNECTOR_HDMIA); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 510 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
| 511 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 512 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 513 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 514 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 515 | connector->interlace_allowed = 0; |
| 516 | connector->doublescan_allowed = 0; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 517 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 518 | |
| 519 | /* Set up the DDC bus. */ |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 520 | if (sdvox_reg == SDVOB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 521 | intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 522 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 523 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 524 | } else if (sdvox_reg == SDVOC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 525 | intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 526 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 527 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 528 | } else if (sdvox_reg == HDMIB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 529 | intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 530 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 531 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 532 | } else if (sdvox_reg == HDMIC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 533 | intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 534 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 535 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 536 | } else if (sdvox_reg == HDMID) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 537 | intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 538 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 539 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 540 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 541 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 542 | intel_hdmi->sdvox_reg = sdvox_reg; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 543 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 544 | if (!HAS_PCH_SPLIT(dev)) |
| 545 | intel_hdmi->write_infoframe = i9xx_write_infoframe; |
| 546 | else |
| 547 | intel_hdmi->write_infoframe = ironlake_write_infoframe; |
| 548 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 549 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 550 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 551 | intel_hdmi_add_properties(intel_hdmi, connector); |
| 552 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 553 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 554 | drm_sysfs_connector_add(connector); |
| 555 | |
| 556 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 557 | * 0xd. Failure to do so will result in spurious interrupts being |
| 558 | * generated on the port when a cable is not attached. |
| 559 | */ |
| 560 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 561 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 562 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 563 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 564 | } |