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; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 44 | bool has_hdmi_sink; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 45 | bool has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 46 | int force_audio; |
| 47 | struct drm_property *force_audio_property; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 50 | static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) |
| 51 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 52 | return container_of(encoder, struct intel_hdmi, base.base); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 55 | static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector) |
| 56 | { |
| 57 | return container_of(intel_attached_encoder(connector), |
| 58 | struct intel_hdmi, base); |
| 59 | } |
| 60 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 61 | void intel_dip_infoframe_csum(struct dip_infoframe *avi_if) |
| 62 | { |
| 63 | uint8_t *data = (uint8_t *)avi_if; |
| 64 | uint8_t sum = 0; |
| 65 | unsigned i; |
| 66 | |
| 67 | avi_if->checksum = 0; |
| 68 | avi_if->ecc = 0; |
| 69 | |
| 70 | for (i = 0; i < sizeof(*avi_if); i++) |
| 71 | sum += data[i]; |
| 72 | |
| 73 | avi_if->checksum = 0x100 - sum; |
| 74 | } |
| 75 | |
| 76 | static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder) |
| 77 | { |
| 78 | struct dip_infoframe avi_if = { |
| 79 | .type = DIP_TYPE_AVI, |
| 80 | .ver = DIP_VERSION_AVI, |
| 81 | .len = DIP_LEN_AVI, |
| 82 | }; |
| 83 | uint32_t *data = (uint32_t *)&avi_if; |
| 84 | struct drm_device *dev = encoder->dev; |
| 85 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 86 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 87 | u32 port; |
| 88 | unsigned i; |
| 89 | |
| 90 | if (!intel_hdmi->has_hdmi_sink) |
| 91 | return; |
| 92 | |
| 93 | /* XXX first guess at handling video port, is this corrent? */ |
| 94 | if (intel_hdmi->sdvox_reg == SDVOB) |
| 95 | port = VIDEO_DIP_PORT_B; |
| 96 | else if (intel_hdmi->sdvox_reg == SDVOC) |
| 97 | port = VIDEO_DIP_PORT_C; |
| 98 | else |
| 99 | return; |
| 100 | |
| 101 | I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | port | |
| 102 | VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC); |
| 103 | |
| 104 | intel_dip_infoframe_csum(&avi_if); |
| 105 | for (i = 0; i < sizeof(avi_if); i += 4) { |
| 106 | I915_WRITE(VIDEO_DIP_DATA, *data); |
| 107 | data++; |
| 108 | } |
| 109 | |
| 110 | I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | port | |
| 111 | VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC | |
| 112 | VIDEO_DIP_ENABLE_AVI); |
| 113 | } |
| 114 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 115 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, |
| 116 | struct drm_display_mode *mode, |
| 117 | struct drm_display_mode *adjusted_mode) |
| 118 | { |
| 119 | struct drm_device *dev = encoder->dev; |
| 120 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 121 | struct drm_crtc *crtc = encoder->crtc; |
| 122 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 123 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 124 | u32 sdvox; |
| 125 | |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 126 | sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE; |
| 127 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 128 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
| 129 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 130 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 131 | |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 132 | /* Required on CPT */ |
| 133 | if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev)) |
| 134 | sdvox |= HDMI_MODE_SELECT; |
| 135 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 136 | if (intel_hdmi->has_audio) { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 137 | sdvox |= SDVO_AUDIO_ENABLE; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 138 | sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC; |
| 139 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 140 | |
Zhenyu Wang | 0f22906 | 2010-04-07 16:15:57 +0800 | [diff] [blame] | 141 | if (intel_crtc->pipe == 1) { |
| 142 | if (HAS_PCH_CPT(dev)) |
| 143 | sdvox |= PORT_TRANS_B_SEL_CPT; |
| 144 | else |
| 145 | sdvox |= SDVO_PIPE_B_SELECT; |
| 146 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 147 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 148 | I915_WRITE(intel_hdmi->sdvox_reg, sdvox); |
| 149 | POSTING_READ(intel_hdmi->sdvox_reg); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 150 | |
| 151 | intel_hdmi_set_avi_infoframe(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) |
| 155 | { |
| 156 | struct drm_device *dev = encoder->dev; |
| 157 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 158 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 159 | u32 temp; |
| 160 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 161 | temp = I915_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 162 | |
| 163 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 164 | * we do this anyway which shows more stable in testing. |
| 165 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 166 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 167 | I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE); |
| 168 | POSTING_READ(intel_hdmi->sdvox_reg); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 169 | } |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 170 | |
| 171 | if (mode != DRM_MODE_DPMS_ON) { |
| 172 | temp &= ~SDVO_ENABLE; |
| 173 | } else { |
| 174 | temp |= SDVO_ENABLE; |
| 175 | } |
| 176 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 177 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 178 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 179 | |
| 180 | /* HW workaround, need to write this twice for issue that may result |
| 181 | * in first write getting masked. |
| 182 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 183 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 184 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 185 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 186 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 189 | static int intel_hdmi_mode_valid(struct drm_connector *connector, |
| 190 | struct drm_display_mode *mode) |
| 191 | { |
| 192 | if (mode->clock > 165000) |
| 193 | return MODE_CLOCK_HIGH; |
| 194 | if (mode->clock < 20000) |
| 195 | return MODE_CLOCK_HIGH; |
| 196 | |
| 197 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 198 | return MODE_NO_DBLESCAN; |
| 199 | |
| 200 | return MODE_OK; |
| 201 | } |
| 202 | |
| 203 | static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, |
| 204 | struct drm_display_mode *mode, |
| 205 | struct drm_display_mode *adjusted_mode) |
| 206 | { |
| 207 | return true; |
| 208 | } |
| 209 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 210 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 211 | intel_hdmi_detect(struct drm_connector *connector, bool force) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 212 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 213 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 214 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 215 | struct edid *edid; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 216 | enum drm_connector_status status = connector_status_disconnected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 217 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 218 | intel_hdmi->has_hdmi_sink = false; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 219 | intel_hdmi->has_audio = false; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 220 | edid = drm_get_edid(connector, |
| 221 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 222 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 223 | if (edid) { |
Eric Anholt | be9f1c4 | 2009-06-21 22:14:55 -0700 | [diff] [blame] | 224 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 225 | status = connector_status_connected; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 226 | intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid); |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 227 | intel_hdmi->has_audio = drm_detect_monitor_audio(edid); |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 228 | } |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 229 | connector->display_info.raw_edid = NULL; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 230 | kfree(edid); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 231 | } |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 232 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 233 | if (status == connector_status_connected) { |
| 234 | if (intel_hdmi->force_audio) |
| 235 | intel_hdmi->has_audio = intel_hdmi->force_audio > 0; |
| 236 | } |
| 237 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 238 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 239 | } |
| 240 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 241 | static int intel_hdmi_get_modes(struct drm_connector *connector) |
| 242 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 243 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 244 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 245 | |
| 246 | /* We should parse the EDID data and find out if it's an HDMI sink so |
| 247 | * we can send audio to it. |
| 248 | */ |
| 249 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 250 | return intel_ddc_get_modes(connector, |
| 251 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 254 | static bool |
| 255 | intel_hdmi_detect_audio(struct drm_connector *connector) |
| 256 | { |
| 257 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 258 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 259 | struct edid *edid; |
| 260 | bool has_audio = false; |
| 261 | |
| 262 | edid = drm_get_edid(connector, |
| 263 | &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter); |
| 264 | if (edid) { |
| 265 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 266 | has_audio = drm_detect_monitor_audio(edid); |
| 267 | |
| 268 | connector->display_info.raw_edid = NULL; |
| 269 | kfree(edid); |
| 270 | } |
| 271 | |
| 272 | return has_audio; |
| 273 | } |
| 274 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 275 | static int |
| 276 | intel_hdmi_set_property(struct drm_connector *connector, |
| 277 | struct drm_property *property, |
| 278 | uint64_t val) |
| 279 | { |
| 280 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 281 | int ret; |
| 282 | |
| 283 | ret = drm_connector_property_set_value(connector, property, val); |
| 284 | if (ret) |
| 285 | return ret; |
| 286 | |
| 287 | if (property == intel_hdmi->force_audio_property) { |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 288 | int i = val; |
| 289 | bool has_audio; |
| 290 | |
| 291 | if (i == intel_hdmi->force_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 292 | return 0; |
| 293 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 294 | intel_hdmi->force_audio = i; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 295 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 296 | if (i == 0) |
| 297 | has_audio = intel_hdmi_detect_audio(connector); |
| 298 | else |
| 299 | has_audio = i > 0; |
| 300 | |
| 301 | if (has_audio == intel_hdmi->has_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 302 | return 0; |
| 303 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 304 | intel_hdmi->has_audio = has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 305 | goto done; |
| 306 | } |
| 307 | |
| 308 | return -EINVAL; |
| 309 | |
| 310 | done: |
| 311 | if (intel_hdmi->base.base.crtc) { |
| 312 | struct drm_crtc *crtc = intel_hdmi->base.base.crtc; |
| 313 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 314 | crtc->x, crtc->y, |
| 315 | crtc->fb); |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 321 | static void intel_hdmi_destroy(struct drm_connector *connector) |
| 322 | { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 323 | drm_sysfs_connector_remove(connector); |
| 324 | drm_connector_cleanup(connector); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 325 | kfree(connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { |
| 329 | .dpms = intel_hdmi_dpms, |
| 330 | .mode_fixup = intel_hdmi_mode_fixup, |
| 331 | .prepare = intel_encoder_prepare, |
| 332 | .mode_set = intel_hdmi_mode_set, |
| 333 | .commit = intel_encoder_commit, |
| 334 | }; |
| 335 | |
| 336 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 337 | .dpms = drm_helper_connector_dpms, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 338 | .detect = intel_hdmi_detect, |
| 339 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 340 | .set_property = intel_hdmi_set_property, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 341 | .destroy = intel_hdmi_destroy, |
| 342 | }; |
| 343 | |
| 344 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { |
| 345 | .get_modes = intel_hdmi_get_modes, |
| 346 | .mode_valid = intel_hdmi_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 347 | .best_encoder = intel_best_encoder, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 348 | }; |
| 349 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 350 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 351 | .destroy = intel_encoder_destroy, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 352 | }; |
| 353 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 354 | static void |
| 355 | intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector) |
| 356 | { |
| 357 | struct drm_device *dev = connector->dev; |
| 358 | |
| 359 | intel_hdmi->force_audio_property = |
| 360 | drm_property_create(dev, DRM_MODE_PROP_RANGE, "force_audio", 2); |
| 361 | if (intel_hdmi->force_audio_property) { |
| 362 | intel_hdmi->force_audio_property->values[0] = -1; |
| 363 | intel_hdmi->force_audio_property->values[1] = 1; |
| 364 | drm_connector_attach_property(connector, intel_hdmi->force_audio_property, 0); |
| 365 | } |
| 366 | } |
| 367 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 368 | void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) |
| 369 | { |
| 370 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 371 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 372 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 373 | struct intel_connector *intel_connector; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 374 | struct intel_hdmi *intel_hdmi; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 375 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 376 | intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL); |
| 377 | if (!intel_hdmi) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 378 | return; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 379 | |
| 380 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 381 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 382 | kfree(intel_hdmi); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 386 | intel_encoder = &intel_hdmi->base; |
Chris Wilson | 373a3cf | 2010-09-15 12:03:59 +0100 | [diff] [blame] | 387 | drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs, |
| 388 | DRM_MODE_ENCODER_TMDS); |
| 389 | |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 390 | connector = &intel_connector->base; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 391 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, |
Adam Jackson | 8d91104 | 2009-09-23 15:08:29 -0400 | [diff] [blame] | 392 | DRM_MODE_CONNECTOR_HDMIA); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 393 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
| 394 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 395 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 396 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 397 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 398 | connector->interlace_allowed = 0; |
| 399 | connector->doublescan_allowed = 0; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 400 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 401 | |
| 402 | /* Set up the DDC bus. */ |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 403 | if (sdvox_reg == SDVOB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 404 | intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 405 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 406 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 407 | } else if (sdvox_reg == SDVOC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 408 | intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 409 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 410 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 411 | } else if (sdvox_reg == HDMIB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 412 | intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 413 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 414 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 415 | } else if (sdvox_reg == HDMIC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 416 | intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 417 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 418 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 419 | } else if (sdvox_reg == HDMID) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 420 | intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 421 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 422 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 423 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 424 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 425 | intel_hdmi->sdvox_reg = sdvox_reg; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 426 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 427 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 428 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 429 | intel_hdmi_add_properties(intel_hdmi, connector); |
| 430 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 431 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 432 | drm_sysfs_connector_add(connector); |
| 433 | |
| 434 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 435 | * 0xd. Failure to do so will result in spurious interrupts being |
| 436 | * generated on the port when a cable is not attached. |
| 437 | */ |
| 438 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 439 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 440 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 441 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 442 | } |