blob: 8d892b0cd8a1185ff2bb22f672c90601e7d15d83 [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
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300318static void 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
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300333static void 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
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300348static void g4x_set_infoframes(struct drm_encoder *encoder,
349 struct drm_display_mode *adjusted_mode)
350{
351 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
352 intel_hdmi_set_spd_infoframe(encoder);
353}
354
355static void ibx_set_infoframes(struct drm_encoder *encoder,
356 struct drm_display_mode *adjusted_mode)
357{
358 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
359 intel_hdmi_set_spd_infoframe(encoder);
360}
361
362static void cpt_set_infoframes(struct drm_encoder *encoder,
363 struct drm_display_mode *adjusted_mode)
364{
365 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
366 intel_hdmi_set_spd_infoframe(encoder);
367}
368
369static void vlv_set_infoframes(struct drm_encoder *encoder,
370 struct drm_display_mode *adjusted_mode)
371{
372 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
373 intel_hdmi_set_spd_infoframe(encoder);
374}
375
376static void hsw_set_infoframes(struct drm_encoder *encoder,
377 struct drm_display_mode *adjusted_mode)
378{
379 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
380 intel_hdmi_set_spd_infoframe(encoder);
381}
382
Eric Anholt7d573822009-01-02 13:33:00 -0800383static void intel_hdmi_mode_set(struct drm_encoder *encoder,
384 struct drm_display_mode *mode,
385 struct drm_display_mode *adjusted_mode)
386{
387 struct drm_device *dev = encoder->dev;
388 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300389 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100390 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800391 u32 sdvox;
392
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400393 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700394 if (!HAS_PCH_SPLIT(dev))
395 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400396 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
397 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
398 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
399 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800400
Jesse Barnes020f6702011-06-24 12:19:25 -0700401 if (intel_crtc->bpp > 24)
402 sdvox |= COLOR_FORMAT_12bpc;
403 else
404 sdvox |= COLOR_FORMAT_8bpc;
405
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800406 /* Required on CPT */
407 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
408 sdvox |= HDMI_MODE_SELECT;
409
David Härdeman3c17fe42010-09-24 21:44:32 +0200410 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800411 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
412 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800413 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200414 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800415 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200416 }
Eric Anholt7d573822009-01-02 13:33:00 -0800417
Jesse Barnes75770562011-10-12 09:01:58 -0700418 if (HAS_PCH_CPT(dev))
419 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
420 else if (intel_crtc->pipe == 1)
421 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800422
Chris Wilsonea5b2132010-08-04 13:50:23 +0100423 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
424 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200425
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300426 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800427}
428
429static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
430{
431 struct drm_device *dev = encoder->dev;
432 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100433 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800434 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800435 u32 enable_bits = SDVO_ENABLE;
436
437 if (intel_hdmi->has_audio)
438 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800439
Chris Wilsonea5b2132010-08-04 13:50:23 +0100440 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000441
442 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
443 * we do this anyway which shows more stable in testing.
444 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800445 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100446 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
447 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800448 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000449
450 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800451 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000452 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800453 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000454 }
455
Chris Wilsonea5b2132010-08-04 13:50:23 +0100456 I915_WRITE(intel_hdmi->sdvox_reg, temp);
457 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000458
459 /* HW workaround, need to write this twice for issue that may result
460 * in first write getting masked.
461 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800462 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100463 I915_WRITE(intel_hdmi->sdvox_reg, temp);
464 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000465 }
Eric Anholt7d573822009-01-02 13:33:00 -0800466}
467
Eric Anholt7d573822009-01-02 13:33:00 -0800468static int intel_hdmi_mode_valid(struct drm_connector *connector,
469 struct drm_display_mode *mode)
470{
471 if (mode->clock > 165000)
472 return MODE_CLOCK_HIGH;
473 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200474 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800475
476 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
477 return MODE_NO_DBLESCAN;
478
479 return MODE_OK;
480}
481
482static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
483 struct drm_display_mode *mode,
484 struct drm_display_mode *adjusted_mode)
485{
486 return true;
487}
488
Chris Wilson8ec22b22012-05-11 18:01:34 +0100489static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
490{
491 struct drm_device *dev = intel_hdmi->base.base.dev;
492 struct drm_i915_private *dev_priv = dev->dev_private;
493 uint32_t bit;
494
495 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100496 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100497 bit = HDMIB_HOTPLUG_LIVE_STATUS;
498 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100499 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100500 bit = HDMIC_HOTPLUG_LIVE_STATUS;
501 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100502 default:
503 bit = 0;
504 break;
505 }
506
507 return I915_READ(PORT_HOTPLUG_STAT) & bit;
508}
509
Keith Packardaa93d632009-05-05 09:52:46 -0700510static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100511intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800512{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100513 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700514 struct drm_i915_private *dev_priv = connector->dev->dev_private;
515 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700516 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800517
Chris Wilson8ec22b22012-05-11 18:01:34 +0100518 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
519 return status;
520
Chris Wilsonea5b2132010-08-04 13:50:23 +0100521 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800522 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700523 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800524 intel_gmbus_get_adapter(dev_priv,
525 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800526
Keith Packardaa93d632009-05-05 09:52:46 -0700527 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700528 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700529 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800530 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
531 intel_hdmi->has_hdmi_sink =
532 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800533 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700534 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800535 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700536 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800537 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800538
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100539 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800540 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
541 intel_hdmi->has_audio =
542 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100543 }
544
Keith Packardaa93d632009-05-05 09:52:46 -0700545 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800546}
547
Eric Anholt7d573822009-01-02 13:33:00 -0800548static int intel_hdmi_get_modes(struct drm_connector *connector)
549{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100550 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700551 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800552
553 /* We should parse the EDID data and find out if it's an HDMI sink so
554 * we can send audio to it.
555 */
556
Chris Wilsonf899fc62010-07-20 15:44:45 -0700557 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800558 intel_gmbus_get_adapter(dev_priv,
559 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800560}
561
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000562static bool
563intel_hdmi_detect_audio(struct drm_connector *connector)
564{
565 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
566 struct drm_i915_private *dev_priv = connector->dev->dev_private;
567 struct edid *edid;
568 bool has_audio = false;
569
570 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800571 intel_gmbus_get_adapter(dev_priv,
572 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000573 if (edid) {
574 if (edid->input & DRM_EDID_INPUT_DIGITAL)
575 has_audio = drm_detect_monitor_audio(edid);
576
577 connector->display_info.raw_edid = NULL;
578 kfree(edid);
579 }
580
581 return has_audio;
582}
583
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100584static int
585intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300586 struct drm_property *property,
587 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100588{
589 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000590 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100591 int ret;
592
593 ret = drm_connector_property_set_value(connector, property, val);
594 if (ret)
595 return ret;
596
Chris Wilson3f43c482011-05-12 22:17:24 +0100597 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800598 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000599 bool has_audio;
600
601 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100602 return 0;
603
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000604 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100605
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800606 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000607 has_audio = intel_hdmi_detect_audio(connector);
608 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800609 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000610
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800611 if (i == HDMI_AUDIO_OFF_DVI)
612 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100613
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000614 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100615 goto done;
616 }
617
Chris Wilsone953fd72011-02-21 22:23:52 +0000618 if (property == dev_priv->broadcast_rgb_property) {
619 if (val == !!intel_hdmi->color_range)
620 return 0;
621
622 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
623 goto done;
624 }
625
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100626 return -EINVAL;
627
628done:
629 if (intel_hdmi->base.base.crtc) {
630 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
631 drm_crtc_helper_set_mode(crtc, &crtc->mode,
632 crtc->x, crtc->y,
633 crtc->fb);
634 }
635
636 return 0;
637}
638
Eric Anholt7d573822009-01-02 13:33:00 -0800639static void intel_hdmi_destroy(struct drm_connector *connector)
640{
Eric Anholt7d573822009-01-02 13:33:00 -0800641 drm_sysfs_connector_remove(connector);
642 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800643 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800644}
645
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300646static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
647 .dpms = intel_ddi_dpms,
648 .mode_fixup = intel_hdmi_mode_fixup,
649 .prepare = intel_encoder_prepare,
650 .mode_set = intel_ddi_mode_set,
651 .commit = intel_encoder_commit,
652};
653
Eric Anholt7d573822009-01-02 13:33:00 -0800654static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
655 .dpms = intel_hdmi_dpms,
656 .mode_fixup = intel_hdmi_mode_fixup,
657 .prepare = intel_encoder_prepare,
658 .mode_set = intel_hdmi_mode_set,
659 .commit = intel_encoder_commit,
660};
661
662static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700663 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800664 .detect = intel_hdmi_detect,
665 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100666 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800667 .destroy = intel_hdmi_destroy,
668};
669
670static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
671 .get_modes = intel_hdmi_get_modes,
672 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100673 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800674};
675
Eric Anholt7d573822009-01-02 13:33:00 -0800676static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100677 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800678};
679
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100680static void
681intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
682{
Chris Wilson3f43c482011-05-12 22:17:24 +0100683 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000684 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100685}
686
Eric Anholt7d573822009-01-02 13:33:00 -0800687void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
688{
689 struct drm_i915_private *dev_priv = dev->dev_private;
690 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700691 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800692 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100693 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530694 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800695
Chris Wilsonea5b2132010-08-04 13:50:23 +0100696 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
697 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800698 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800699
700 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
701 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100702 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800703 return;
704 }
705
Chris Wilsonea5b2132010-08-04 13:50:23 +0100706 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100707 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
708 DRM_MODE_ENCODER_TMDS);
709
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800710 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800711 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400712 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800713 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
714
Eric Anholt21d40d32010-03-25 11:11:14 -0700715 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800716
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000717 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100718 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800719 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700720 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800721
722 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800723 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700724 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700725 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800726 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800727 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700728 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700729 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800730 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800731 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700732 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700733 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800734 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800735 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700736 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700737 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800738 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800739 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700740 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700741 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800742 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300743 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
744 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
745 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
746 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
747 intel_hdmi->ddi_port = PORT_B;
748 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
749 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
750 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
751 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
752 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
753 intel_hdmi->ddi_port = PORT_C;
754 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
755 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
756 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
757 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
758 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
759 intel_hdmi->ddi_port = PORT_D;
760 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300761 } else {
762 /* If we got an unknown sdvox_reg, things are pretty much broken
763 * in a way that we should let the kernel know about it */
764 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800765 }
Eric Anholt7d573822009-01-02 13:33:00 -0800766
Chris Wilsonea5b2132010-08-04 13:50:23 +0100767 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800768
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530769 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200770 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300771 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530772 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700773 } else if (IS_VALLEYVIEW(dev)) {
774 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300775 intel_hdmi->set_infoframes = vlv_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700776 for_each_pipe(i)
777 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300778 } else if (IS_HASWELL(dev)) {
779 /* FIXME: Haswell has a new set of DIP frame registers, but we are
780 * just doing the minimal required for HDMI to work at this stage.
781 */
782 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300783 intel_hdmi->set_infoframes = hsw_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300784 for_each_pipe(i)
785 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300786 } else if (HAS_PCH_IBX(dev)) {
787 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300788 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300789 for_each_pipe(i)
790 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
791 } else {
792 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300793 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530794 for_each_pipe(i)
795 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
796 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700797
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300798 if (IS_HASWELL(dev))
799 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
800 else
801 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800802
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100803 intel_hdmi_add_properties(intel_hdmi, connector);
804
Chris Wilsondf0e9242010-09-09 16:20:55 +0100805 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800806 drm_sysfs_connector_add(connector);
807
808 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
809 * 0xd. Failure to do so will result in spurious interrupts being
810 * generated on the port when a cable is not attached.
811 */
812 if (IS_G4X(dev) && !IS_GM45(dev)) {
813 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
814 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
815 }
Eric Anholt7d573822009-01-02 13:33:00 -0800816}