drm/i915: Track whether cursor needs physical address in intel_device_info
[linux-2.6-block.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>
30#include <linux/delay.h>
31#include "drmP.h"
32#include "drm.h"
33#include "drm_crtc.h"
aa93d632 34#include "drm_edid.h"
7d57382e
EA
35#include "intel_drv.h"
36#include "i915_drm.h"
37#include "i915_drv.h"
38
39struct intel_hdmi_priv {
40 u32 sdvox_reg;
41 u32 save_SDVOX;
9dff6af8 42 bool has_hdmi_sink;
7d57382e
EA
43};
44
45static void intel_hdmi_mode_set(struct drm_encoder *encoder,
46 struct drm_display_mode *mode,
47 struct drm_display_mode *adjusted_mode)
48{
49 struct drm_device *dev = encoder->dev;
50 struct drm_i915_private *dev_priv = dev->dev_private;
51 struct drm_crtc *crtc = encoder->crtc;
52 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
53 struct intel_output *intel_output = enc_to_intel_output(encoder);
54 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
55 u32 sdvox;
56
57 sdvox = SDVO_ENCODING_HDMI |
58 SDVO_BORDER_ENABLE |
59 SDVO_VSYNC_ACTIVE_HIGH |
56d21b07 60 SDVO_HSYNC_ACTIVE_HIGH;
7d57382e
EA
61
62 if (hdmi_priv->has_hdmi_sink)
63 sdvox |= SDVO_AUDIO_ENABLE;
64
65 if (intel_crtc->pipe == 1)
66 sdvox |= SDVO_PIPE_B_SELECT;
67
68 I915_WRITE(hdmi_priv->sdvox_reg, sdvox);
69 POSTING_READ(hdmi_priv->sdvox_reg);
70}
71
72static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
73{
74 struct drm_device *dev = encoder->dev;
75 struct drm_i915_private *dev_priv = dev->dev_private;
76 struct intel_output *intel_output = enc_to_intel_output(encoder);
77 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
78 u32 temp;
79
d8a2d0e0
ZW
80 temp = I915_READ(hdmi_priv->sdvox_reg);
81
82 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
83 * we do this anyway which shows more stable in testing.
84 */
f2b115e6 85 if (IS_IRONLAKE(dev)) {
7d57382e 86 I915_WRITE(hdmi_priv->sdvox_reg, temp & ~SDVO_ENABLE);
d8a2d0e0
ZW
87 POSTING_READ(hdmi_priv->sdvox_reg);
88 }
89
90 if (mode != DRM_MODE_DPMS_ON) {
91 temp &= ~SDVO_ENABLE;
7d57382e 92 } else {
d8a2d0e0 93 temp |= SDVO_ENABLE;
7d57382e 94 }
d8a2d0e0
ZW
95
96 I915_WRITE(hdmi_priv->sdvox_reg, temp);
7d57382e 97 POSTING_READ(hdmi_priv->sdvox_reg);
d8a2d0e0
ZW
98
99 /* HW workaround, need to write this twice for issue that may result
100 * in first write getting masked.
101 */
f2b115e6 102 if (IS_IRONLAKE(dev)) {
d8a2d0e0
ZW
103 I915_WRITE(hdmi_priv->sdvox_reg, temp);
104 POSTING_READ(hdmi_priv->sdvox_reg);
105 }
7d57382e
EA
106}
107
108static void intel_hdmi_save(struct drm_connector *connector)
109{
110 struct drm_device *dev = connector->dev;
111 struct drm_i915_private *dev_priv = dev->dev_private;
112 struct intel_output *intel_output = to_intel_output(connector);
113 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
114
115 hdmi_priv->save_SDVOX = I915_READ(hdmi_priv->sdvox_reg);
116}
117
118static void intel_hdmi_restore(struct drm_connector *connector)
119{
120 struct drm_device *dev = connector->dev;
121 struct drm_i915_private *dev_priv = dev->dev_private;
122 struct intel_output *intel_output = to_intel_output(connector);
123 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
124
125 I915_WRITE(hdmi_priv->sdvox_reg, hdmi_priv->save_SDVOX);
126 POSTING_READ(hdmi_priv->sdvox_reg);
127}
128
129static int intel_hdmi_mode_valid(struct drm_connector *connector,
130 struct drm_display_mode *mode)
131{
132 if (mode->clock > 165000)
133 return MODE_CLOCK_HIGH;
134 if (mode->clock < 20000)
135 return MODE_CLOCK_HIGH;
136
137 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
138 return MODE_NO_DBLESCAN;
139
140 return MODE_OK;
141}
142
143static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
144 struct drm_display_mode *mode,
145 struct drm_display_mode *adjusted_mode)
146{
147 return true;
148}
149
aa93d632 150static enum drm_connector_status
2ded9e27 151intel_hdmi_detect(struct drm_connector *connector)
9dff6af8
ML
152{
153 struct intel_output *intel_output = to_intel_output(connector);
154 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
155 struct edid *edid = NULL;
aa93d632 156 enum drm_connector_status status = connector_status_disconnected;
9dff6af8 157
2ded9e27 158 hdmi_priv->has_hdmi_sink = false;
9dff6af8 159 edid = drm_get_edid(&intel_output->base,
f9c10a9b 160 intel_output->ddc_bus);
2ded9e27 161
aa93d632 162 if (edid) {
be9f1c4f 163 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
aa93d632
KP
164 status = connector_status_connected;
165 hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
166 }
9dff6af8 167 intel_output->base.display_info.raw_edid = NULL;
aa93d632 168 kfree(edid);
9dff6af8 169 }
30ad48b7 170
2ded9e27 171 return status;
7d57382e
EA
172}
173
174static int intel_hdmi_get_modes(struct drm_connector *connector)
175{
176 struct intel_output *intel_output = to_intel_output(connector);
177
178 /* We should parse the EDID data and find out if it's an HDMI sink so
179 * we can send audio to it.
180 */
181
182 return intel_ddc_get_modes(intel_output);
183}
184
185static void intel_hdmi_destroy(struct drm_connector *connector)
186{
187 struct intel_output *intel_output = to_intel_output(connector);
188
189 if (intel_output->i2c_bus)
190 intel_i2c_destroy(intel_output->i2c_bus);
191 drm_sysfs_connector_remove(connector);
192 drm_connector_cleanup(connector);
193 kfree(intel_output);
194}
195
196static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
197 .dpms = intel_hdmi_dpms,
198 .mode_fixup = intel_hdmi_mode_fixup,
199 .prepare = intel_encoder_prepare,
200 .mode_set = intel_hdmi_mode_set,
201 .commit = intel_encoder_commit,
202};
203
204static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
c9fb15f6 205 .dpms = drm_helper_connector_dpms,
7d57382e
EA
206 .save = intel_hdmi_save,
207 .restore = intel_hdmi_restore,
208 .detect = intel_hdmi_detect,
209 .fill_modes = drm_helper_probe_single_connector_modes,
210 .destroy = intel_hdmi_destroy,
211};
212
213static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
214 .get_modes = intel_hdmi_get_modes,
215 .mode_valid = intel_hdmi_mode_valid,
216 .best_encoder = intel_best_encoder,
217};
218
219static void intel_hdmi_enc_destroy(struct drm_encoder *encoder)
220{
221 drm_encoder_cleanup(encoder);
222}
223
224static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
225 .destroy = intel_hdmi_enc_destroy,
226};
227
fc816655
ZY
228/*
229 * Enumerate the child dev array parsed from VBT to check whether
230 * the given HDMI is present.
231 * If it is present, return 1.
232 * If it is not present, return false.
233 * If no child dev is parsed from VBT, it assumes that the given
234 * HDMI is present.
235 */
6e36595a 236static int hdmi_is_present_in_vbt(struct drm_device *dev, int hdmi_reg)
fc816655
ZY
237{
238 struct drm_i915_private *dev_priv = dev->dev_private;
239 struct child_device_config *p_child;
240 int i, hdmi_port, ret;
241
242 if (!dev_priv->child_dev_num)
243 return 1;
244
245 if (hdmi_reg == SDVOB)
246 hdmi_port = DVO_B;
247 else if (hdmi_reg == SDVOC)
248 hdmi_port = DVO_C;
249 else if (hdmi_reg == HDMIB)
250 hdmi_port = DVO_B;
251 else if (hdmi_reg == HDMIC)
252 hdmi_port = DVO_C;
253 else if (hdmi_reg == HDMID)
254 hdmi_port = DVO_D;
255 else
256 return 0;
257
258 ret = 0;
259 for (i = 0; i < dev_priv->child_dev_num; i++) {
260 p_child = dev_priv->child_dev + i;
261 /*
262 * If the device type is not HDMI, continue.
263 */
264 if (p_child->device_type != DEVICE_TYPE_HDMI)
265 continue;
266 /* Find the HDMI port */
267 if (p_child->dvo_port == hdmi_port) {
268 ret = 1;
269 break;
270 }
271 }
272 return ret;
273}
7d57382e
EA
274void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
275{
276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct drm_connector *connector;
278 struct intel_output *intel_output;
279 struct intel_hdmi_priv *hdmi_priv;
280
fc816655
ZY
281 if (!hdmi_is_present_in_vbt(dev, sdvox_reg)) {
282 DRM_DEBUG_KMS("HDMI is not present. Ignored it \n");
283 return;
284 }
7d57382e
EA
285 intel_output = kcalloc(sizeof(struct intel_output) +
286 sizeof(struct intel_hdmi_priv), 1, GFP_KERNEL);
287 if (!intel_output)
288 return;
289 hdmi_priv = (struct intel_hdmi_priv *)(intel_output + 1);
290
291 connector = &intel_output->base;
292 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
8d91104a 293 DRM_MODE_CONNECTOR_HDMIA);
7d57382e
EA
294 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
295
296 intel_output->type = INTEL_OUTPUT_HDMI;
297
298 connector->interlace_allowed = 0;
299 connector->doublescan_allowed = 0;
f8aed700 300 intel_output->crtc_mask = (1 << 0) | (1 << 1);
7d57382e
EA
301
302 /* Set up the DDC bus. */
f8aed700
ML
303 if (sdvox_reg == SDVOB) {
304 intel_output->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
7d57382e 305 intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "HDMIB");
f8aed700
ML
306 } else if (sdvox_reg == SDVOC) {
307 intel_output->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
7d57382e 308 intel_output->ddc_bus = intel_i2c_create(dev, GPIOD, "HDMIC");
f8aed700
ML
309 } else if (sdvox_reg == HDMIB) {
310 intel_output->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
30ad48b7
ZW
311 intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOE,
312 "HDMIB");
f8aed700
ML
313 } else if (sdvox_reg == HDMIC) {
314 intel_output->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
30ad48b7
ZW
315 intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOD,
316 "HDMIC");
f8aed700
ML
317 } else if (sdvox_reg == HDMID) {
318 intel_output->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
30ad48b7
ZW
319 intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOF,
320 "HDMID");
f8aed700 321 }
7d57382e
EA
322 if (!intel_output->ddc_bus)
323 goto err_connector;
324
325 hdmi_priv->sdvox_reg = sdvox_reg;
326 intel_output->dev_priv = hdmi_priv;
327
328 drm_encoder_init(dev, &intel_output->enc, &intel_hdmi_enc_funcs,
329 DRM_MODE_ENCODER_TMDS);
330 drm_encoder_helper_add(&intel_output->enc, &intel_hdmi_helper_funcs);
331
332 drm_mode_connector_attach_encoder(&intel_output->base,
333 &intel_output->enc);
334 drm_sysfs_connector_add(connector);
335
336 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
337 * 0xd. Failure to do so will result in spurious interrupts being
338 * generated on the port when a cable is not attached.
339 */
340 if (IS_G4X(dev) && !IS_GM45(dev)) {
341 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
342 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
343 }
344
345 return;
346
347err_connector:
348 drm_connector_cleanup(connector);
349 kfree(intel_output);
350
351 return;
352}