]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/gpu/drm/i915/intel_hdmi.c
Merge branch 'for-rmk' of git://git.pengutronix.de/git/imx/linux-2.6
[net-next-2.6.git] / drivers / gpu / drm / i915 / intel_hdmi.c
CommitLineData
7d57382e
EA
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>
5a0e3ad6 30#include <linux/slab.h>
7d57382e
EA
31#include <linux/delay.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
aa93d632 35#include "drm_edid.h"
7d57382e
EA
36#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
ea5b213a
CW
40struct intel_hdmi {
41 struct intel_encoder base;
7d57382e 42 u32 sdvox_reg;
9dff6af8 43 bool has_hdmi_sink;
7d57382e
EA
44};
45
ea5b213a
CW
46static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
47{
48 return container_of(enc_to_intel_encoder(encoder), struct intel_hdmi, base);
49}
50
7d57382e
EA
51static void intel_hdmi_mode_set(struct drm_encoder *encoder,
52 struct drm_display_mode *mode,
53 struct drm_display_mode *adjusted_mode)
54{
55 struct drm_device *dev = encoder->dev;
56 struct drm_i915_private *dev_priv = dev->dev_private;
57 struct drm_crtc *crtc = encoder->crtc;
58 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
ea5b213a 59 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
7d57382e
EA
60 u32 sdvox;
61
b599c0bc
AJ
62 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
63 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
64 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
65 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
66 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
7d57382e 67
ea5b213a 68 if (intel_hdmi->has_hdmi_sink) {
7d57382e 69 sdvox |= SDVO_AUDIO_ENABLE;
467b200d
ZW
70 if (HAS_PCH_CPT(dev))
71 sdvox |= HDMI_MODE_SELECT;
72 }
7d57382e 73
0f229062
ZW
74 if (intel_crtc->pipe == 1) {
75 if (HAS_PCH_CPT(dev))
76 sdvox |= PORT_TRANS_B_SEL_CPT;
77 else
78 sdvox |= SDVO_PIPE_B_SELECT;
79 }
7d57382e 80
ea5b213a
CW
81 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
82 POSTING_READ(intel_hdmi->sdvox_reg);
7d57382e
EA
83}
84
85static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
86{
87 struct drm_device *dev = encoder->dev;
88 struct drm_i915_private *dev_priv = dev->dev_private;
ea5b213a 89 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
7d57382e
EA
90 u32 temp;
91
ea5b213a 92 temp = I915_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
93
94 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
95 * we do this anyway which shows more stable in testing.
96 */
c619eed4 97 if (HAS_PCH_SPLIT(dev)) {
ea5b213a
CW
98 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
99 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
100 }
101
102 if (mode != DRM_MODE_DPMS_ON) {
103 temp &= ~SDVO_ENABLE;
7d57382e 104 } else {
d8a2d0e0 105 temp |= SDVO_ENABLE;
7d57382e 106 }
d8a2d0e0 107
ea5b213a
CW
108 I915_WRITE(intel_hdmi->sdvox_reg, temp);
109 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0
ZW
110
111 /* HW workaround, need to write this twice for issue that may result
112 * in first write getting masked.
113 */
c619eed4 114 if (HAS_PCH_SPLIT(dev)) {
ea5b213a
CW
115 I915_WRITE(intel_hdmi->sdvox_reg, temp);
116 POSTING_READ(intel_hdmi->sdvox_reg);
d8a2d0e0 117 }
7d57382e
EA
118}
119
7d57382e
EA
120static int intel_hdmi_mode_valid(struct drm_connector *connector,
121 struct drm_display_mode *mode)
122{
123 if (mode->clock > 165000)
124 return MODE_CLOCK_HIGH;
125 if (mode->clock < 20000)
126 return MODE_CLOCK_HIGH;
127
128 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
129 return MODE_NO_DBLESCAN;
130
131 return MODE_OK;
132}
133
134static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
135 struct drm_display_mode *mode,
136 struct drm_display_mode *adjusted_mode)
137{
138 return true;
139}
140
aa93d632 141static enum drm_connector_status
930a9e28 142intel_hdmi_detect(struct drm_connector *connector, bool force)
9dff6af8 143{
674e2d08 144 struct drm_encoder *encoder = intel_attached_encoder(connector);
ea5b213a 145 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
9dff6af8 146 struct edid *edid = NULL;
aa93d632 147 enum drm_connector_status status = connector_status_disconnected;
9dff6af8 148
ea5b213a
CW
149 intel_hdmi->has_hdmi_sink = false;
150 edid = drm_get_edid(connector, intel_hdmi->base.ddc_bus);
2ded9e27 151
aa93d632 152 if (edid) {
be9f1c4f 153 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
aa93d632 154 status = connector_status_connected;
ea5b213a 155 intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
aa93d632 156 }
674e2d08 157 connector->display_info.raw_edid = NULL;
aa93d632 158 kfree(edid);
9dff6af8 159 }
30ad48b7 160
2ded9e27 161 return status;
7d57382e
EA
162}
163
164static int intel_hdmi_get_modes(struct drm_connector *connector)
165{
674e2d08 166 struct drm_encoder *encoder = intel_attached_encoder(connector);
ea5b213a 167 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
7d57382e
EA
168
169 /* We should parse the EDID data and find out if it's an HDMI sink so
170 * we can send audio to it.
171 */
172
ea5b213a 173 return intel_ddc_get_modes(connector, intel_hdmi->base.ddc_bus);
7d57382e
EA
174}
175
176static void intel_hdmi_destroy(struct drm_connector *connector)
177{
7d57382e
EA
178 drm_sysfs_connector_remove(connector);
179 drm_connector_cleanup(connector);
674e2d08 180 kfree(connector);
7d57382e
EA
181}
182
183static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
184 .dpms = intel_hdmi_dpms,
185 .mode_fixup = intel_hdmi_mode_fixup,
186 .prepare = intel_encoder_prepare,
187 .mode_set = intel_hdmi_mode_set,
188 .commit = intel_encoder_commit,
189};
190
191static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
c9fb15f6 192 .dpms = drm_helper_connector_dpms,
7d57382e
EA
193 .detect = intel_hdmi_detect,
194 .fill_modes = drm_helper_probe_single_connector_modes,
195 .destroy = intel_hdmi_destroy,
196};
197
198static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
199 .get_modes = intel_hdmi_get_modes,
200 .mode_valid = intel_hdmi_mode_valid,
674e2d08 201 .best_encoder = intel_attached_encoder,
7d57382e
EA
202};
203
7d57382e 204static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
ea5b213a 205 .destroy = intel_encoder_destroy,
7d57382e
EA
206};
207
7d57382e
EA
208void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
209{
210 struct drm_i915_private *dev_priv = dev->dev_private;
211 struct drm_connector *connector;
21d40d37 212 struct intel_encoder *intel_encoder;
674e2d08 213 struct intel_connector *intel_connector;
ea5b213a 214 struct intel_hdmi *intel_hdmi;
7d57382e 215
ea5b213a
CW
216 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
217 if (!intel_hdmi)
7d57382e 218 return;
674e2d08
ZW
219
220 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
221 if (!intel_connector) {
ea5b213a 222 kfree(intel_hdmi);
674e2d08
ZW
223 return;
224 }
225
ea5b213a 226 intel_encoder = &intel_hdmi->base;
674e2d08 227 connector = &intel_connector->base;
7d57382e 228 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
8d91104a 229 DRM_MODE_CONNECTOR_HDMIA);
7d57382e
EA
230 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
231
21d40d37 232 intel_encoder->type = INTEL_OUTPUT_HDMI;
7d57382e 233
eb1f8e4f 234 connector->polled = DRM_CONNECTOR_POLL_HPD;
7d57382e
EA
235 connector->interlace_allowed = 0;
236 connector->doublescan_allowed = 0;
21d40d37 237 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
7d57382e
EA
238
239 /* Set up the DDC bus. */
f8aed700 240 if (sdvox_reg == SDVOB) {
21d40d37
EA
241 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
242 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "HDMIB");
b01f2c3a 243 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
f8aed700 244 } else if (sdvox_reg == SDVOC) {
21d40d37
EA
245 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
246 intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOD, "HDMIC");
b01f2c3a 247 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
f8aed700 248 } else if (sdvox_reg == HDMIB) {
21d40d37
EA
249 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
250 intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOE,
30ad48b7 251 "HDMIB");
b01f2c3a 252 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
f8aed700 253 } else if (sdvox_reg == HDMIC) {
21d40d37
EA
254 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
255 intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOD,
30ad48b7 256 "HDMIC");
b01f2c3a 257 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
f8aed700 258 } else if (sdvox_reg == HDMID) {
21d40d37
EA
259 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
260 intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOF,
30ad48b7 261 "HDMID");
b01f2c3a 262 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
f8aed700 263 }
21d40d37 264 if (!intel_encoder->ddc_bus)
7d57382e
EA
265 goto err_connector;
266
ea5b213a 267 intel_hdmi->sdvox_reg = sdvox_reg;
7d57382e 268
21d40d37 269 drm_encoder_init(dev, &intel_encoder->enc, &intel_hdmi_enc_funcs,
7d57382e 270 DRM_MODE_ENCODER_TMDS);
21d40d37 271 drm_encoder_helper_add(&intel_encoder->enc, &intel_hdmi_helper_funcs);
7d57382e 272
674e2d08 273 drm_mode_connector_attach_encoder(&intel_connector->base,
21d40d37 274 &intel_encoder->enc);
7d57382e
EA
275 drm_sysfs_connector_add(connector);
276
277 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
278 * 0xd. Failure to do so will result in spurious interrupts being
279 * generated on the port when a cable is not attached.
280 */
281 if (IS_G4X(dev) && !IS_GM45(dev)) {
282 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
283 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
284 }
285
286 return;
287
288err_connector:
289 drm_connector_cleanup(connector);
ea5b213a 290 kfree(intel_hdmi);
674e2d08 291 kfree(intel_connector);
7d57382e
EA
292
293 return;
294}