blob: 4c6f1411b28ae7cd91bc9ee666cfe2873f312708 [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
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030040struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010041{
Chris Wilson4ef69c72010-09-09 15:14:28 +010042 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010043}
44
Chris Wilsondf0e9242010-09-09 16:20:55 +010045static 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 Barnes45187ac2011-08-03 09:22:55 -070051void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020052{
Jesse Barnes45187ac2011-08-03 09:22:55 -070053 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020054 uint8_t sum = 0;
55 unsigned i;
56
Jesse Barnes45187ac2011-08-03 09:22:55 -070057 frame->checksum = 0;
58 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020059
Jesse Barnes64a8fc02011-09-22 11:16:00 +053060 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020061 sum += data[i];
62
Jesse Barnes45187ac2011-08-03 09:22:55 -070063 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020064}
65
Daniel Vetterbc2481f2012-05-08 15:18:32 +020066static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020067{
Jesse Barnes45187ac2011-08-03 09:22:55 -070068 switch (frame->type) {
69 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030070 return VIDEO_DIP_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070071 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030072 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070073 default:
74 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030075 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070077}
78
Daniel Vetterbc2481f2012-05-08 15:18:32 +020079static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070080{
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 switch (frame->type) {
82 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030083 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070084 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030085 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030086 default:
87 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030088 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030089 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030090}
91
Paulo Zanoni2da8af52012-05-14 17:12:51 -030092static 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
105static 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 Vettera3da1df2012-05-08 15:19:06 +0200118static void g4x_write_infoframe(struct drm_encoder *encoder,
119 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700120{
121 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200122 struct drm_device *dev = encoder->dev;
123 struct drm_i915_private *dev_priv = dev->dev_private;
124 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300125 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700126 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200127
Paulo Zanoni3e6e6392012-05-04 17:18:19 -0300128 val &= ~VIDEO_DIP_PORT_MASK;
David Härdeman3c17fe42010-09-24 21:44:32 +0200129 if (intel_hdmi->sdvox_reg == SDVOB)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300130 val |= VIDEO_DIP_PORT_B;
David Härdeman3c17fe42010-09-24 21:44:32 +0200131 else if (intel_hdmi->sdvox_reg == SDVOC)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300132 val |= VIDEO_DIP_PORT_C;
David Härdeman3c17fe42010-09-24 21:44:32 +0200133 else
134 return;
135
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300136 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200137 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200139 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300140 val |= VIDEO_DIP_ENABLE;
141
142 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143
144 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200145 I915_WRITE(VIDEO_DIP_DATA, *data);
146 data++;
147 }
148
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200149 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300150 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200151 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300153 I915_WRITE(VIDEO_DIP_CTL, val);
David Härdeman3c17fe42010-09-24 21:44:32 +0200154}
155
Paulo Zanonifdf12502012-05-04 17:18:24 -0300156static void ibx_write_infoframe(struct drm_encoder *encoder,
157 struct dip_infoframe *frame)
158{
159 uint32_t *data = (uint32_t *)frame;
160 struct drm_device *dev = encoder->dev;
161 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300162 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni4e89ee12012-05-04 17:18:26 -0300163 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300164 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
165 unsigned i, len = DIP_HEADER_SIZE + frame->len;
166 u32 val = I915_READ(reg);
167
Paulo Zanoni4e89ee12012-05-04 17:18:26 -0300168 val &= ~VIDEO_DIP_PORT_MASK;
169 switch (intel_hdmi->sdvox_reg) {
170 case HDMIB:
171 val |= VIDEO_DIP_PORT_B;
172 break;
173 case HDMIC:
174 val |= VIDEO_DIP_PORT_C;
175 break;
176 case HDMID:
177 val |= VIDEO_DIP_PORT_D;
178 break;
179 default:
180 return;
181 }
182
Paulo Zanonifdf12502012-05-04 17:18:24 -0300183 intel_wait_for_vblank(dev, intel_crtc->pipe);
184
185 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200186 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300187
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200188 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300189 val |= VIDEO_DIP_ENABLE;
190
191 I915_WRITE(reg, val);
192
193 for (i = 0; i < len; i += 4) {
194 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
195 data++;
196 }
197
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200198 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300199 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200200 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201
202 I915_WRITE(reg, val);
203}
204
205static void cpt_write_infoframe(struct drm_encoder *encoder,
206 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700207{
208 uint32_t *data = (uint32_t *)frame;
209 struct drm_device *dev = encoder->dev;
210 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300211 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700212 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
213 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300214 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700215
216 intel_wait_for_vblank(dev, intel_crtc->pipe);
217
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530218 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200219 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700220
Paulo Zanoniecb97852012-05-04 17:18:21 -0300221 /* The DIP control register spec says that we need to update the AVI
222 * infoframe without clearing its enable bit */
223 if (frame->type == DIP_TYPE_AVI)
224 val |= VIDEO_DIP_ENABLE_AVI;
225 else
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200226 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300227
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300228 val |= VIDEO_DIP_ENABLE;
229
230 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700231
232 for (i = 0; i < len; i += 4) {
233 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
234 data++;
235 }
236
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200237 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300238 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200239 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700240
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300241 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700242}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700243
244static void vlv_write_infoframe(struct drm_encoder *encoder,
245 struct dip_infoframe *frame)
246{
247 uint32_t *data = (uint32_t *)frame;
248 struct drm_device *dev = encoder->dev;
249 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300250 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700251 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
252 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300253 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700254
255 intel_wait_for_vblank(dev, intel_crtc->pipe);
256
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700257 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200258 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700259
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200260 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300261 val |= VIDEO_DIP_ENABLE;
262
263 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700264
265 for (i = 0; i < len; i += 4) {
266 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
267 data++;
268 }
269
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200270 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300271 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200272 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700273
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300274 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700275}
276
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300277static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300278 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300279{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300280 uint32_t *data = (uint32_t *)frame;
281 struct drm_device *dev = encoder->dev;
282 struct drm_i915_private *dev_priv = dev->dev_private;
283 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
284 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
285 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
286 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
287 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300288
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300289 if (data_reg == 0)
290 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300291
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300292 intel_wait_for_vblank(dev, intel_crtc->pipe);
293
294 val &= ~hsw_infoframe_enable(frame);
295 I915_WRITE(ctl_reg, val);
296
297 for (i = 0; i < len; i += 4) {
298 I915_WRITE(data_reg + i, *data);
299 data++;
300 }
301
302 val |= hsw_infoframe_enable(frame);
303 I915_WRITE(ctl_reg, val);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300304}
305
Jesse Barnes45187ac2011-08-03 09:22:55 -0700306static void intel_set_infoframe(struct drm_encoder *encoder,
307 struct dip_infoframe *frame)
308{
309 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
310
311 if (!intel_hdmi->has_hdmi_sink)
312 return;
313
314 intel_dip_infoframe_csum(frame);
315 intel_hdmi->write_infoframe(encoder, frame);
316}
317
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -0300318void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300319 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700320{
321 struct dip_infoframe avi_if = {
322 .type = DIP_TYPE_AVI,
323 .ver = DIP_VERSION_AVI,
324 .len = DIP_LEN_AVI,
325 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700326
Paulo Zanonic846b612012-04-13 16:31:41 -0300327 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
328 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
329
Jesse Barnes45187ac2011-08-03 09:22:55 -0700330 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700331}
332
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -0300333void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700334{
335 struct dip_infoframe spd_if;
336
337 memset(&spd_if, 0, sizeof(spd_if));
338 spd_if.type = DIP_TYPE_SPD;
339 spd_if.ver = DIP_VERSION_SPD;
340 spd_if.len = DIP_LEN_SPD;
341 strcpy(spd_if.body.spd.vn, "Intel");
342 strcpy(spd_if.body.spd.pd, "Integrated gfx");
343 spd_if.body.spd.sdi = DIP_SPD_PC;
344
345 intel_set_infoframe(encoder, &spd_if);
346}
347
Eric Anholt7d573822009-01-02 13:33:00 -0800348static void intel_hdmi_mode_set(struct drm_encoder *encoder,
349 struct drm_display_mode *mode,
350 struct drm_display_mode *adjusted_mode)
351{
352 struct drm_device *dev = encoder->dev;
353 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300354 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100355 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800356 u32 sdvox;
357
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400358 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700359 if (!HAS_PCH_SPLIT(dev))
360 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400361 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
362 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
363 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
364 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800365
Jesse Barnes020f6702011-06-24 12:19:25 -0700366 if (intel_crtc->bpp > 24)
367 sdvox |= COLOR_FORMAT_12bpc;
368 else
369 sdvox |= COLOR_FORMAT_8bpc;
370
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800371 /* Required on CPT */
372 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
373 sdvox |= HDMI_MODE_SELECT;
374
David Härdeman3c17fe42010-09-24 21:44:32 +0200375 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800376 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
377 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800378 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200379 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800380 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200381 }
Eric Anholt7d573822009-01-02 13:33:00 -0800382
Jesse Barnes75770562011-10-12 09:01:58 -0700383 if (HAS_PCH_CPT(dev))
384 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
385 else if (intel_crtc->pipe == 1)
386 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800387
Chris Wilsonea5b2132010-08-04 13:50:23 +0100388 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
389 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200390
Paulo Zanonic846b612012-04-13 16:31:41 -0300391 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700392 intel_hdmi_set_spd_infoframe(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800393}
394
395static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
396{
397 struct drm_device *dev = encoder->dev;
398 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100399 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800400 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800401 u32 enable_bits = SDVO_ENABLE;
402
403 if (intel_hdmi->has_audio)
404 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800405
Chris Wilsonea5b2132010-08-04 13:50:23 +0100406 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000407
408 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
409 * we do this anyway which shows more stable in testing.
410 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800411 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100412 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
413 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800414 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000415
416 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800417 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000418 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800419 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000420 }
421
Chris Wilsonea5b2132010-08-04 13:50:23 +0100422 I915_WRITE(intel_hdmi->sdvox_reg, temp);
423 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000424
425 /* HW workaround, need to write this twice for issue that may result
426 * in first write getting masked.
427 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800428 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100429 I915_WRITE(intel_hdmi->sdvox_reg, temp);
430 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000431 }
Eric Anholt7d573822009-01-02 13:33:00 -0800432}
433
Eric Anholt7d573822009-01-02 13:33:00 -0800434static int intel_hdmi_mode_valid(struct drm_connector *connector,
435 struct drm_display_mode *mode)
436{
437 if (mode->clock > 165000)
438 return MODE_CLOCK_HIGH;
439 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200440 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800441
442 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
443 return MODE_NO_DBLESCAN;
444
445 return MODE_OK;
446}
447
448static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
449 struct drm_display_mode *mode,
450 struct drm_display_mode *adjusted_mode)
451{
452 return true;
453}
454
Chris Wilson8ec22b22012-05-11 18:01:34 +0100455static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
456{
457 struct drm_device *dev = intel_hdmi->base.base.dev;
458 struct drm_i915_private *dev_priv = dev->dev_private;
459 uint32_t bit;
460
461 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100462 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100463 bit = HDMIB_HOTPLUG_LIVE_STATUS;
464 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100465 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100466 bit = HDMIC_HOTPLUG_LIVE_STATUS;
467 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100468 default:
469 bit = 0;
470 break;
471 }
472
473 return I915_READ(PORT_HOTPLUG_STAT) & bit;
474}
475
Keith Packardaa93d632009-05-05 09:52:46 -0700476static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100477intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800478{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100479 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700480 struct drm_i915_private *dev_priv = connector->dev->dev_private;
481 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700482 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800483
Chris Wilson8ec22b22012-05-11 18:01:34 +0100484 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
485 return status;
486
Chris Wilsonea5b2132010-08-04 13:50:23 +0100487 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800488 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700489 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800490 intel_gmbus_get_adapter(dev_priv,
491 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800492
Keith Packardaa93d632009-05-05 09:52:46 -0700493 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700494 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700495 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800496 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
497 intel_hdmi->has_hdmi_sink =
498 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800499 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700500 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800501 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700502 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800503 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800504
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100505 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800506 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
507 intel_hdmi->has_audio =
508 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100509 }
510
Keith Packardaa93d632009-05-05 09:52:46 -0700511 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800512}
513
Eric Anholt7d573822009-01-02 13:33:00 -0800514static int intel_hdmi_get_modes(struct drm_connector *connector)
515{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100516 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700517 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800518
519 /* We should parse the EDID data and find out if it's an HDMI sink so
520 * we can send audio to it.
521 */
522
Chris Wilsonf899fc62010-07-20 15:44:45 -0700523 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800524 intel_gmbus_get_adapter(dev_priv,
525 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800526}
527
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000528static bool
529intel_hdmi_detect_audio(struct drm_connector *connector)
530{
531 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
532 struct drm_i915_private *dev_priv = connector->dev->dev_private;
533 struct edid *edid;
534 bool has_audio = false;
535
536 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800537 intel_gmbus_get_adapter(dev_priv,
538 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000539 if (edid) {
540 if (edid->input & DRM_EDID_INPUT_DIGITAL)
541 has_audio = drm_detect_monitor_audio(edid);
542
543 connector->display_info.raw_edid = NULL;
544 kfree(edid);
545 }
546
547 return has_audio;
548}
549
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100550static int
551intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300552 struct drm_property *property,
553 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100554{
555 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000556 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100557 int ret;
558
559 ret = drm_connector_property_set_value(connector, property, val);
560 if (ret)
561 return ret;
562
Chris Wilson3f43c482011-05-12 22:17:24 +0100563 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800564 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000565 bool has_audio;
566
567 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100568 return 0;
569
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000570 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100571
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800572 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000573 has_audio = intel_hdmi_detect_audio(connector);
574 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800575 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000576
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800577 if (i == HDMI_AUDIO_OFF_DVI)
578 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100579
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000580 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100581 goto done;
582 }
583
Chris Wilsone953fd72011-02-21 22:23:52 +0000584 if (property == dev_priv->broadcast_rgb_property) {
585 if (val == !!intel_hdmi->color_range)
586 return 0;
587
588 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
589 goto done;
590 }
591
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100592 return -EINVAL;
593
594done:
595 if (intel_hdmi->base.base.crtc) {
596 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
597 drm_crtc_helper_set_mode(crtc, &crtc->mode,
598 crtc->x, crtc->y,
599 crtc->fb);
600 }
601
602 return 0;
603}
604
Eric Anholt7d573822009-01-02 13:33:00 -0800605static void intel_hdmi_destroy(struct drm_connector *connector)
606{
Eric Anholt7d573822009-01-02 13:33:00 -0800607 drm_sysfs_connector_remove(connector);
608 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800609 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800610}
611
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300612static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
613 .dpms = intel_ddi_dpms,
614 .mode_fixup = intel_hdmi_mode_fixup,
615 .prepare = intel_encoder_prepare,
616 .mode_set = intel_ddi_mode_set,
617 .commit = intel_encoder_commit,
618};
619
Eric Anholt7d573822009-01-02 13:33:00 -0800620static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
621 .dpms = intel_hdmi_dpms,
622 .mode_fixup = intel_hdmi_mode_fixup,
623 .prepare = intel_encoder_prepare,
624 .mode_set = intel_hdmi_mode_set,
625 .commit = intel_encoder_commit,
626};
627
628static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700629 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800630 .detect = intel_hdmi_detect,
631 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100632 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800633 .destroy = intel_hdmi_destroy,
634};
635
636static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
637 .get_modes = intel_hdmi_get_modes,
638 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100639 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800640};
641
Eric Anholt7d573822009-01-02 13:33:00 -0800642static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100643 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800644};
645
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100646static void
647intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
648{
Chris Wilson3f43c482011-05-12 22:17:24 +0100649 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000650 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100651}
652
Eric Anholt7d573822009-01-02 13:33:00 -0800653void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
654{
655 struct drm_i915_private *dev_priv = dev->dev_private;
656 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700657 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800658 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100659 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530660 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800661
Chris Wilsonea5b2132010-08-04 13:50:23 +0100662 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
663 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800664 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800665
666 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
667 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100668 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800669 return;
670 }
671
Chris Wilsonea5b2132010-08-04 13:50:23 +0100672 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100673 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
674 DRM_MODE_ENCODER_TMDS);
675
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800676 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800677 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400678 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800679 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
680
Eric Anholt21d40d32010-03-25 11:11:14 -0700681 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800682
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000683 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100684 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800685 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700686 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800687
688 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800689 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700690 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700691 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800692 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800693 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700694 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700695 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800696 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800697 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700698 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700699 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800700 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800701 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700702 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700703 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800704 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800705 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700706 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700707 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800708 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300709 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
710 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
711 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
712 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
713 intel_hdmi->ddi_port = PORT_B;
714 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
715 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
716 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
717 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
718 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
719 intel_hdmi->ddi_port = PORT_C;
720 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
721 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
722 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
723 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
724 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
725 intel_hdmi->ddi_port = PORT_D;
726 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300727 } else {
728 /* If we got an unknown sdvox_reg, things are pretty much broken
729 * in a way that we should let the kernel know about it */
730 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800731 }
Eric Anholt7d573822009-01-02 13:33:00 -0800732
Chris Wilsonea5b2132010-08-04 13:50:23 +0100733 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800734
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530735 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200736 intel_hdmi->write_infoframe = g4x_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530737 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700738 } else if (IS_VALLEYVIEW(dev)) {
739 intel_hdmi->write_infoframe = vlv_write_infoframe;
740 for_each_pipe(i)
741 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300742 } else if (IS_HASWELL(dev)) {
743 /* FIXME: Haswell has a new set of DIP frame registers, but we are
744 * just doing the minimal required for HDMI to work at this stage.
745 */
746 intel_hdmi->write_infoframe = hsw_write_infoframe;
747 for_each_pipe(i)
748 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300749 } else if (HAS_PCH_IBX(dev)) {
750 intel_hdmi->write_infoframe = ibx_write_infoframe;
751 for_each_pipe(i)
752 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
753 } else {
754 intel_hdmi->write_infoframe = cpt_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530755 for_each_pipe(i)
756 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
757 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700758
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300759 if (IS_HASWELL(dev))
760 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
761 else
762 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800763
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100764 intel_hdmi_add_properties(intel_hdmi, connector);
765
Chris Wilsondf0e9242010-09-09 16:20:55 +0100766 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800767 drm_sysfs_connector_add(connector);
768
769 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
770 * 0xd. Failure to do so will result in spurious interrupts being
771 * generated on the port when a cable is not attached.
772 */
773 if (IS_G4X(dev) && !IS_GM45(dev)) {
774 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
775 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
776 }
Eric Anholt7d573822009-01-02 13:33:00 -0800777}