blob: d43cebdea1ee8413420c37105356ddb4a2574629 [file] [log] [blame]
Eric Anholt7d573822009-01-02 13:33:00 -08001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Eric Anholt7d573822009-01-02 13:33:00 -080031#include <linux/delay.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
Keith Packardaa93d632009-05-05 09:52:46 -070035#include "drm_edid.h"
Eric Anholt7d573822009-01-02 13:33:00 -080036#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
Chris Wilsonea5b2132010-08-04 13:50:23 +010040struct intel_hdmi {
41 struct intel_encoder base;
Eric Anholt7d573822009-01-02 13:33:00 -080042 u32 sdvox_reg;
Chris Wilsonf899fc62010-07-20 15:44:45 -070043 int ddc_bus;
Chris Wilsone953fd72011-02-21 22:23:52 +000044 uint32_t color_range;
Ma Ling9dff6af2009-04-02 13:13:26 +080045 bool has_hdmi_sink;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +080046 bool has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +010047 int force_audio;
Jesse Barnes45187ac2011-08-03 09:22:55 -070048 void (*write_infoframe)(struct drm_encoder *encoder,
49 struct dip_infoframe *frame);
Eric Anholt7d573822009-01-02 13:33:00 -080050};
51
Chris Wilsonea5b2132010-08-04 13:50:23 +010052static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
53{
Chris Wilson4ef69c72010-09-09 15:14:28 +010054 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010055}
56
Chris Wilsondf0e9242010-09-09 16:20:55 +010057static 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 Barnes45187ac2011-08-03 09:22:55 -070063void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020064{
Jesse Barnes45187ac2011-08-03 09:22:55 -070065 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020066 uint8_t sum = 0;
67 unsigned i;
68
Jesse Barnes45187ac2011-08-03 09:22:55 -070069 frame->checksum = 0;
70 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020071
Jesse Barnes45187ac2011-08-03 09:22:55 -070072 /* Header isn't part of the checksum */
73 for (i = 5; i < frame->len; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020074 sum += data[i];
75
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020077}
78
Jesse Barnes45187ac2011-08-03 09:22:55 -070079static u32 intel_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020080{
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 u32 flags = 0;
82
83 switch (frame->type) {
84 case DIP_TYPE_AVI:
85 flags |= VIDEO_DIP_SELECT_AVI;
86 break;
87 case DIP_TYPE_SPD:
88 flags |= VIDEO_DIP_SELECT_SPD;
89 break;
90 default:
91 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
92 break;
93 }
94
95 return flags;
96}
97
98static u32 intel_infoframe_flags(struct dip_infoframe *frame)
99{
100 u32 flags = 0;
101
102 switch (frame->type) {
103 case DIP_TYPE_AVI:
104 flags |= VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_FREQ_VSYNC;
105 break;
106 case DIP_TYPE_SPD:
107 flags |= VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_FREQ_2VSYNC;
108 break;
109 default:
110 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
111 break;
112 }
113
114 return flags;
115}
116
117static void i9xx_write_infoframe(struct drm_encoder *encoder,
118 struct dip_infoframe *frame)
119{
120 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200121 struct drm_device *dev = encoder->dev;
122 struct drm_i915_private *dev_priv = dev->dev_private;
123 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700124 u32 port, flags, val = I915_READ(VIDEO_DIP_CTL);
125 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200126
David Härdeman3c17fe42010-09-24 21:44:32 +0200127
128 /* XXX first guess at handling video port, is this corrent? */
129 if (intel_hdmi->sdvox_reg == SDVOB)
130 port = VIDEO_DIP_PORT_B;
131 else if (intel_hdmi->sdvox_reg == SDVOC)
132 port = VIDEO_DIP_PORT_C;
133 else
134 return;
135
Jesse Barnes45187ac2011-08-03 09:22:55 -0700136 flags = intel_infoframe_index(frame);
David Härdeman3c17fe42010-09-24 21:44:32 +0200137
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138 val &= ~VIDEO_DIP_SELECT_MASK;
139
140 I915_WRITE(VIDEO_DIP_CTL, val | port | flags);
141
142 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200143 I915_WRITE(VIDEO_DIP_DATA, *data);
144 data++;
145 }
146
Jesse Barnes45187ac2011-08-03 09:22:55 -0700147 flags |= intel_infoframe_flags(frame);
148
149 I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags);
David Härdeman3c17fe42010-09-24 21:44:32 +0200150}
151
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152static void ironlake_write_infoframe(struct drm_encoder *encoder,
153 struct dip_infoframe *frame)
154{
155 uint32_t *data = (uint32_t *)frame;
156 struct drm_device *dev = encoder->dev;
157 struct drm_i915_private *dev_priv = dev->dev_private;
158 struct drm_crtc *crtc = encoder->crtc;
159 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
160 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
161 unsigned i, len = DIP_HEADER_SIZE + frame->len;
162 u32 flags, val = I915_READ(reg);
163
164 intel_wait_for_vblank(dev, intel_crtc->pipe);
165
166 flags = intel_infoframe_index(frame);
167
168 val &= ~VIDEO_DIP_SELECT_MASK;
169
170 I915_WRITE(reg, val | flags);
171
172 for (i = 0; i < len; i += 4) {
173 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
174 data++;
175 }
176
177 flags |= intel_infoframe_flags(frame);
178
179 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
180}
181static void intel_set_infoframe(struct drm_encoder *encoder,
182 struct dip_infoframe *frame)
183{
184 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
185
186 if (!intel_hdmi->has_hdmi_sink)
187 return;
188
189 intel_dip_infoframe_csum(frame);
190 intel_hdmi->write_infoframe(encoder, frame);
191}
192
193static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700194{
195 struct dip_infoframe avi_if = {
196 .type = DIP_TYPE_AVI,
197 .ver = DIP_VERSION_AVI,
198 .len = DIP_LEN_AVI,
199 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700200
Jesse Barnes45187ac2011-08-03 09:22:55 -0700201 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700202}
203
Eric Anholt7d573822009-01-02 13:33:00 -0800204static void intel_hdmi_mode_set(struct drm_encoder *encoder,
205 struct drm_display_mode *mode,
206 struct drm_display_mode *adjusted_mode)
207{
208 struct drm_device *dev = encoder->dev;
209 struct drm_i915_private *dev_priv = dev->dev_private;
210 struct drm_crtc *crtc = encoder->crtc;
211 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100212 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800213 u32 sdvox;
214
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400215 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700216 if (!HAS_PCH_SPLIT(dev))
217 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400218 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
219 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
220 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
221 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800222
Jesse Barnes020f6702011-06-24 12:19:25 -0700223 if (intel_crtc->bpp > 24)
224 sdvox |= COLOR_FORMAT_12bpc;
225 else
226 sdvox |= COLOR_FORMAT_8bpc;
227
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800228 /* Required on CPT */
229 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
230 sdvox |= HDMI_MODE_SELECT;
231
David Härdeman3c17fe42010-09-24 21:44:32 +0200232 if (intel_hdmi->has_audio) {
Eric Anholt7d573822009-01-02 13:33:00 -0800233 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200234 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
235 }
Eric Anholt7d573822009-01-02 13:33:00 -0800236
Zhenyu Wang0f229062010-04-07 16:15:57 +0800237 if (intel_crtc->pipe == 1) {
238 if (HAS_PCH_CPT(dev))
239 sdvox |= PORT_TRANS_B_SEL_CPT;
240 else
241 sdvox |= SDVO_PIPE_B_SELECT;
242 }
Eric Anholt7d573822009-01-02 13:33:00 -0800243
Chris Wilsonea5b2132010-08-04 13:50:23 +0100244 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
245 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200246
Jesse Barnes45187ac2011-08-03 09:22:55 -0700247 intel_hdmi_set_avi_infoframe(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800248}
249
250static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
251{
252 struct drm_device *dev = encoder->dev;
253 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100254 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800255 u32 temp;
256
Chris Wilsonea5b2132010-08-04 13:50:23 +0100257 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000258
259 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
260 * we do this anyway which shows more stable in testing.
261 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800262 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100263 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
264 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800265 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000266
267 if (mode != DRM_MODE_DPMS_ON) {
268 temp &= ~SDVO_ENABLE;
269 } else {
270 temp |= SDVO_ENABLE;
271 }
272
Chris Wilsonea5b2132010-08-04 13:50:23 +0100273 I915_WRITE(intel_hdmi->sdvox_reg, temp);
274 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000275
276 /* HW workaround, need to write this twice for issue that may result
277 * in first write getting masked.
278 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800279 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100280 I915_WRITE(intel_hdmi->sdvox_reg, temp);
281 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000282 }
Eric Anholt7d573822009-01-02 13:33:00 -0800283}
284
Eric Anholt7d573822009-01-02 13:33:00 -0800285static int intel_hdmi_mode_valid(struct drm_connector *connector,
286 struct drm_display_mode *mode)
287{
288 if (mode->clock > 165000)
289 return MODE_CLOCK_HIGH;
290 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200291 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800292
293 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
294 return MODE_NO_DBLESCAN;
295
296 return MODE_OK;
297}
298
299static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
300 struct drm_display_mode *mode,
301 struct drm_display_mode *adjusted_mode)
302{
303 return true;
304}
305
Keith Packardaa93d632009-05-05 09:52:46 -0700306static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100307intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800308{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100309 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700310 struct drm_i915_private *dev_priv = connector->dev->dev_private;
311 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700312 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800313
Chris Wilsonea5b2132010-08-04 13:50:23 +0100314 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800315 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700316 edid = drm_get_edid(connector,
317 &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter);
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800318
Keith Packardaa93d632009-05-05 09:52:46 -0700319 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700320 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700321 status = connector_status_connected;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100322 intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800323 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700324 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800325 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700326 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800327 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800328
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100329 if (status == connector_status_connected) {
330 if (intel_hdmi->force_audio)
331 intel_hdmi->has_audio = intel_hdmi->force_audio > 0;
332 }
333
Keith Packardaa93d632009-05-05 09:52:46 -0700334 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800335}
336
Eric Anholt7d573822009-01-02 13:33:00 -0800337static int intel_hdmi_get_modes(struct drm_connector *connector)
338{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100339 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700340 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800341
342 /* We should parse the EDID data and find out if it's an HDMI sink so
343 * we can send audio to it.
344 */
345
Chris Wilsonf899fc62010-07-20 15:44:45 -0700346 return intel_ddc_get_modes(connector,
347 &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter);
Eric Anholt7d573822009-01-02 13:33:00 -0800348}
349
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000350static bool
351intel_hdmi_detect_audio(struct drm_connector *connector)
352{
353 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
354 struct drm_i915_private *dev_priv = connector->dev->dev_private;
355 struct edid *edid;
356 bool has_audio = false;
357
358 edid = drm_get_edid(connector,
359 &dev_priv->gmbus[intel_hdmi->ddc_bus].adapter);
360 if (edid) {
361 if (edid->input & DRM_EDID_INPUT_DIGITAL)
362 has_audio = drm_detect_monitor_audio(edid);
363
364 connector->display_info.raw_edid = NULL;
365 kfree(edid);
366 }
367
368 return has_audio;
369}
370
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100371static int
372intel_hdmi_set_property(struct drm_connector *connector,
373 struct drm_property *property,
374 uint64_t val)
375{
376 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000377 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100378 int ret;
379
380 ret = drm_connector_property_set_value(connector, property, val);
381 if (ret)
382 return ret;
383
Chris Wilson3f43c482011-05-12 22:17:24 +0100384 if (property == dev_priv->force_audio_property) {
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000385 int i = val;
386 bool has_audio;
387
388 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100389 return 0;
390
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000391 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100392
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000393 if (i == 0)
394 has_audio = intel_hdmi_detect_audio(connector);
395 else
396 has_audio = i > 0;
397
398 if (has_audio == intel_hdmi->has_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100399 return 0;
400
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000401 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100402 goto done;
403 }
404
Chris Wilsone953fd72011-02-21 22:23:52 +0000405 if (property == dev_priv->broadcast_rgb_property) {
406 if (val == !!intel_hdmi->color_range)
407 return 0;
408
409 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
410 goto done;
411 }
412
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100413 return -EINVAL;
414
415done:
416 if (intel_hdmi->base.base.crtc) {
417 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
418 drm_crtc_helper_set_mode(crtc, &crtc->mode,
419 crtc->x, crtc->y,
420 crtc->fb);
421 }
422
423 return 0;
424}
425
Eric Anholt7d573822009-01-02 13:33:00 -0800426static void intel_hdmi_destroy(struct drm_connector *connector)
427{
Eric Anholt7d573822009-01-02 13:33:00 -0800428 drm_sysfs_connector_remove(connector);
429 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800430 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800431}
432
433static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
434 .dpms = intel_hdmi_dpms,
435 .mode_fixup = intel_hdmi_mode_fixup,
436 .prepare = intel_encoder_prepare,
437 .mode_set = intel_hdmi_mode_set,
438 .commit = intel_encoder_commit,
439};
440
441static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700442 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800443 .detect = intel_hdmi_detect,
444 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100445 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800446 .destroy = intel_hdmi_destroy,
447};
448
449static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
450 .get_modes = intel_hdmi_get_modes,
451 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100452 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800453};
454
Eric Anholt7d573822009-01-02 13:33:00 -0800455static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100456 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800457};
458
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100459static void
460intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
461{
Chris Wilson3f43c482011-05-12 22:17:24 +0100462 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000463 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100464}
465
Eric Anholt7d573822009-01-02 13:33:00 -0800466void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
467{
468 struct drm_i915_private *dev_priv = dev->dev_private;
469 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700470 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800471 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100472 struct intel_hdmi *intel_hdmi;
Eric Anholt7d573822009-01-02 13:33:00 -0800473
Chris Wilsonea5b2132010-08-04 13:50:23 +0100474 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
475 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800476 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800477
478 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
479 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100480 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800481 return;
482 }
483
Chris Wilsonea5b2132010-08-04 13:50:23 +0100484 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100485 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
486 DRM_MODE_ENCODER_TMDS);
487
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800488 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800489 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400490 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800491 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
492
Eric Anholt21d40d32010-03-25 11:11:14 -0700493 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800494
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000495 connector->polled = DRM_CONNECTOR_POLL_HPD;
Eric Anholt7d573822009-01-02 13:33:00 -0800496 connector->interlace_allowed = 0;
497 connector->doublescan_allowed = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -0700498 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
Eric Anholt7d573822009-01-02 13:33:00 -0800499
500 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800501 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700502 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700503 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800504 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800505 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700506 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700507 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800508 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800509 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700510 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700511 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800512 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800513 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700514 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700515 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800516 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800517 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700518 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700519 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800520 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800521 }
Eric Anholt7d573822009-01-02 13:33:00 -0800522
Chris Wilsonea5b2132010-08-04 13:50:23 +0100523 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800524
Jesse Barnes45187ac2011-08-03 09:22:55 -0700525 if (!HAS_PCH_SPLIT(dev))
526 intel_hdmi->write_infoframe = i9xx_write_infoframe;
527 else
528 intel_hdmi->write_infoframe = ironlake_write_infoframe;
529
Chris Wilson4ef69c72010-09-09 15:14:28 +0100530 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800531
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100532 intel_hdmi_add_properties(intel_hdmi, connector);
533
Chris Wilsondf0e9242010-09-09 16:20:55 +0100534 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800535 drm_sysfs_connector_add(connector);
536
537 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
538 * 0xd. Failure to do so will result in spurious interrupts being
539 * generated on the port when a cable is not attached.
540 */
541 if (IS_G4X(dev) && !IS_GM45(dev)) {
542 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
543 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
544 }
Eric Anholt7d573822009-01-02 13:33:00 -0800545}