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 | |
Eugeni Dodonov | f5bbfca | 2012-05-09 15:37:30 -0300 | [diff] [blame] | 40 | struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 41 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 42 | return container_of(encoder, struct intel_hdmi, base.base); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 45 | static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector) |
| 46 | { |
| 47 | return container_of(intel_attached_encoder(connector), |
| 48 | struct intel_hdmi, base); |
| 49 | } |
| 50 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 51 | void intel_dip_infoframe_csum(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 52 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 53 | uint8_t *data = (uint8_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 54 | uint8_t sum = 0; |
| 55 | unsigned i; |
| 56 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 57 | frame->checksum = 0; |
| 58 | frame->ecc = 0; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 59 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 60 | for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 61 | sum += data[i]; |
| 62 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 63 | frame->checksum = 0x100 - sum; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 66 | static u32 g4x_infoframe_index(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 67 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 68 | switch (frame->type) { |
| 69 | case DIP_TYPE_AVI: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 70 | return VIDEO_DIP_SELECT_AVI; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 71 | case DIP_TYPE_SPD: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 72 | return VIDEO_DIP_SELECT_SPD; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 73 | default: |
| 74 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 75 | return 0; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 76 | } |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 79 | static u32 g4x_infoframe_enable(struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 80 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 81 | switch (frame->type) { |
| 82 | case DIP_TYPE_AVI: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 83 | return VIDEO_DIP_ENABLE_AVI; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 84 | case DIP_TYPE_SPD: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 85 | return VIDEO_DIP_ENABLE_SPD; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 86 | default: |
| 87 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 88 | return 0; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 89 | } |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 90 | } |
| 91 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 92 | static u32 hsw_infoframe_enable(struct dip_infoframe *frame) |
| 93 | { |
| 94 | switch (frame->type) { |
| 95 | case DIP_TYPE_AVI: |
| 96 | return VIDEO_DIP_ENABLE_AVI_HSW; |
| 97 | case DIP_TYPE_SPD: |
| 98 | return VIDEO_DIP_ENABLE_SPD_HSW; |
| 99 | default: |
| 100 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 101 | return 0; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe) |
| 106 | { |
| 107 | switch (frame->type) { |
| 108 | case DIP_TYPE_AVI: |
| 109 | return HSW_TVIDEO_DIP_AVI_DATA(pipe); |
| 110 | case DIP_TYPE_SPD: |
| 111 | return HSW_TVIDEO_DIP_SPD_DATA(pipe); |
| 112 | default: |
| 113 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 114 | return 0; |
| 115 | } |
| 116 | } |
| 117 | |
Daniel Vetter | a3da1df | 2012-05-08 15:19:06 +0200 | [diff] [blame] | 118 | static void g4x_write_infoframe(struct drm_encoder *encoder, |
| 119 | struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 120 | { |
| 121 | uint32_t *data = (uint32_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 122 | struct drm_device *dev = encoder->dev; |
| 123 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 124 | u32 val = I915_READ(VIDEO_DIP_CTL); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 125 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 126 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 127 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 128 | |
Paulo Zanoni | 1d4f85a | 2012-05-04 17:18:18 -0300 | [diff] [blame] | 129 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 130 | val |= g4x_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 131 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 132 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 133 | |
| 134 | I915_WRITE(VIDEO_DIP_CTL, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 135 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 136 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 137 | for (i = 0; i < len; i += 4) { |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 138 | I915_WRITE(VIDEO_DIP_DATA, *data); |
| 139 | data++; |
| 140 | } |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 141 | mmiowb(); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 142 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 143 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 144 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 145 | val |= VIDEO_DIP_FREQ_VSYNC; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 146 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 147 | I915_WRITE(VIDEO_DIP_CTL, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 148 | POSTING_READ(VIDEO_DIP_CTL); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 151 | static void ibx_write_infoframe(struct drm_encoder *encoder, |
| 152 | struct dip_infoframe *frame) |
| 153 | { |
| 154 | uint32_t *data = (uint32_t *)frame; |
| 155 | struct drm_device *dev = encoder->dev; |
| 156 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 157 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 158 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 159 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
| 160 | u32 val = I915_READ(reg); |
| 161 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 162 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 163 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 164 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 165 | val |= g4x_infoframe_index(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 166 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 167 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 168 | |
| 169 | I915_WRITE(reg, val); |
| 170 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 171 | mmiowb(); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 172 | for (i = 0; i < len; i += 4) { |
| 173 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 174 | data++; |
| 175 | } |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 176 | mmiowb(); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 177 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 178 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 179 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 180 | val |= VIDEO_DIP_FREQ_VSYNC; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 181 | |
| 182 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 183 | POSTING_READ(reg); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void cpt_write_infoframe(struct drm_encoder *encoder, |
| 187 | struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 188 | { |
| 189 | uint32_t *data = (uint32_t *)frame; |
| 190 | struct drm_device *dev = encoder->dev; |
| 191 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 192 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 193 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 194 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 195 | u32 val = I915_READ(reg); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 196 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 197 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 198 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 199 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 200 | val |= g4x_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 201 | |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 202 | /* The DIP control register spec says that we need to update the AVI |
| 203 | * infoframe without clearing its enable bit */ |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 204 | if (frame->type != DIP_TYPE_AVI) |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 205 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 206 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 207 | I915_WRITE(reg, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 208 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 209 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 210 | for (i = 0; i < len; i += 4) { |
| 211 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 212 | data++; |
| 213 | } |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 214 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 215 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 216 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 217 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 218 | val |= VIDEO_DIP_FREQ_VSYNC; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 219 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 220 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 221 | POSTING_READ(reg); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 222 | } |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 223 | |
| 224 | static void vlv_write_infoframe(struct drm_encoder *encoder, |
| 225 | struct dip_infoframe *frame) |
| 226 | { |
| 227 | uint32_t *data = (uint32_t *)frame; |
| 228 | struct drm_device *dev = encoder->dev; |
| 229 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 230 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 231 | int reg = VLV_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); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 234 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 235 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 236 | |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 237 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 238 | val |= g4x_infoframe_index(frame); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 239 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 240 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 241 | |
| 242 | I915_WRITE(reg, val); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 243 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 244 | mmiowb(); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 245 | for (i = 0; i < len; i += 4) { |
| 246 | I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 247 | data++; |
| 248 | } |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 249 | mmiowb(); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 250 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 251 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 252 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 253 | val |= VIDEO_DIP_FREQ_VSYNC; |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 254 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 255 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 256 | POSTING_READ(reg); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 259 | static void hsw_write_infoframe(struct drm_encoder *encoder, |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 260 | struct dip_infoframe *frame) |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 261 | { |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 262 | uint32_t *data = (uint32_t *)frame; |
| 263 | struct drm_device *dev = encoder->dev; |
| 264 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 265 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 266 | u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 267 | u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe); |
| 268 | unsigned int i, len = DIP_HEADER_SIZE + frame->len; |
| 269 | u32 val = I915_READ(ctl_reg); |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 270 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 271 | if (data_reg == 0) |
| 272 | return; |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 273 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 274 | val &= ~hsw_infoframe_enable(frame); |
| 275 | I915_WRITE(ctl_reg, val); |
| 276 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 277 | mmiowb(); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 278 | for (i = 0; i < len; i += 4) { |
| 279 | I915_WRITE(data_reg + i, *data); |
| 280 | data++; |
| 281 | } |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 282 | mmiowb(); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 283 | |
| 284 | val |= hsw_infoframe_enable(frame); |
| 285 | I915_WRITE(ctl_reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 286 | POSTING_READ(ctl_reg); |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 287 | } |
| 288 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 289 | static void intel_set_infoframe(struct drm_encoder *encoder, |
| 290 | struct dip_infoframe *frame) |
| 291 | { |
| 292 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 293 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 294 | intel_dip_infoframe_csum(frame); |
| 295 | intel_hdmi->write_infoframe(encoder, frame); |
| 296 | } |
| 297 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 298 | static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder, |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 299 | struct drm_display_mode *adjusted_mode) |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 300 | { |
| 301 | struct dip_infoframe avi_if = { |
| 302 | .type = DIP_TYPE_AVI, |
| 303 | .ver = DIP_VERSION_AVI, |
| 304 | .len = DIP_LEN_AVI, |
| 305 | }; |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 306 | |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 307 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 308 | avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2; |
| 309 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 310 | intel_set_infoframe(encoder, &avi_if); |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 313 | static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder) |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 314 | { |
| 315 | struct dip_infoframe spd_if; |
| 316 | |
| 317 | memset(&spd_if, 0, sizeof(spd_if)); |
| 318 | spd_if.type = DIP_TYPE_SPD; |
| 319 | spd_if.ver = DIP_VERSION_SPD; |
| 320 | spd_if.len = DIP_LEN_SPD; |
| 321 | strcpy(spd_if.body.spd.vn, "Intel"); |
| 322 | strcpy(spd_if.body.spd.pd, "Integrated gfx"); |
| 323 | spd_if.body.spd.sdi = DIP_SPD_PC; |
| 324 | |
| 325 | intel_set_infoframe(encoder, &spd_if); |
| 326 | } |
| 327 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 328 | static void g4x_set_infoframes(struct drm_encoder *encoder, |
| 329 | struct drm_display_mode *adjusted_mode) |
| 330 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 331 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 332 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 333 | u32 reg = VIDEO_DIP_CTL; |
| 334 | u32 val = I915_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 335 | u32 port; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 336 | |
| 337 | /* If the registers were not initialized yet, they might be zeroes, |
| 338 | * which means we're selecting the AVI DIP and we're setting its |
| 339 | * frequency to once. This seems to really confuse the HW and make |
| 340 | * things stop working (the register spec says the AVI always needs to |
| 341 | * be sent every VSync). So here we avoid writing to the register more |
| 342 | * than we need and also explicitly select the AVI DIP and explicitly |
| 343 | * set its frequency to every VSync. Avoiding to write it twice seems to |
| 344 | * be enough to solve the problem, but being defensive shouldn't hurt us |
| 345 | * either. */ |
| 346 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 347 | |
| 348 | if (!intel_hdmi->has_hdmi_sink) { |
| 349 | if (!(val & VIDEO_DIP_ENABLE)) |
| 350 | return; |
| 351 | val &= ~VIDEO_DIP_ENABLE; |
| 352 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 353 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 357 | switch (intel_hdmi->sdvox_reg) { |
| 358 | case SDVOB: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 359 | port = VIDEO_DIP_PORT_B; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 360 | break; |
| 361 | case SDVOC: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 362 | port = VIDEO_DIP_PORT_C; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 363 | break; |
| 364 | default: |
| 365 | return; |
| 366 | } |
| 367 | |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 368 | if (port != (val & VIDEO_DIP_PORT_MASK)) { |
| 369 | if (val & VIDEO_DIP_ENABLE) { |
| 370 | val &= ~VIDEO_DIP_ENABLE; |
| 371 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 372 | POSTING_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 373 | } |
| 374 | val &= ~VIDEO_DIP_PORT_MASK; |
| 375 | val |= port; |
| 376 | } |
| 377 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 378 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 379 | val &= ~VIDEO_DIP_ENABLE_VENDOR; |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 380 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 381 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 382 | POSTING_READ(reg); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 383 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 384 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 385 | intel_hdmi_set_spd_infoframe(encoder); |
| 386 | } |
| 387 | |
| 388 | static void ibx_set_infoframes(struct drm_encoder *encoder, |
| 389 | struct drm_display_mode *adjusted_mode) |
| 390 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 391 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 392 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 393 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 394 | u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 395 | u32 val = I915_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 396 | u32 port; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 397 | |
| 398 | /* See the big comment in g4x_set_infoframes() */ |
| 399 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 400 | |
| 401 | if (!intel_hdmi->has_hdmi_sink) { |
| 402 | if (!(val & VIDEO_DIP_ENABLE)) |
| 403 | return; |
| 404 | val &= ~VIDEO_DIP_ENABLE; |
| 405 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 406 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 407 | return; |
| 408 | } |
| 409 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 410 | switch (intel_hdmi->sdvox_reg) { |
| 411 | case HDMIB: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 412 | port = VIDEO_DIP_PORT_B; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 413 | break; |
| 414 | case HDMIC: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 415 | port = VIDEO_DIP_PORT_C; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 416 | break; |
| 417 | case HDMID: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 418 | port = VIDEO_DIP_PORT_D; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 419 | break; |
| 420 | default: |
| 421 | return; |
| 422 | } |
| 423 | |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 424 | if (port != (val & VIDEO_DIP_PORT_MASK)) { |
| 425 | if (val & VIDEO_DIP_ENABLE) { |
| 426 | val &= ~VIDEO_DIP_ENABLE; |
| 427 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 428 | POSTING_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 429 | } |
| 430 | val &= ~VIDEO_DIP_PORT_MASK; |
| 431 | val |= port; |
| 432 | } |
| 433 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 434 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 435 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 436 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 437 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 438 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 439 | POSTING_READ(reg); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 440 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 441 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 442 | intel_hdmi_set_spd_infoframe(encoder); |
| 443 | } |
| 444 | |
| 445 | static void cpt_set_infoframes(struct drm_encoder *encoder, |
| 446 | struct drm_display_mode *adjusted_mode) |
| 447 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 448 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 449 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 450 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 451 | u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 452 | u32 val = I915_READ(reg); |
| 453 | |
| 454 | /* See the big comment in g4x_set_infoframes() */ |
| 455 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 456 | |
| 457 | if (!intel_hdmi->has_hdmi_sink) { |
| 458 | if (!(val & VIDEO_DIP_ENABLE)) |
| 459 | return; |
| 460 | val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI); |
| 461 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 462 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 463 | return; |
| 464 | } |
| 465 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 466 | /* Set both together, unset both together: see the spec. */ |
| 467 | val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 468 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 469 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 470 | |
| 471 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 472 | POSTING_READ(reg); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 473 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 474 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 475 | intel_hdmi_set_spd_infoframe(encoder); |
| 476 | } |
| 477 | |
| 478 | static void vlv_set_infoframes(struct drm_encoder *encoder, |
| 479 | struct drm_display_mode *adjusted_mode) |
| 480 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 481 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 482 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 483 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 484 | u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 485 | u32 val = I915_READ(reg); |
| 486 | |
| 487 | /* See the big comment in g4x_set_infoframes() */ |
| 488 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 489 | |
| 490 | if (!intel_hdmi->has_hdmi_sink) { |
| 491 | if (!(val & VIDEO_DIP_ENABLE)) |
| 492 | return; |
| 493 | val &= ~VIDEO_DIP_ENABLE; |
| 494 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 495 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 496 | return; |
| 497 | } |
| 498 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 499 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 500 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 501 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 502 | |
| 503 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 504 | POSTING_READ(reg); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 505 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 506 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 507 | intel_hdmi_set_spd_infoframe(encoder); |
| 508 | } |
| 509 | |
| 510 | static void hsw_set_infoframes(struct drm_encoder *encoder, |
| 511 | struct drm_display_mode *adjusted_mode) |
| 512 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 513 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 514 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 515 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 516 | u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe); |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 517 | u32 val = I915_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 518 | |
| 519 | if (!intel_hdmi->has_hdmi_sink) { |
| 520 | I915_WRITE(reg, 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 521 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 522 | return; |
| 523 | } |
| 524 | |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 525 | val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW | |
| 526 | VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW); |
| 527 | |
| 528 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame^] | 529 | POSTING_READ(reg); |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 530 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 531 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 532 | intel_hdmi_set_spd_infoframe(encoder); |
| 533 | } |
| 534 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 535 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, |
| 536 | struct drm_display_mode *mode, |
| 537 | struct drm_display_mode *adjusted_mode) |
| 538 | { |
| 539 | struct drm_device *dev = encoder->dev; |
| 540 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 541 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 542 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 543 | u32 sdvox; |
| 544 | |
Paulo Zanoni | b659c3d | 2012-05-28 16:42:56 -0300 | [diff] [blame] | 545 | sdvox = SDVO_ENCODING_HDMI; |
Jesse Barnes | 5d4fac9 | 2011-06-24 12:19:19 -0700 | [diff] [blame] | 546 | if (!HAS_PCH_SPLIT(dev)) |
| 547 | sdvox |= intel_hdmi->color_range; |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 548 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 549 | sdvox |= SDVO_VSYNC_ACTIVE_HIGH; |
| 550 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 551 | sdvox |= SDVO_HSYNC_ACTIVE_HIGH; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 552 | |
Jesse Barnes | 020f670 | 2011-06-24 12:19:25 -0700 | [diff] [blame] | 553 | if (intel_crtc->bpp > 24) |
| 554 | sdvox |= COLOR_FORMAT_12bpc; |
| 555 | else |
| 556 | sdvox |= COLOR_FORMAT_8bpc; |
| 557 | |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 558 | /* Required on CPT */ |
| 559 | if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev)) |
| 560 | sdvox |= HDMI_MODE_SELECT; |
| 561 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 562 | if (intel_hdmi->has_audio) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 563 | DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n", |
| 564 | pipe_name(intel_crtc->pipe)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 565 | sdvox |= SDVO_AUDIO_ENABLE; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 566 | sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 567 | intel_write_eld(encoder, adjusted_mode); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 568 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 569 | |
Jesse Barnes | 7577056 | 2011-10-12 09:01:58 -0700 | [diff] [blame] | 570 | if (HAS_PCH_CPT(dev)) |
| 571 | sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe); |
| 572 | else if (intel_crtc->pipe == 1) |
| 573 | sdvox |= SDVO_PIPE_B_SELECT; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 574 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 575 | I915_WRITE(intel_hdmi->sdvox_reg, sdvox); |
| 576 | POSTING_READ(intel_hdmi->sdvox_reg); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 577 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 578 | intel_hdmi->set_infoframes(encoder, adjusted_mode); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) |
| 582 | { |
| 583 | struct drm_device *dev = encoder->dev; |
| 584 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 585 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 586 | u32 temp; |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 587 | u32 enable_bits = SDVO_ENABLE; |
| 588 | |
| 589 | if (intel_hdmi->has_audio) |
| 590 | enable_bits |= SDVO_AUDIO_ENABLE; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 591 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 592 | temp = I915_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 593 | |
| 594 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 595 | * we do this anyway which shows more stable in testing. |
| 596 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 597 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 598 | I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE); |
| 599 | POSTING_READ(intel_hdmi->sdvox_reg); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 600 | } |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 601 | |
| 602 | if (mode != DRM_MODE_DPMS_ON) { |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 603 | temp &= ~enable_bits; |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 604 | } else { |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 605 | temp |= enable_bits; |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 608 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 609 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 610 | |
| 611 | /* HW workaround, need to write this twice for issue that may result |
| 612 | * in first write getting masked. |
| 613 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 614 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 615 | I915_WRITE(intel_hdmi->sdvox_reg, temp); |
| 616 | POSTING_READ(intel_hdmi->sdvox_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 617 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 620 | static int intel_hdmi_mode_valid(struct drm_connector *connector, |
| 621 | struct drm_display_mode *mode) |
| 622 | { |
| 623 | if (mode->clock > 165000) |
| 624 | return MODE_CLOCK_HIGH; |
| 625 | if (mode->clock < 20000) |
Nicolas Kaiser | 5cbba41 | 2011-05-30 12:48:26 +0200 | [diff] [blame] | 626 | return MODE_CLOCK_LOW; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 627 | |
| 628 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 629 | return MODE_NO_DBLESCAN; |
| 630 | |
| 631 | return MODE_OK; |
| 632 | } |
| 633 | |
| 634 | static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, |
| 635 | struct drm_display_mode *mode, |
| 636 | struct drm_display_mode *adjusted_mode) |
| 637 | { |
| 638 | return true; |
| 639 | } |
| 640 | |
Chris Wilson | 8ec22b2 | 2012-05-11 18:01:34 +0100 | [diff] [blame] | 641 | static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi) |
| 642 | { |
| 643 | struct drm_device *dev = intel_hdmi->base.base.dev; |
| 644 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 645 | uint32_t bit; |
| 646 | |
| 647 | switch (intel_hdmi->sdvox_reg) { |
Chris Wilson | eeafaac | 2012-05-25 10:23:37 +0100 | [diff] [blame] | 648 | case SDVOB: |
Chris Wilson | 8ec22b2 | 2012-05-11 18:01:34 +0100 | [diff] [blame] | 649 | bit = HDMIB_HOTPLUG_LIVE_STATUS; |
| 650 | break; |
Chris Wilson | eeafaac | 2012-05-25 10:23:37 +0100 | [diff] [blame] | 651 | case SDVOC: |
Chris Wilson | 8ec22b2 | 2012-05-11 18:01:34 +0100 | [diff] [blame] | 652 | bit = HDMIC_HOTPLUG_LIVE_STATUS; |
| 653 | break; |
Chris Wilson | 8ec22b2 | 2012-05-11 18:01:34 +0100 | [diff] [blame] | 654 | default: |
| 655 | bit = 0; |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | return I915_READ(PORT_HOTPLUG_STAT) & bit; |
| 660 | } |
| 661 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 662 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 663 | intel_hdmi_detect(struct drm_connector *connector, bool force) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 664 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 665 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 666 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 667 | struct edid *edid; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 668 | enum drm_connector_status status = connector_status_disconnected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 669 | |
Chris Wilson | 8ec22b2 | 2012-05-11 18:01:34 +0100 | [diff] [blame] | 670 | if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi)) |
| 671 | return status; |
| 672 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 673 | intel_hdmi->has_hdmi_sink = false; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 674 | intel_hdmi->has_audio = false; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 675 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 676 | intel_gmbus_get_adapter(dev_priv, |
| 677 | intel_hdmi->ddc_bus)); |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 678 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 679 | if (edid) { |
Eric Anholt | be9f1c4 | 2009-06-21 22:14:55 -0700 | [diff] [blame] | 680 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 681 | status = connector_status_connected; |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 682 | if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI) |
| 683 | intel_hdmi->has_hdmi_sink = |
| 684 | drm_detect_hdmi_monitor(edid); |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 685 | intel_hdmi->has_audio = drm_detect_monitor_audio(edid); |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 686 | } |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 687 | connector->display_info.raw_edid = NULL; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 688 | kfree(edid); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 689 | } |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 690 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 691 | if (status == connector_status_connected) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 692 | if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO) |
| 693 | intel_hdmi->has_audio = |
| 694 | (intel_hdmi->force_audio == HDMI_AUDIO_ON); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 697 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 698 | } |
| 699 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 700 | static int intel_hdmi_get_modes(struct drm_connector *connector) |
| 701 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 702 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 703 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 704 | |
| 705 | /* We should parse the EDID data and find out if it's an HDMI sink so |
| 706 | * we can send audio to it. |
| 707 | */ |
| 708 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 709 | return intel_ddc_get_modes(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 710 | intel_gmbus_get_adapter(dev_priv, |
| 711 | intel_hdmi->ddc_bus)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 714 | static bool |
| 715 | intel_hdmi_detect_audio(struct drm_connector *connector) |
| 716 | { |
| 717 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 718 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 719 | struct edid *edid; |
| 720 | bool has_audio = false; |
| 721 | |
| 722 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 723 | intel_gmbus_get_adapter(dev_priv, |
| 724 | intel_hdmi->ddc_bus)); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 725 | if (edid) { |
| 726 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 727 | has_audio = drm_detect_monitor_audio(edid); |
| 728 | |
| 729 | connector->display_info.raw_edid = NULL; |
| 730 | kfree(edid); |
| 731 | } |
| 732 | |
| 733 | return has_audio; |
| 734 | } |
| 735 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 736 | static int |
| 737 | intel_hdmi_set_property(struct drm_connector *connector, |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 738 | struct drm_property *property, |
| 739 | uint64_t val) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 740 | { |
| 741 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 742 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 743 | int ret; |
| 744 | |
| 745 | ret = drm_connector_property_set_value(connector, property, val); |
| 746 | if (ret) |
| 747 | return ret; |
| 748 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 749 | if (property == dev_priv->force_audio_property) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 750 | enum hdmi_force_audio i = val; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 751 | bool has_audio; |
| 752 | |
| 753 | if (i == intel_hdmi->force_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 754 | return 0; |
| 755 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 756 | intel_hdmi->force_audio = i; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 757 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 758 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 759 | has_audio = intel_hdmi_detect_audio(connector); |
| 760 | else |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 761 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 762 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 763 | if (i == HDMI_AUDIO_OFF_DVI) |
| 764 | intel_hdmi->has_hdmi_sink = 0; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 765 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 766 | intel_hdmi->has_audio = has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 767 | goto done; |
| 768 | } |
| 769 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 770 | if (property == dev_priv->broadcast_rgb_property) { |
| 771 | if (val == !!intel_hdmi->color_range) |
| 772 | return 0; |
| 773 | |
| 774 | intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0; |
| 775 | goto done; |
| 776 | } |
| 777 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 778 | return -EINVAL; |
| 779 | |
| 780 | done: |
| 781 | if (intel_hdmi->base.base.crtc) { |
| 782 | struct drm_crtc *crtc = intel_hdmi->base.base.crtc; |
| 783 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 784 | crtc->x, crtc->y, |
| 785 | crtc->fb); |
| 786 | } |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 791 | static void intel_hdmi_destroy(struct drm_connector *connector) |
| 792 | { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 793 | drm_sysfs_connector_remove(connector); |
| 794 | drm_connector_cleanup(connector); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 795 | kfree(connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 798 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = { |
| 799 | .dpms = intel_ddi_dpms, |
| 800 | .mode_fixup = intel_hdmi_mode_fixup, |
| 801 | .prepare = intel_encoder_prepare, |
| 802 | .mode_set = intel_ddi_mode_set, |
| 803 | .commit = intel_encoder_commit, |
| 804 | }; |
| 805 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 806 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { |
| 807 | .dpms = intel_hdmi_dpms, |
| 808 | .mode_fixup = intel_hdmi_mode_fixup, |
| 809 | .prepare = intel_encoder_prepare, |
| 810 | .mode_set = intel_hdmi_mode_set, |
| 811 | .commit = intel_encoder_commit, |
| 812 | }; |
| 813 | |
| 814 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 815 | .dpms = drm_helper_connector_dpms, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 816 | .detect = intel_hdmi_detect, |
| 817 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 818 | .set_property = intel_hdmi_set_property, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 819 | .destroy = intel_hdmi_destroy, |
| 820 | }; |
| 821 | |
| 822 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { |
| 823 | .get_modes = intel_hdmi_get_modes, |
| 824 | .mode_valid = intel_hdmi_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 825 | .best_encoder = intel_best_encoder, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 826 | }; |
| 827 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 828 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 829 | .destroy = intel_encoder_destroy, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 830 | }; |
| 831 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 832 | static void |
| 833 | intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector) |
| 834 | { |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 835 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 836 | intel_attach_broadcast_rgb_property(connector); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 839 | void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) |
| 840 | { |
| 841 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 842 | struct drm_connector *connector; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 843 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 844 | struct intel_connector *intel_connector; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 845 | struct intel_hdmi *intel_hdmi; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 846 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 847 | intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL); |
| 848 | if (!intel_hdmi) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 849 | return; |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 850 | |
| 851 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 852 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 853 | kfree(intel_hdmi); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 857 | intel_encoder = &intel_hdmi->base; |
Chris Wilson | 373a3cf | 2010-09-15 12:03:59 +0100 | [diff] [blame] | 858 | drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs, |
| 859 | DRM_MODE_ENCODER_TMDS); |
| 860 | |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 861 | connector = &intel_connector->base; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 862 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, |
Adam Jackson | 8d91104 | 2009-09-23 15:08:29 -0400 | [diff] [blame] | 863 | DRM_MODE_CONNECTOR_HDMIA); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 864 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
| 865 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 866 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 867 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 868 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Peter Ross | c3febcc | 2012-01-28 14:49:26 +0100 | [diff] [blame] | 869 | connector->interlace_allowed = 1; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 870 | connector->doublescan_allowed = 0; |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 871 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 872 | |
| 873 | /* Set up the DDC bus. */ |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 874 | if (sdvox_reg == SDVOB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 875 | intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 876 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 877 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 878 | } else if (sdvox_reg == SDVOC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 879 | intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 880 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 881 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 882 | } else if (sdvox_reg == HDMIB) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 883 | intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 884 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 885 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 886 | } else if (sdvox_reg == HDMIC) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 887 | intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 888 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 889 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 890 | } else if (sdvox_reg == HDMID) { |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 891 | intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 892 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 893 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
Eugeni Dodonov | 7ceae0a | 2012-05-09 15:37:28 -0300 | [diff] [blame] | 894 | } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) { |
| 895 | DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n"); |
| 896 | intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); |
| 897 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
| 898 | intel_hdmi->ddi_port = PORT_B; |
| 899 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
| 900 | } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) { |
| 901 | DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n"); |
| 902 | intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); |
| 903 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
| 904 | intel_hdmi->ddi_port = PORT_C; |
| 905 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
| 906 | } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) { |
| 907 | DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n"); |
| 908 | intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); |
| 909 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
| 910 | intel_hdmi->ddi_port = PORT_D; |
| 911 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
Eugeni Dodonov | 6e4c167 | 2012-05-09 15:37:13 -0300 | [diff] [blame] | 912 | } else { |
| 913 | /* If we got an unknown sdvox_reg, things are pretty much broken |
| 914 | * in a way that we should let the kernel know about it */ |
| 915 | BUG(); |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 916 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 917 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 918 | intel_hdmi->sdvox_reg = sdvox_reg; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 919 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 920 | if (!HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | a3da1df | 2012-05-08 15:19:06 +0200 | [diff] [blame] | 921 | intel_hdmi->write_infoframe = g4x_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 922 | intel_hdmi->set_infoframes = g4x_set_infoframes; |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 923 | } else if (IS_VALLEYVIEW(dev)) { |
| 924 | intel_hdmi->write_infoframe = vlv_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 925 | intel_hdmi->set_infoframes = vlv_set_infoframes; |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 926 | } else if (IS_HASWELL(dev)) { |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 927 | intel_hdmi->write_infoframe = hsw_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 928 | intel_hdmi->set_infoframes = hsw_set_infoframes; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 929 | } else if (HAS_PCH_IBX(dev)) { |
| 930 | intel_hdmi->write_infoframe = ibx_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 931 | intel_hdmi->set_infoframes = ibx_set_infoframes; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 932 | } else { |
| 933 | intel_hdmi->write_infoframe = cpt_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 934 | intel_hdmi->set_infoframes = cpt_set_infoframes; |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 935 | } |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 936 | |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 937 | if (IS_HASWELL(dev)) |
| 938 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw); |
| 939 | else |
| 940 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 941 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 942 | intel_hdmi_add_properties(intel_hdmi, connector); |
| 943 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 944 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 945 | drm_sysfs_connector_add(connector); |
| 946 | |
| 947 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 948 | * 0xd. Failure to do so will result in spurious interrupts being |
| 949 | * generated on the port when a cable is not attached. |
| 950 | */ |
| 951 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 952 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 953 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 954 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 955 | } |