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; |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 47 | enum hdmi_force_audio 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 | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 72 | for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 73 | sum += data[i]; |
| 74 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 75 | frame->checksum = 0x100 - sum; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 78 | static u32 intel_infoframe_index(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 79 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 80 | u32 flags = 0; |
| 81 | |
| 82 | switch (frame->type) { |
| 83 | case DIP_TYPE_AVI: |
| 84 | flags |= VIDEO_DIP_SELECT_AVI; |
| 85 | break; |
| 86 | case DIP_TYPE_SPD: |
| 87 | flags |= VIDEO_DIP_SELECT_SPD; |
| 88 | break; |
| 89 | default: |
| 90 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | return flags; |
| 95 | } |
| 96 | |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 97 | static u32 intel_infoframe_enable(struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 98 | { |
| 99 | u32 flags = 0; |
| 100 | |
| 101 | switch (frame->type) { |
| 102 | case DIP_TYPE_AVI: |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 103 | flags |= VIDEO_DIP_ENABLE_AVI; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 104 | break; |
| 105 | case DIP_TYPE_SPD: |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 106 | flags |= VIDEO_DIP_ENABLE_SPD; |
| 107 | break; |
| 108 | default: |
| 109 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | return flags; |
| 114 | } |
| 115 | |
| 116 | static u32 intel_infoframe_frequency(struct dip_infoframe *frame) |
| 117 | { |
| 118 | u32 flags = 0; |
| 119 | |
| 120 | switch (frame->type) { |
| 121 | case DIP_TYPE_AVI: |
| 122 | case DIP_TYPE_SPD: |
| 123 | flags |= VIDEO_DIP_FREQ_VSYNC; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 124 | break; |
| 125 | default: |
| 126 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | return flags; |
| 131 | } |
| 132 | |
| 133 | static void i9xx_write_infoframe(struct drm_encoder *encoder, |
| 134 | struct dip_infoframe *frame) |
| 135 | { |
| 136 | uint32_t *data = (uint32_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 137 | struct drm_device *dev = encoder->dev; |
| 138 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 139 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 140 | u32 val = I915_READ(VIDEO_DIP_CTL); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 141 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 142 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 143 | |
| 144 | /* XXX first guess at handling video port, is this corrent? */ |
Paulo Zanoni | 3e6e639 | 2012-05-04 17:18:19 -0300 | [diff] [blame] | 145 | val &= ~VIDEO_DIP_PORT_MASK; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 146 | if (intel_hdmi->sdvox_reg == SDVOB) |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 147 | val |= VIDEO_DIP_PORT_B; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 148 | else if (intel_hdmi->sdvox_reg == SDVOC) |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 149 | val |= VIDEO_DIP_PORT_C; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 150 | else |
| 151 | return; |
| 152 | |
Paulo Zanoni | 1d4f85a | 2012-05-04 17:18:18 -0300 | [diff] [blame] | 153 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 154 | val |= intel_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 155 | |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 156 | val &= ~intel_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 157 | val |= VIDEO_DIP_ENABLE; |
| 158 | |
| 159 | I915_WRITE(VIDEO_DIP_CTL, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 160 | |
| 161 | for (i = 0; i < len; i += 4) { |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 162 | I915_WRITE(VIDEO_DIP_DATA, *data); |
| 163 | data++; |
| 164 | } |
| 165 | |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 166 | val |= intel_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 167 | val &= ~VIDEO_DIP_FREQ_MASK; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 168 | val |= intel_infoframe_frequency(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 169 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 170 | I915_WRITE(VIDEO_DIP_CTL, val); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 173 | static void ibx_write_infoframe(struct drm_encoder *encoder, |
| 174 | struct dip_infoframe *frame) |
| 175 | { |
| 176 | uint32_t *data = (uint32_t *)frame; |
| 177 | struct drm_device *dev = encoder->dev; |
| 178 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 179 | struct drm_crtc *crtc = encoder->crtc; |
| 180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 4e89ee1 | 2012-05-04 17:18:26 -0300 | [diff] [blame^] | 181 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 182 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 183 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
| 184 | u32 val = I915_READ(reg); |
| 185 | |
Paulo Zanoni | 4e89ee1 | 2012-05-04 17:18:26 -0300 | [diff] [blame^] | 186 | val &= ~VIDEO_DIP_PORT_MASK; |
| 187 | switch (intel_hdmi->sdvox_reg) { |
| 188 | case HDMIB: |
| 189 | val |= VIDEO_DIP_PORT_B; |
| 190 | break; |
| 191 | case HDMIC: |
| 192 | val |= VIDEO_DIP_PORT_C; |
| 193 | break; |
| 194 | case HDMID: |
| 195 | val |= VIDEO_DIP_PORT_D; |
| 196 | break; |
| 197 | default: |
| 198 | return; |
| 199 | } |
| 200 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 201 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 202 | |
| 203 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
| 204 | val |= intel_infoframe_index(frame); |
| 205 | |
Paulo Zanoni | 4dc20c0 | 2012-05-04 17:18:25 -0300 | [diff] [blame] | 206 | val &= ~intel_infoframe_enable(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 207 | val |= VIDEO_DIP_ENABLE; |
| 208 | |
| 209 | I915_WRITE(reg, val); |
| 210 | |
| 211 | for (i = 0; i < len; i += 4) { |
| 212 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 213 | data++; |
| 214 | } |
| 215 | |
| 216 | val |= intel_infoframe_enable(frame); |
| 217 | val &= ~VIDEO_DIP_FREQ_MASK; |
| 218 | val |= intel_infoframe_frequency(frame); |
| 219 | |
| 220 | I915_WRITE(reg, val); |
| 221 | } |
| 222 | |
| 223 | static void cpt_write_infoframe(struct drm_encoder *encoder, |
| 224 | struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 225 | { |
| 226 | uint32_t *data = (uint32_t *)frame; |
| 227 | struct drm_device *dev = encoder->dev; |
| 228 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 229 | struct drm_crtc *crtc = encoder->crtc; |
| 230 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 231 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 232 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 233 | u32 val = I915_READ(reg); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 234 | |
| 235 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 236 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 237 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 238 | val |= intel_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 239 | |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 240 | /* The DIP control register spec says that we need to update the AVI |
| 241 | * infoframe without clearing its enable bit */ |
| 242 | if (frame->type == DIP_TYPE_AVI) |
| 243 | val |= VIDEO_DIP_ENABLE_AVI; |
| 244 | else |
| 245 | val &= ~intel_infoframe_enable(frame); |
| 246 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 247 | val |= VIDEO_DIP_ENABLE; |
| 248 | |
| 249 | I915_WRITE(reg, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 250 | |
| 251 | for (i = 0; i < len; i += 4) { |
| 252 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 253 | data++; |
| 254 | } |
| 255 | |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 256 | val |= intel_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 257 | val &= ~VIDEO_DIP_FREQ_MASK; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 258 | val |= intel_infoframe_frequency(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 259 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 260 | I915_WRITE(reg, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 261 | } |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 262 | |
| 263 | static void vlv_write_infoframe(struct drm_encoder *encoder, |
| 264 | struct dip_infoframe *frame) |
| 265 | { |
| 266 | uint32_t *data = (uint32_t *)frame; |
| 267 | struct drm_device *dev = encoder->dev; |
| 268 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 269 | struct drm_crtc *crtc = encoder->crtc; |
| 270 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 271 | int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 272 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 273 | u32 val = I915_READ(reg); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 274 | |
| 275 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 276 | |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 277 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 278 | val |= intel_infoframe_index(frame); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 279 | |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 280 | val &= ~intel_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 281 | val |= VIDEO_DIP_ENABLE; |
| 282 | |
| 283 | I915_WRITE(reg, val); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 284 | |
| 285 | for (i = 0; i < len; i += 4) { |
| 286 | I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 287 | data++; |
| 288 | } |
| 289 | |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 290 | val |= intel_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 291 | val &= ~VIDEO_DIP_FREQ_MASK; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 292 | val |= intel_infoframe_frequency(frame); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 293 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 294 | I915_WRITE(reg, val); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 297 | static void intel_set_infoframe(struct drm_encoder *encoder, |
| 298 | struct dip_infoframe *frame) |
| 299 | { |
| 300 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 301 | |
| 302 | if (!intel_hdmi->has_hdmi_sink) |
| 303 | return; |
| 304 | |
| 305 | intel_dip_infoframe_csum(frame); |
| 306 | intel_hdmi->write_infoframe(encoder, frame); |
| 307 | } |
| 308 | |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 309 | static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder, |
| 310 | struct drm_display_mode *adjusted_mode) |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 311 | { |
| 312 | struct dip_infoframe avi_if = { |
| 313 | .type = DIP_TYPE_AVI, |
| 314 | .ver = DIP_VERSION_AVI, |
| 315 | .len = DIP_LEN_AVI, |
| 316 | }; |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 317 | |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 318 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 319 | avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2; |
| 320 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 321 | intel_set_infoframe(encoder, &avi_if); |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 324 | static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder) |
| 325 | { |
| 326 | struct dip_infoframe spd_if; |
| 327 | |
| 328 | memset(&spd_if, 0, sizeof(spd_if)); |
| 329 | spd_if.type = DIP_TYPE_SPD; |
| 330 | spd_if.ver = DIP_VERSION_SPD; |
| 331 | spd_if.len = DIP_LEN_SPD; |
| 332 | strcpy(spd_if.body.spd.vn, "Intel"); |
| 333 | strcpy(spd_if.body.spd.pd, "Integrated gfx"); |
| 334 | spd_if.body.spd.sdi = DIP_SPD_PC; |
| 335 | |
| 336 | intel_set_infoframe(encoder, &spd_if); |
| 337 | } |
| 338 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 339 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, |
| 340 | struct drm_display_mode *mode, |
| 341 | struct drm_display_mode *adjusted_mode) |
| 342 | { |
| 343 | struct drm_device *dev = encoder->dev; |
| 344 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 345 | struct drm_crtc *crtc = encoder->crtc; |
| 346 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 347 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 348 | u32 sdvox; |
| 349 | |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 350 | sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE; |
Jesse Barnes | 5d4fac9 | 2011-06-24 12:19:19 -0700 | [diff] [blame] | 351 | if (!HAS_PCH_SPLIT(dev)) |
| 352 | sdvox |= intel_hdmi->color_range; |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 353 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 354 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
| 355 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 356 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 357 | |
Jesse Barnes | 020f670 | 2011-06-24 12:19:25 -0700 | [diff] [blame] | 358 | if (intel_crtc->bpp > 24) |
| 359 | sdvox |= COLOR_FORMAT_12bpc; |
| 360 | else |
| 361 | sdvox |= COLOR_FORMAT_8bpc; |
| 362 | |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 363 | /* Required on CPT */ |
| 364 | if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev)) |
| 365 | sdvox |= HDMI_MODE_SELECT; |
| 366 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 367 | if (intel_hdmi->has_audio) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 368 | DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n", |
| 369 | pipe_name(intel_crtc->pipe)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 370 | sdvox |= SDVO_AUDIO_ENABLE; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 371 | sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 372 | intel_write_eld(encoder, adjusted_mode); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 373 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 374 | |
Jesse Barnes | 7577056 | 2011-10-12 09:01:58 -0700 | [diff] [blame] | 375 | if (HAS_PCH_CPT(dev)) |
| 376 | sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe); |
| 377 | else if (intel_crtc->pipe == 1) |
| 378 | sdvox |= SDVO_PIPE_B_SELECT; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 379 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 380 | I915_WRITE(intel_hdmi->sdvox_reg, sdvox); |
| 381 | POSTING_READ(intel_hdmi->sdvox_reg); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 382 | |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 383 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 384 | intel_hdmi_set_spd_infoframe(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) |
| 388 | { |
| 389 | struct drm_device *dev = encoder->dev; |
| 390 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 391 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 392 | u32 temp; |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 393 | u32 enable_bits = SDVO_ENABLE; |
| 394 | |
| 395 | if (intel_hdmi->has_audio) |
| 396 | enable_bits |= SDVO_AUDIO_ENABLE; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 397 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 398 | temp = I915_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 399 | |
| 400 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 401 | * we do this anyway which shows more stable in testing. |
| 402 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 403 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 404 | I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE); |
| 405 | POSTING_READ(intel_hdmi->sdvox_reg); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 406 | } |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 407 | |
| 408 | if (mode != DRM_MODE_DPMS_ON) { |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 409 | temp &= ~enable_bits; |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 410 | } else { |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 411 | temp |= enable_bits; |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 414 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 415 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 416 | |
| 417 | /* HW workaround, need to write this twice for issue that may result |
| 418 | * in first write getting masked. |
| 419 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 420 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 421 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 422 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 423 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 426 | static int intel_hdmi_mode_valid(struct drm_connector *connector, |
| 427 | struct drm_display_mode *mode) |
| 428 | { |
| 429 | if (mode->clock > 165000) |
| 430 | return MODE_CLOCK_HIGH; |
| 431 | if (mode->clock < 20000) |
Nicolas Kaiser | 5cbba41 | 2011-05-30 12:48:26 +0200 | [diff] [blame] | 432 | return MODE_CLOCK_LOW; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 433 | |
| 434 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 435 | return MODE_NO_DBLESCAN; |
| 436 | |
| 437 | return MODE_OK; |
| 438 | } |
| 439 | |
| 440 | static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, |
| 441 | struct drm_display_mode *mode, |
| 442 | struct drm_display_mode *adjusted_mode) |
| 443 | { |
| 444 | return true; |
| 445 | } |
| 446 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 447 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 448 | intel_hdmi_detect(struct drm_connector *connector, bool force) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 449 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 450 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 451 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 452 | struct edid *edid; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 453 | enum drm_connector_status status = connector_status_disconnected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 454 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 455 | intel_hdmi->has_hdmi_sink = false; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 456 | intel_hdmi->has_audio = false; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 457 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 458 | intel_gmbus_get_adapter(dev_priv, |
| 459 | intel_hdmi->ddc_bus)); |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 460 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 461 | if (edid) { |
Eric Anholt | be9f1c4 | 2009-06-21 22:14:55 -0700 | [diff] [blame] | 462 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 463 | status = connector_status_connected; |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 464 | if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI) |
| 465 | intel_hdmi->has_hdmi_sink = |
| 466 | drm_detect_hdmi_monitor(edid); |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 467 | intel_hdmi->has_audio = drm_detect_monitor_audio(edid); |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 468 | } |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 469 | connector->display_info.raw_edid = NULL; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 470 | kfree(edid); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 471 | } |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 472 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 473 | if (status == connector_status_connected) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 474 | if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO) |
| 475 | intel_hdmi->has_audio = |
| 476 | (intel_hdmi->force_audio == HDMI_AUDIO_ON); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 479 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 480 | } |
| 481 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 482 | static int intel_hdmi_get_modes(struct drm_connector *connector) |
| 483 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 484 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 485 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 486 | |
| 487 | /* We should parse the EDID data and find out if it's an HDMI sink so |
| 488 | * we can send audio to it. |
| 489 | */ |
| 490 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 491 | return intel_ddc_get_modes(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 492 | intel_gmbus_get_adapter(dev_priv, |
| 493 | intel_hdmi->ddc_bus)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 496 | static bool |
| 497 | intel_hdmi_detect_audio(struct drm_connector *connector) |
| 498 | { |
| 499 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 500 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 501 | struct edid *edid; |
| 502 | bool has_audio = false; |
| 503 | |
| 504 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 505 | intel_gmbus_get_adapter(dev_priv, |
| 506 | intel_hdmi->ddc_bus)); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 507 | if (edid) { |
| 508 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 509 | has_audio = drm_detect_monitor_audio(edid); |
| 510 | |
| 511 | connector->display_info.raw_edid = NULL; |
| 512 | kfree(edid); |
| 513 | } |
| 514 | |
| 515 | return has_audio; |
| 516 | } |
| 517 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 518 | static int |
| 519 | intel_hdmi_set_property(struct drm_connector *connector, |
| 520 | struct drm_property *property, |
| 521 | uint64_t val) |
| 522 | { |
| 523 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 524 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 525 | int ret; |
| 526 | |
| 527 | ret = drm_connector_property_set_value(connector, property, val); |
| 528 | if (ret) |
| 529 | return ret; |
| 530 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 531 | if (property == dev_priv->force_audio_property) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 532 | enum hdmi_force_audio i = val; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 533 | bool has_audio; |
| 534 | |
| 535 | if (i == intel_hdmi->force_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 536 | return 0; |
| 537 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 538 | intel_hdmi->force_audio = i; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 539 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 540 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 541 | has_audio = intel_hdmi_detect_audio(connector); |
| 542 | else |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 543 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 544 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 545 | if (i == HDMI_AUDIO_OFF_DVI) |
| 546 | intel_hdmi->has_hdmi_sink = 0; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 547 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 548 | intel_hdmi->has_audio = has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 549 | goto done; |
| 550 | } |
| 551 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 552 | if (property == dev_priv->broadcast_rgb_property) { |
| 553 | if (val == !!intel_hdmi->color_range) |
| 554 | return 0; |
| 555 | |
| 556 | intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0; |
| 557 | goto done; |
| 558 | } |
| 559 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 560 | return -EINVAL; |
| 561 | |
| 562 | done: |
| 563 | if (intel_hdmi->base.base.crtc) { |
| 564 | struct drm_crtc *crtc = intel_hdmi->base.base.crtc; |
| 565 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 566 | crtc->x, crtc->y, |
| 567 | crtc->fb); |
| 568 | } |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 573 | static void intel_hdmi_destroy(struct drm_connector *connector) |
| 574 | { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 575 | drm_sysfs_connector_remove(connector); |
| 576 | drm_connector_cleanup(connector); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 577 | kfree(connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { |
| 581 | .dpms = intel_hdmi_dpms, |
| 582 | .mode_fixup = intel_hdmi_mode_fixup, |
| 583 | .prepare = intel_encoder_prepare, |
| 584 | .mode_set = intel_hdmi_mode_set, |
| 585 | .commit = intel_encoder_commit, |
| 586 | }; |
| 587 | |
| 588 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 589 | .dpms = drm_helper_connector_dpms, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 590 | .detect = intel_hdmi_detect, |
| 591 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 592 | .set_property = intel_hdmi_set_property, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 593 | .destroy = intel_hdmi_destroy, |
| 594 | }; |
| 595 | |
| 596 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { |
| 597 | .get_modes = intel_hdmi_get_modes, |
| 598 | .mode_valid = intel_hdmi_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 599 | .best_encoder = intel_best_encoder, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 600 | }; |
| 601 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 602 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 603 | .destroy = intel_encoder_destroy, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 604 | }; |
| 605 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 606 | static void |
| 607 | intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector) |
| 608 | { |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 609 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 610 | intel_attach_broadcast_rgb_property(connector); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 611 | } |
| 612 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 613 | void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) |
| 614 | { |
| 615 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 616 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 617 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 618 | struct intel_connector *intel_connector; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 619 | struct intel_hdmi *intel_hdmi; |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 620 | int i; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 621 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 622 | intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL); |
| 623 | if (!intel_hdmi) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 624 | return; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 625 | |
| 626 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 627 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 628 | kfree(intel_hdmi); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 632 | intel_encoder = &intel_hdmi->base; |
Chris Wilson | 373a3cf | 2010-09-15 12:03:59 +0100 | [diff] [blame] | 633 | drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs, |
| 634 | DRM_MODE_ENCODER_TMDS); |
| 635 | |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 636 | connector = &intel_connector->base; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 637 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, |
Adam Jackson | 8d91104 | 2009-09-23 15:08:29 -0400 | [diff] [blame] | 638 | DRM_MODE_CONNECTOR_HDMIA); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 639 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
| 640 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 641 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 642 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 643 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Peter Ross | c3febcc | 2012-01-28 14:49:26 +0100 | [diff] [blame] | 644 | connector->interlace_allowed = 1; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 645 | connector->doublescan_allowed = 0; |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 646 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 647 | |
| 648 | /* Set up the DDC bus. */ |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 649 | if (sdvox_reg == SDVOB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 650 | intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 651 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 652 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 653 | } else if (sdvox_reg == SDVOC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 654 | intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 655 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 656 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 657 | } else if (sdvox_reg == HDMIB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 658 | intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 659 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 660 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 661 | } else if (sdvox_reg == HDMIC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 662 | intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 663 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 664 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 665 | } else if (sdvox_reg == HDMID) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 666 | intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 667 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 668 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 669 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 670 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 671 | intel_hdmi->sdvox_reg = sdvox_reg; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 672 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 673 | if (!HAS_PCH_SPLIT(dev)) { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 674 | intel_hdmi->write_infoframe = i9xx_write_infoframe; |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 675 | I915_WRITE(VIDEO_DIP_CTL, 0); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 676 | } else if (IS_VALLEYVIEW(dev)) { |
| 677 | intel_hdmi->write_infoframe = vlv_write_infoframe; |
| 678 | for_each_pipe(i) |
| 679 | I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 680 | } else if (HAS_PCH_IBX(dev)) { |
| 681 | intel_hdmi->write_infoframe = ibx_write_infoframe; |
| 682 | for_each_pipe(i) |
| 683 | I915_WRITE(TVIDEO_DIP_CTL(i), 0); |
| 684 | } else { |
| 685 | intel_hdmi->write_infoframe = cpt_write_infoframe; |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 686 | for_each_pipe(i) |
| 687 | I915_WRITE(TVIDEO_DIP_CTL(i), 0); |
| 688 | } |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 689 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 690 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 691 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 692 | intel_hdmi_add_properties(intel_hdmi, connector); |
| 693 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 694 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 695 | drm_sysfs_connector_add(connector); |
| 696 | |
| 697 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 698 | * 0xd. Failure to do so will result in spurious interrupts being |
| 699 | * generated on the port when a cable is not attached. |
| 700 | */ |
| 701 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 702 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 703 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 704 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 705 | } |