blob: 025be7dd2a27a9647ac7e596eac1ea16acb14b78 [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>
David Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
33#include <drm/drm_crtc.h>
34#include <drm/drm_edid.h>
Eric Anholt7d573822009-01-02 13:33:00 -080035#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/i915_drm.h>
Eric Anholt7d573822009-01-02 13:33:00 -080037#include "i915_drv.h"
38
Daniel Vetterafba0182012-06-12 16:36:45 +020039static void
40assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
41{
42 struct drm_device *dev = intel_hdmi->base.base.dev;
43 struct drm_i915_private *dev_priv = dev->dev_private;
44 uint32_t enabled_bits;
45
46 enabled_bits = IS_HASWELL(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
47
48 WARN(I915_READ(intel_hdmi->sdvox_reg) & enabled_bits,
49 "HDMI port enabled, expecting disabled\n");
50}
51
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030052struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010053{
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 Barnes64a8fc02011-09-22 11:16:00 +053072 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020073 sum += data[i];
74
Jesse Barnes45187ac2011-08-03 09:22:55 -070075 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020076}
77
Daniel Vetterbc2481f2012-05-08 15:18:32 +020078static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020079{
Jesse Barnes45187ac2011-08-03 09:22:55 -070080 switch (frame->type) {
81 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030082 return VIDEO_DIP_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070083 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030084 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070085 default:
86 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030087 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070088 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070089}
90
Daniel Vetterbc2481f2012-05-08 15:18:32 +020091static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070092{
Jesse Barnes45187ac2011-08-03 09:22:55 -070093 switch (frame->type) {
94 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030095 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070096 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030097 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030098 default:
99 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -0300100 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300101 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300102}
103
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300104static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
105{
106 switch (frame->type) {
107 case DIP_TYPE_AVI:
108 return VIDEO_DIP_ENABLE_AVI_HSW;
109 case DIP_TYPE_SPD:
110 return VIDEO_DIP_ENABLE_SPD_HSW;
111 default:
112 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
113 return 0;
114 }
115}
116
117static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe)
118{
119 switch (frame->type) {
120 case DIP_TYPE_AVI:
121 return HSW_TVIDEO_DIP_AVI_DATA(pipe);
122 case DIP_TYPE_SPD:
123 return HSW_TVIDEO_DIP_SPD_DATA(pipe);
124 default:
125 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
126 return 0;
127 }
128}
129
Daniel Vettera3da1df2012-05-08 15:19:06 +0200130static void g4x_write_infoframe(struct drm_encoder *encoder,
131 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700132{
133 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200134 struct drm_device *dev = encoder->dev;
135 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300136 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700137 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200138
Paulo Zanoni822974a2012-05-28 16:42:51 -0300139 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
140
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300141 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200142 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200144 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300145
146 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700147
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300148 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700149 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200150 I915_WRITE(VIDEO_DIP_DATA, *data);
151 data++;
152 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300153 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200154
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200155 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300156 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200157 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700158
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300159 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300160 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200161}
162
Paulo Zanonifdf12502012-05-04 17:18:24 -0300163static void ibx_write_infoframe(struct drm_encoder *encoder,
164 struct dip_infoframe *frame)
165{
166 uint32_t *data = (uint32_t *)frame;
167 struct drm_device *dev = encoder->dev;
168 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300169 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300170 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
171 unsigned i, len = DIP_HEADER_SIZE + frame->len;
172 u32 val = I915_READ(reg);
173
Paulo Zanoni822974a2012-05-28 16:42:51 -0300174 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
175
Paulo Zanonifdf12502012-05-04 17:18:24 -0300176 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200177 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300178
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200179 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300180
181 I915_WRITE(reg, val);
182
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300183 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300184 for (i = 0; i < len; i += 4) {
185 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
186 data++;
187 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300188 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300189
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200190 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300191 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200192 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300193
194 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300195 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196}
197
198static void cpt_write_infoframe(struct drm_encoder *encoder,
199 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700200{
201 uint32_t *data = (uint32_t *)frame;
202 struct drm_device *dev = encoder->dev;
203 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300204 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700205 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
206 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300207 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700208
Paulo Zanoni822974a2012-05-28 16:42:51 -0300209 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
210
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530211 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200212 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700213
Paulo Zanoniecb97852012-05-04 17:18:21 -0300214 /* The DIP control register spec says that we need to update the AVI
215 * infoframe without clearing its enable bit */
Paulo Zanoni822974a2012-05-28 16:42:51 -0300216 if (frame->type != DIP_TYPE_AVI)
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200217 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300218
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300219 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700220
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300221 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700222 for (i = 0; i < len; i += 4) {
223 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
224 data++;
225 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300226 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700227
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200228 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300229 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200230 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700231
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300232 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300233 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700234}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700235
236static void vlv_write_infoframe(struct drm_encoder *encoder,
237 struct dip_infoframe *frame)
238{
239 uint32_t *data = (uint32_t *)frame;
240 struct drm_device *dev = encoder->dev;
241 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300242 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700243 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
244 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300245 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700246
Paulo Zanoni822974a2012-05-28 16:42:51 -0300247 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
248
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700249 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200250 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700251
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200252 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300253
254 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700255
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300256 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700257 for (i = 0; i < len; i += 4) {
258 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
259 data++;
260 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300261 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700262
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200263 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300264 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200265 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700266
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300267 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300268 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700269}
270
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300271static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300272 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300273{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300274 uint32_t *data = (uint32_t *)frame;
275 struct drm_device *dev = encoder->dev;
276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
278 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
279 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
280 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
281 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300282
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300283 if (data_reg == 0)
284 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300285
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300286 val &= ~hsw_infoframe_enable(frame);
287 I915_WRITE(ctl_reg, val);
288
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300289 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300290 for (i = 0; i < len; i += 4) {
291 I915_WRITE(data_reg + i, *data);
292 data++;
293 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300294 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300295
296 val |= hsw_infoframe_enable(frame);
297 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300298 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300299}
300
Jesse Barnes45187ac2011-08-03 09:22:55 -0700301static void intel_set_infoframe(struct drm_encoder *encoder,
302 struct dip_infoframe *frame)
303{
304 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
305
Jesse Barnes45187ac2011-08-03 09:22:55 -0700306 intel_dip_infoframe_csum(frame);
307 intel_hdmi->write_infoframe(encoder, frame);
308}
309
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300310static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300311 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700312{
313 struct dip_infoframe avi_if = {
314 .type = DIP_TYPE_AVI,
315 .ver = DIP_VERSION_AVI,
316 .len = DIP_LEN_AVI,
317 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700318
Paulo Zanonic846b612012-04-13 16:31:41 -0300319 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
320 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
321
Jesse Barnes45187ac2011-08-03 09:22:55 -0700322 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700323}
324
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300325static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700326{
327 struct dip_infoframe spd_if;
328
329 memset(&spd_if, 0, sizeof(spd_if));
330 spd_if.type = DIP_TYPE_SPD;
331 spd_if.ver = DIP_VERSION_SPD;
332 spd_if.len = DIP_LEN_SPD;
333 strcpy(spd_if.body.spd.vn, "Intel");
334 strcpy(spd_if.body.spd.pd, "Integrated gfx");
335 spd_if.body.spd.sdi = DIP_SPD_PC;
336
337 intel_set_infoframe(encoder, &spd_if);
338}
339
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300340static void g4x_set_infoframes(struct drm_encoder *encoder,
341 struct drm_display_mode *adjusted_mode)
342{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300343 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
344 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
345 u32 reg = VIDEO_DIP_CTL;
346 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300347 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300348
Daniel Vetterafba0182012-06-12 16:36:45 +0200349 assert_hdmi_port_disabled(intel_hdmi);
350
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300351 /* If the registers were not initialized yet, they might be zeroes,
352 * which means we're selecting the AVI DIP and we're setting its
353 * frequency to once. This seems to really confuse the HW and make
354 * things stop working (the register spec says the AVI always needs to
355 * be sent every VSync). So here we avoid writing to the register more
356 * than we need and also explicitly select the AVI DIP and explicitly
357 * set its frequency to every VSync. Avoiding to write it twice seems to
358 * be enough to solve the problem, but being defensive shouldn't hurt us
359 * either. */
360 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
361
362 if (!intel_hdmi->has_hdmi_sink) {
363 if (!(val & VIDEO_DIP_ENABLE))
364 return;
365 val &= ~VIDEO_DIP_ENABLE;
366 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300367 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300368 return;
369 }
370
Paulo Zanonif278d972012-05-28 16:42:50 -0300371 switch (intel_hdmi->sdvox_reg) {
372 case SDVOB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300373 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300374 break;
375 case SDVOC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300376 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300377 break;
378 default:
379 return;
380 }
381
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300382 if (port != (val & VIDEO_DIP_PORT_MASK)) {
383 if (val & VIDEO_DIP_ENABLE) {
384 val &= ~VIDEO_DIP_ENABLE;
385 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300386 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300387 }
388 val &= ~VIDEO_DIP_PORT_MASK;
389 val |= port;
390 }
391
Paulo Zanoni822974a2012-05-28 16:42:51 -0300392 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300393 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300394
Paulo Zanonif278d972012-05-28 16:42:50 -0300395 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300396 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300397
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300398 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
399 intel_hdmi_set_spd_infoframe(encoder);
400}
401
402static void ibx_set_infoframes(struct drm_encoder *encoder,
403 struct drm_display_mode *adjusted_mode)
404{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300405 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
406 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
407 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
408 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
409 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300410 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300411
Daniel Vetterafba0182012-06-12 16:36:45 +0200412 assert_hdmi_port_disabled(intel_hdmi);
413
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300414 /* See the big comment in g4x_set_infoframes() */
415 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
416
417 if (!intel_hdmi->has_hdmi_sink) {
418 if (!(val & VIDEO_DIP_ENABLE))
419 return;
420 val &= ~VIDEO_DIP_ENABLE;
421 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300422 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300423 return;
424 }
425
Paulo Zanonif278d972012-05-28 16:42:50 -0300426 switch (intel_hdmi->sdvox_reg) {
427 case HDMIB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300428 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300429 break;
430 case HDMIC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300431 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300432 break;
433 case HDMID:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300434 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300435 break;
436 default:
437 return;
438 }
439
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300440 if (port != (val & VIDEO_DIP_PORT_MASK)) {
441 if (val & VIDEO_DIP_ENABLE) {
442 val &= ~VIDEO_DIP_ENABLE;
443 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300444 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300445 }
446 val &= ~VIDEO_DIP_PORT_MASK;
447 val |= port;
448 }
449
Paulo Zanoni822974a2012-05-28 16:42:51 -0300450 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300451 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
452 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300453
Paulo Zanonif278d972012-05-28 16:42:50 -0300454 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300455 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300456
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300457 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
458 intel_hdmi_set_spd_infoframe(encoder);
459}
460
461static void cpt_set_infoframes(struct drm_encoder *encoder,
462 struct drm_display_mode *adjusted_mode)
463{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300464 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
465 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
466 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
467 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
468 u32 val = I915_READ(reg);
469
Daniel Vetterafba0182012-06-12 16:36:45 +0200470 assert_hdmi_port_disabled(intel_hdmi);
471
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300472 /* See the big comment in g4x_set_infoframes() */
473 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
474
475 if (!intel_hdmi->has_hdmi_sink) {
476 if (!(val & VIDEO_DIP_ENABLE))
477 return;
478 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
479 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300480 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300481 return;
482 }
483
Paulo Zanoni822974a2012-05-28 16:42:51 -0300484 /* Set both together, unset both together: see the spec. */
485 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300486 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
487 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300488
489 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300490 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300491
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300492 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
493 intel_hdmi_set_spd_infoframe(encoder);
494}
495
496static void vlv_set_infoframes(struct drm_encoder *encoder,
497 struct drm_display_mode *adjusted_mode)
498{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300499 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
500 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
501 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
502 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
503 u32 val = I915_READ(reg);
504
Daniel Vetterafba0182012-06-12 16:36:45 +0200505 assert_hdmi_port_disabled(intel_hdmi);
506
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300507 /* See the big comment in g4x_set_infoframes() */
508 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
509
510 if (!intel_hdmi->has_hdmi_sink) {
511 if (!(val & VIDEO_DIP_ENABLE))
512 return;
513 val &= ~VIDEO_DIP_ENABLE;
514 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300515 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300516 return;
517 }
518
Paulo Zanoni822974a2012-05-28 16:42:51 -0300519 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300520 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
521 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300522
523 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300524 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300525
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300526 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
527 intel_hdmi_set_spd_infoframe(encoder);
528}
529
530static void hsw_set_infoframes(struct drm_encoder *encoder,
531 struct drm_display_mode *adjusted_mode)
532{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300533 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
534 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
535 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
536 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300537 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300538
Daniel Vetterafba0182012-06-12 16:36:45 +0200539 assert_hdmi_port_disabled(intel_hdmi);
540
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300541 if (!intel_hdmi->has_hdmi_sink) {
542 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300543 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300544 return;
545 }
546
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300547 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
548 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
549
550 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300551 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300552
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300553 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
554 intel_hdmi_set_spd_infoframe(encoder);
555}
556
Eric Anholt7d573822009-01-02 13:33:00 -0800557static void intel_hdmi_mode_set(struct drm_encoder *encoder,
558 struct drm_display_mode *mode,
559 struct drm_display_mode *adjusted_mode)
560{
561 struct drm_device *dev = encoder->dev;
562 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300563 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100564 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800565 u32 sdvox;
566
Paulo Zanonib659c3d2012-05-28 16:42:56 -0300567 sdvox = SDVO_ENCODING_HDMI;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700568 if (!HAS_PCH_SPLIT(dev))
569 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400570 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
571 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
572 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
573 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800574
Jesse Barnes020f6702011-06-24 12:19:25 -0700575 if (intel_crtc->bpp > 24)
576 sdvox |= COLOR_FORMAT_12bpc;
577 else
578 sdvox |= COLOR_FORMAT_8bpc;
579
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800580 /* Required on CPT */
581 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
582 sdvox |= HDMI_MODE_SELECT;
583
David Härdeman3c17fe42010-09-24 21:44:32 +0200584 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800585 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
586 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800587 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200588 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800589 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200590 }
Eric Anholt7d573822009-01-02 13:33:00 -0800591
Jesse Barnes75770562011-10-12 09:01:58 -0700592 if (HAS_PCH_CPT(dev))
593 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200594 else if (intel_crtc->pipe == PIPE_B)
Jesse Barnes75770562011-10-12 09:01:58 -0700595 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800596
Chris Wilsonea5b2132010-08-04 13:50:23 +0100597 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
598 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200599
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300600 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800601}
602
603static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
604{
605 struct drm_device *dev = encoder->dev;
606 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100607 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800608 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800609 u32 enable_bits = SDVO_ENABLE;
610
Wang Xingchaob98b6012012-09-13 07:43:22 +0800611 if (intel_hdmi->has_audio || mode != DRM_MODE_DPMS_ON)
Wu Fengguang2deed762011-12-09 20:42:20 +0800612 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800613
Chris Wilsonea5b2132010-08-04 13:50:23 +0100614 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000615
Daniel Vetter7a87c282012-06-05 11:03:39 +0200616 /* HW workaround for IBX, we need to move the port to transcoder A
617 * before disabling it. */
618 if (HAS_PCH_IBX(dev)) {
619 struct drm_crtc *crtc = encoder->crtc;
620 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
621
622 if (mode != DRM_MODE_DPMS_ON) {
623 if (temp & SDVO_PIPE_B_SELECT) {
624 temp &= ~SDVO_PIPE_B_SELECT;
625 I915_WRITE(intel_hdmi->sdvox_reg, temp);
626 POSTING_READ(intel_hdmi->sdvox_reg);
627
628 /* Again we need to write this twice. */
629 I915_WRITE(intel_hdmi->sdvox_reg, temp);
630 POSTING_READ(intel_hdmi->sdvox_reg);
631
632 /* Transcoder selection bits only update
633 * effectively on vblank. */
634 if (crtc)
635 intel_wait_for_vblank(dev, pipe);
636 else
637 msleep(50);
638 }
639 } else {
640 /* Restore the transcoder select bit. */
641 if (pipe == PIPE_B)
642 enable_bits |= SDVO_PIPE_B_SELECT;
643 }
644 }
645
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000646 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
647 * we do this anyway which shows more stable in testing.
648 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800649 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100650 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
651 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800652 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000653
654 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800655 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000656 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800657 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000658 }
659
Chris Wilsonea5b2132010-08-04 13:50:23 +0100660 I915_WRITE(intel_hdmi->sdvox_reg, temp);
661 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000662
663 /* HW workaround, need to write this twice for issue that may result
664 * in first write getting masked.
665 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800666 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100667 I915_WRITE(intel_hdmi->sdvox_reg, temp);
668 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000669 }
Eric Anholt7d573822009-01-02 13:33:00 -0800670}
671
Eric Anholt7d573822009-01-02 13:33:00 -0800672static int intel_hdmi_mode_valid(struct drm_connector *connector,
673 struct drm_display_mode *mode)
674{
675 if (mode->clock > 165000)
676 return MODE_CLOCK_HIGH;
677 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200678 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800679
680 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
681 return MODE_NO_DBLESCAN;
682
683 return MODE_OK;
684}
685
686static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200687 const struct drm_display_mode *mode,
Eric Anholt7d573822009-01-02 13:33:00 -0800688 struct drm_display_mode *adjusted_mode)
689{
690 return true;
691}
692
Chris Wilson8ec22b22012-05-11 18:01:34 +0100693static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
694{
695 struct drm_device *dev = intel_hdmi->base.base.dev;
696 struct drm_i915_private *dev_priv = dev->dev_private;
697 uint32_t bit;
698
699 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100700 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100701 bit = HDMIB_HOTPLUG_LIVE_STATUS;
702 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100703 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100704 bit = HDMIC_HOTPLUG_LIVE_STATUS;
705 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100706 default:
707 bit = 0;
708 break;
709 }
710
711 return I915_READ(PORT_HOTPLUG_STAT) & bit;
712}
713
Keith Packardaa93d632009-05-05 09:52:46 -0700714static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100715intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800716{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100717 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700718 struct drm_i915_private *dev_priv = connector->dev->dev_private;
719 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700720 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800721
Chris Wilson8ec22b22012-05-11 18:01:34 +0100722 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
723 return status;
724
Chris Wilsonea5b2132010-08-04 13:50:23 +0100725 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800726 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700727 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800728 intel_gmbus_get_adapter(dev_priv,
729 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800730
Keith Packardaa93d632009-05-05 09:52:46 -0700731 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700732 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700733 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800734 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
735 intel_hdmi->has_hdmi_sink =
736 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800737 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700738 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800739 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700740 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800741 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800742
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100743 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800744 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
745 intel_hdmi->has_audio =
746 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100747 }
748
Keith Packardaa93d632009-05-05 09:52:46 -0700749 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800750}
751
Eric Anholt7d573822009-01-02 13:33:00 -0800752static int intel_hdmi_get_modes(struct drm_connector *connector)
753{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100754 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700755 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800756
757 /* We should parse the EDID data and find out if it's an HDMI sink so
758 * we can send audio to it.
759 */
760
Chris Wilsonf899fc62010-07-20 15:44:45 -0700761 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800762 intel_gmbus_get_adapter(dev_priv,
763 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800764}
765
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000766static bool
767intel_hdmi_detect_audio(struct drm_connector *connector)
768{
769 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
770 struct drm_i915_private *dev_priv = connector->dev->dev_private;
771 struct edid *edid;
772 bool has_audio = false;
773
774 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800775 intel_gmbus_get_adapter(dev_priv,
776 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000777 if (edid) {
778 if (edid->input & DRM_EDID_INPUT_DIGITAL)
779 has_audio = drm_detect_monitor_audio(edid);
780
781 connector->display_info.raw_edid = NULL;
782 kfree(edid);
783 }
784
785 return has_audio;
786}
787
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100788static int
789intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300790 struct drm_property *property,
791 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100792{
793 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000794 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100795 int ret;
796
797 ret = drm_connector_property_set_value(connector, property, val);
798 if (ret)
799 return ret;
800
Chris Wilson3f43c482011-05-12 22:17:24 +0100801 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800802 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000803 bool has_audio;
804
805 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100806 return 0;
807
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000808 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100809
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800810 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000811 has_audio = intel_hdmi_detect_audio(connector);
812 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800813 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000814
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800815 if (i == HDMI_AUDIO_OFF_DVI)
816 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100817
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000818 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100819 goto done;
820 }
821
Chris Wilsone953fd72011-02-21 22:23:52 +0000822 if (property == dev_priv->broadcast_rgb_property) {
823 if (val == !!intel_hdmi->color_range)
824 return 0;
825
826 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
827 goto done;
828 }
829
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100830 return -EINVAL;
831
832done:
833 if (intel_hdmi->base.base.crtc) {
834 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
835 drm_crtc_helper_set_mode(crtc, &crtc->mode,
836 crtc->x, crtc->y,
837 crtc->fb);
838 }
839
840 return 0;
841}
842
Eric Anholt7d573822009-01-02 13:33:00 -0800843static void intel_hdmi_destroy(struct drm_connector *connector)
844{
Eric Anholt7d573822009-01-02 13:33:00 -0800845 drm_sysfs_connector_remove(connector);
846 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800847 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800848}
849
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300850static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
851 .dpms = intel_ddi_dpms,
852 .mode_fixup = intel_hdmi_mode_fixup,
853 .prepare = intel_encoder_prepare,
854 .mode_set = intel_ddi_mode_set,
855 .commit = intel_encoder_commit,
856};
857
Eric Anholt7d573822009-01-02 13:33:00 -0800858static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
859 .dpms = intel_hdmi_dpms,
860 .mode_fixup = intel_hdmi_mode_fixup,
861 .prepare = intel_encoder_prepare,
862 .mode_set = intel_hdmi_mode_set,
863 .commit = intel_encoder_commit,
864};
865
866static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700867 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800868 .detect = intel_hdmi_detect,
869 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100870 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800871 .destroy = intel_hdmi_destroy,
872};
873
874static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
875 .get_modes = intel_hdmi_get_modes,
876 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100877 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800878};
879
Eric Anholt7d573822009-01-02 13:33:00 -0800880static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100881 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800882};
883
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100884static void
885intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
886{
Chris Wilson3f43c482011-05-12 22:17:24 +0100887 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000888 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100889}
890
Eric Anholt7d573822009-01-02 13:33:00 -0800891void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
892{
893 struct drm_i915_private *dev_priv = dev->dev_private;
894 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700895 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800896 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100897 struct intel_hdmi *intel_hdmi;
Eric Anholt7d573822009-01-02 13:33:00 -0800898
Chris Wilsonea5b2132010-08-04 13:50:23 +0100899 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
900 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800901 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800902
903 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
904 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100905 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800906 return;
907 }
908
Chris Wilsonea5b2132010-08-04 13:50:23 +0100909 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100910 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
911 DRM_MODE_ENCODER_TMDS);
912
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800913 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800914 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400915 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800916 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
917
Eric Anholt21d40d32010-03-25 11:11:14 -0700918 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800919
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000920 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100921 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800922 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700923 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800924
925 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800926 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700927 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700928 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800929 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800930 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700931 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700932 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800933 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800934 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700935 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700936 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800937 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800938 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700939 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700940 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800941 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800942 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700943 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700944 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800945 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300946 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
947 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
948 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
949 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
950 intel_hdmi->ddi_port = PORT_B;
951 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
952 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
953 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
954 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
955 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
956 intel_hdmi->ddi_port = PORT_C;
957 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
958 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
959 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
960 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
961 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
962 intel_hdmi->ddi_port = PORT_D;
963 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300964 } else {
965 /* If we got an unknown sdvox_reg, things are pretty much broken
966 * in a way that we should let the kernel know about it */
967 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800968 }
Eric Anholt7d573822009-01-02 13:33:00 -0800969
Chris Wilsonea5b2132010-08-04 13:50:23 +0100970 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800971
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530972 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200973 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300974 intel_hdmi->set_infoframes = g4x_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700975 } else if (IS_VALLEYVIEW(dev)) {
976 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300977 intel_hdmi->set_infoframes = vlv_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300978 } else if (IS_HASWELL(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300979 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300980 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300981 } else if (HAS_PCH_IBX(dev)) {
982 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300983 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300984 } else {
985 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300986 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530987 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700988
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300989 if (IS_HASWELL(dev))
990 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
991 else
992 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800993
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100994 intel_hdmi_add_properties(intel_hdmi, connector);
995
Chris Wilsondf0e9242010-09-09 16:20:55 +0100996 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800997 drm_sysfs_connector_add(connector);
998
999 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1000 * 0xd. Failure to do so will result in spurious interrupts being
1001 * generated on the port when a cable is not attached.
1002 */
1003 if (IS_G4X(dev) && !IS_GM45(dev)) {
1004 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1005 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1006 }
Eric Anholt7d573822009-01-02 13:33:00 -08001007}