blob: f194d756a58c14ae33225662590a2ed5775e9a6a [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
Paulo Zanoni30add222012-10-26 19:05:45 -020039static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
40{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020041 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020042}
43
Daniel Vetterafba0182012-06-12 16:36:45 +020044static void
45assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
46{
Paulo Zanoni30add222012-10-26 19:05:45 -020047 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Daniel Vetterafba0182012-06-12 16:36:45 +020048 struct drm_i915_private *dev_priv = dev->dev_private;
49 uint32_t enabled_bits;
50
Paulo Zanoniaffa9352012-11-23 15:30:39 -020051 enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020052
53 WARN(I915_READ(intel_hdmi->sdvox_reg) & enabled_bits,
54 "HDMI port enabled, expecting disabled\n");
55}
56
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030057struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010058{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020059 struct intel_digital_port *intel_dig_port =
60 container_of(encoder, struct intel_digital_port, base.base);
61 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010062}
63
Chris Wilsondf0e9242010-09-09 16:20:55 +010064static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
65{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020066 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010067}
68
Jesse Barnes45187ac2011-08-03 09:22:55 -070069void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020070{
Jesse Barnes45187ac2011-08-03 09:22:55 -070071 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020072 uint8_t sum = 0;
73 unsigned i;
74
Jesse Barnes45187ac2011-08-03 09:22:55 -070075 frame->checksum = 0;
76 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020077
Jesse Barnes64a8fc02011-09-22 11:16:00 +053078 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020079 sum += data[i];
80
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020082}
83
Daniel Vetterbc2481f2012-05-08 15:18:32 +020084static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020085{
Jesse Barnes45187ac2011-08-03 09:22:55 -070086 switch (frame->type) {
87 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030088 return VIDEO_DIP_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070089 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030090 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070091 default:
92 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030093 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070094 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070095}
96
Daniel Vetterbc2481f2012-05-08 15:18:32 +020097static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070098{
Jesse Barnes45187ac2011-08-03 09:22:55 -070099 switch (frame->type) {
100 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -0300101 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700102 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -0300103 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300104 default:
105 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -0300106 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300107 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300108}
109
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300110static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
111{
112 switch (frame->type) {
113 case DIP_TYPE_AVI:
114 return VIDEO_DIP_ENABLE_AVI_HSW;
115 case DIP_TYPE_SPD:
116 return VIDEO_DIP_ENABLE_SPD_HSW;
117 default:
118 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
119 return 0;
120 }
121}
122
123static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe)
124{
125 switch (frame->type) {
126 case DIP_TYPE_AVI:
127 return HSW_TVIDEO_DIP_AVI_DATA(pipe);
128 case DIP_TYPE_SPD:
129 return HSW_TVIDEO_DIP_SPD_DATA(pipe);
130 default:
131 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
132 return 0;
133 }
134}
135
Daniel Vettera3da1df2012-05-08 15:19:06 +0200136static void g4x_write_infoframe(struct drm_encoder *encoder,
137 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138{
139 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200140 struct drm_device *dev = encoder->dev;
141 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300142 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200144
Paulo Zanoni822974a2012-05-28 16:42:51 -0300145 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
146
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300147 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200148 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700149
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200150 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300151
152 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700153
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300154 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700155 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200156 I915_WRITE(VIDEO_DIP_DATA, *data);
157 data++;
158 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300159 /* Write every possible data byte to force correct ECC calculation. */
160 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
161 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300162 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200163
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200164 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300165 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200166 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700167
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300168 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300169 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200170}
171
Paulo Zanonifdf12502012-05-04 17:18:24 -0300172static void ibx_write_infoframe(struct drm_encoder *encoder,
173 struct dip_infoframe *frame)
174{
175 uint32_t *data = (uint32_t *)frame;
176 struct drm_device *dev = encoder->dev;
177 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300178 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300179 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
180 unsigned i, len = DIP_HEADER_SIZE + frame->len;
181 u32 val = I915_READ(reg);
182
Paulo Zanoni822974a2012-05-28 16:42:51 -0300183 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
184
Paulo Zanonifdf12502012-05-04 17:18:24 -0300185 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
190 I915_WRITE(reg, val);
191
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300192 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300193 for (i = 0; i < len; i += 4) {
194 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
195 data++;
196 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300197 /* Write every possible data byte to force correct ECC calculation. */
198 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
199 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300200 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200202 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300203 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200204 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300205
206 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300207 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300208}
209
210static void cpt_write_infoframe(struct drm_encoder *encoder,
211 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700212{
213 uint32_t *data = (uint32_t *)frame;
214 struct drm_device *dev = encoder->dev;
215 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300216 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700217 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
218 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300219 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700220
Paulo Zanoni822974a2012-05-28 16:42:51 -0300221 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
222
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530223 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200224 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700225
Paulo Zanoniecb97852012-05-04 17:18:21 -0300226 /* The DIP control register spec says that we need to update the AVI
227 * infoframe without clearing its enable bit */
Paulo Zanoni822974a2012-05-28 16:42:51 -0300228 if (frame->type != DIP_TYPE_AVI)
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200229 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300230
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300231 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700232
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300233 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700234 for (i = 0; i < len; i += 4) {
235 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
236 data++;
237 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300238 /* Write every possible data byte to force correct ECC calculation. */
239 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
240 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300241 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700242
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200243 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300244 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200245 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700246
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300247 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300248 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700249}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700250
251static void vlv_write_infoframe(struct drm_encoder *encoder,
252 struct dip_infoframe *frame)
253{
254 uint32_t *data = (uint32_t *)frame;
255 struct drm_device *dev = encoder->dev;
256 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300257 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700258 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
259 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300260 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700261
Paulo Zanoni822974a2012-05-28 16:42:51 -0300262 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
263
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700264 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200265 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700266
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200267 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300268
269 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700270
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300271 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700272 for (i = 0; i < len; i += 4) {
273 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
274 data++;
275 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300276 /* Write every possible data byte to force correct ECC calculation. */
277 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
278 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300279 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700280
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200281 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300282 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200283 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700284
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300285 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300286 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700287}
288
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300289static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300290 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300291{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300292 uint32_t *data = (uint32_t *)frame;
293 struct drm_device *dev = encoder->dev;
294 struct drm_i915_private *dev_priv = dev->dev_private;
295 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
296 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
297 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
298 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
299 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300300
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300301 if (data_reg == 0)
302 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300303
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300304 val &= ~hsw_infoframe_enable(frame);
305 I915_WRITE(ctl_reg, val);
306
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300307 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300308 for (i = 0; i < len; i += 4) {
309 I915_WRITE(data_reg + i, *data);
310 data++;
311 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300312 /* Write every possible data byte to force correct ECC calculation. */
313 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
314 I915_WRITE(data_reg + i, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300315 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300316
317 val |= hsw_infoframe_enable(frame);
318 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300319 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300320}
321
Jesse Barnes45187ac2011-08-03 09:22:55 -0700322static void intel_set_infoframe(struct drm_encoder *encoder,
323 struct dip_infoframe *frame)
324{
325 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
326
Jesse Barnes45187ac2011-08-03 09:22:55 -0700327 intel_dip_infoframe_csum(frame);
328 intel_hdmi->write_infoframe(encoder, frame);
329}
330
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300331static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300332 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700333{
334 struct dip_infoframe avi_if = {
335 .type = DIP_TYPE_AVI,
336 .ver = DIP_VERSION_AVI,
337 .len = DIP_LEN_AVI,
338 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700339
Paulo Zanonic846b612012-04-13 16:31:41 -0300340 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
341 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
342
Paulo Zanoni9a69b882012-11-23 12:09:27 -0200343 avi_if.body.avi.VIC = drm_mode_cea_vic(adjusted_mode);
344
Jesse Barnes45187ac2011-08-03 09:22:55 -0700345 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700346}
347
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300348static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700349{
350 struct dip_infoframe spd_if;
351
352 memset(&spd_if, 0, sizeof(spd_if));
353 spd_if.type = DIP_TYPE_SPD;
354 spd_if.ver = DIP_VERSION_SPD;
355 spd_if.len = DIP_LEN_SPD;
356 strcpy(spd_if.body.spd.vn, "Intel");
357 strcpy(spd_if.body.spd.pd, "Integrated gfx");
358 spd_if.body.spd.sdi = DIP_SPD_PC;
359
360 intel_set_infoframe(encoder, &spd_if);
361}
362
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300363static void g4x_set_infoframes(struct drm_encoder *encoder,
364 struct drm_display_mode *adjusted_mode)
365{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300366 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
367 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
368 u32 reg = VIDEO_DIP_CTL;
369 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300370 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300371
Daniel Vetterafba0182012-06-12 16:36:45 +0200372 assert_hdmi_port_disabled(intel_hdmi);
373
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300374 /* If the registers were not initialized yet, they might be zeroes,
375 * which means we're selecting the AVI DIP and we're setting its
376 * frequency to once. This seems to really confuse the HW and make
377 * things stop working (the register spec says the AVI always needs to
378 * be sent every VSync). So here we avoid writing to the register more
379 * than we need and also explicitly select the AVI DIP and explicitly
380 * set its frequency to every VSync. Avoiding to write it twice seems to
381 * be enough to solve the problem, but being defensive shouldn't hurt us
382 * either. */
383 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
384
385 if (!intel_hdmi->has_hdmi_sink) {
386 if (!(val & VIDEO_DIP_ENABLE))
387 return;
388 val &= ~VIDEO_DIP_ENABLE;
389 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300390 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300391 return;
392 }
393
Paulo Zanonif278d972012-05-28 16:42:50 -0300394 switch (intel_hdmi->sdvox_reg) {
395 case SDVOB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300396 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300397 break;
398 case SDVOC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300399 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300400 break;
401 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300402 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300403 return;
404 }
405
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300406 if (port != (val & VIDEO_DIP_PORT_MASK)) {
407 if (val & VIDEO_DIP_ENABLE) {
408 val &= ~VIDEO_DIP_ENABLE;
409 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300410 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300411 }
412 val &= ~VIDEO_DIP_PORT_MASK;
413 val |= port;
414 }
415
Paulo Zanoni822974a2012-05-28 16:42:51 -0300416 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300417 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300418
Paulo Zanonif278d972012-05-28 16:42:50 -0300419 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300420 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300421
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300422 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
423 intel_hdmi_set_spd_infoframe(encoder);
424}
425
426static void ibx_set_infoframes(struct drm_encoder *encoder,
427 struct drm_display_mode *adjusted_mode)
428{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300429 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
430 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
431 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
432 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
433 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300434 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300435
Daniel Vetterafba0182012-06-12 16:36:45 +0200436 assert_hdmi_port_disabled(intel_hdmi);
437
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300438 /* See the big comment in g4x_set_infoframes() */
439 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
440
441 if (!intel_hdmi->has_hdmi_sink) {
442 if (!(val & VIDEO_DIP_ENABLE))
443 return;
444 val &= ~VIDEO_DIP_ENABLE;
445 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300446 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300447 return;
448 }
449
Paulo Zanonif278d972012-05-28 16:42:50 -0300450 switch (intel_hdmi->sdvox_reg) {
451 case HDMIB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300452 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300453 break;
454 case HDMIC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300455 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300456 break;
457 case HDMID:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300458 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300459 break;
460 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300461 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300462 return;
463 }
464
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300465 if (port != (val & VIDEO_DIP_PORT_MASK)) {
466 if (val & VIDEO_DIP_ENABLE) {
467 val &= ~VIDEO_DIP_ENABLE;
468 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300469 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300470 }
471 val &= ~VIDEO_DIP_PORT_MASK;
472 val |= port;
473 }
474
Paulo Zanoni822974a2012-05-28 16:42:51 -0300475 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300476 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
477 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300478
Paulo Zanonif278d972012-05-28 16:42:50 -0300479 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300480 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300481
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300482 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
483 intel_hdmi_set_spd_infoframe(encoder);
484}
485
486static void cpt_set_infoframes(struct drm_encoder *encoder,
487 struct drm_display_mode *adjusted_mode)
488{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300489 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
490 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
491 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
492 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
493 u32 val = I915_READ(reg);
494
Daniel Vetterafba0182012-06-12 16:36:45 +0200495 assert_hdmi_port_disabled(intel_hdmi);
496
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300497 /* See the big comment in g4x_set_infoframes() */
498 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
499
500 if (!intel_hdmi->has_hdmi_sink) {
501 if (!(val & VIDEO_DIP_ENABLE))
502 return;
503 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
504 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300505 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300506 return;
507 }
508
Paulo Zanoni822974a2012-05-28 16:42:51 -0300509 /* Set both together, unset both together: see the spec. */
510 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300511 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
512 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300513
514 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300515 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300516
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300517 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
518 intel_hdmi_set_spd_infoframe(encoder);
519}
520
521static void vlv_set_infoframes(struct drm_encoder *encoder,
522 struct drm_display_mode *adjusted_mode)
523{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300524 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
525 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
526 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
527 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
528 u32 val = I915_READ(reg);
529
Daniel Vetterafba0182012-06-12 16:36:45 +0200530 assert_hdmi_port_disabled(intel_hdmi);
531
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300532 /* See the big comment in g4x_set_infoframes() */
533 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
534
535 if (!intel_hdmi->has_hdmi_sink) {
536 if (!(val & VIDEO_DIP_ENABLE))
537 return;
538 val &= ~VIDEO_DIP_ENABLE;
539 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300540 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300541 return;
542 }
543
Paulo Zanoni822974a2012-05-28 16:42:51 -0300544 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300545 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
546 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300547
548 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300549 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300550
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300551 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
552 intel_hdmi_set_spd_infoframe(encoder);
553}
554
555static void hsw_set_infoframes(struct drm_encoder *encoder,
556 struct drm_display_mode *adjusted_mode)
557{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300558 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
559 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
560 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
561 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300562 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300563
Daniel Vetterafba0182012-06-12 16:36:45 +0200564 assert_hdmi_port_disabled(intel_hdmi);
565
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300566 if (!intel_hdmi->has_hdmi_sink) {
567 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300568 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300569 return;
570 }
571
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300572 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
573 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
574
575 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300576 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300577
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300578 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
579 intel_hdmi_set_spd_infoframe(encoder);
580}
581
Eric Anholt7d573822009-01-02 13:33:00 -0800582static void intel_hdmi_mode_set(struct drm_encoder *encoder,
583 struct drm_display_mode *mode,
584 struct drm_display_mode *adjusted_mode)
585{
586 struct drm_device *dev = encoder->dev;
587 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300588 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100589 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800590 u32 sdvox;
591
Paulo Zanonib659c3d2012-05-28 16:42:56 -0300592 sdvox = SDVO_ENCODING_HDMI;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700593 if (!HAS_PCH_SPLIT(dev))
594 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400595 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
596 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
597 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
598 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800599
Jesse Barnes020f6702011-06-24 12:19:25 -0700600 if (intel_crtc->bpp > 24)
601 sdvox |= COLOR_FORMAT_12bpc;
602 else
603 sdvox |= COLOR_FORMAT_8bpc;
604
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800605 /* Required on CPT */
606 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
607 sdvox |= HDMI_MODE_SELECT;
608
David Härdeman3c17fe42010-09-24 21:44:32 +0200609 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800610 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
611 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800612 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200613 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800614 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200615 }
Eric Anholt7d573822009-01-02 13:33:00 -0800616
Jesse Barnes75770562011-10-12 09:01:58 -0700617 if (HAS_PCH_CPT(dev))
618 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200619 else if (intel_crtc->pipe == PIPE_B)
Jesse Barnes75770562011-10-12 09:01:58 -0700620 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800621
Chris Wilsonea5b2132010-08-04 13:50:23 +0100622 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
623 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200624
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300625 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800626}
627
Daniel Vetter85234cd2012-07-02 13:27:29 +0200628static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
629 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800630{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200631 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800632 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200633 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
634 u32 tmp;
635
636 tmp = I915_READ(intel_hdmi->sdvox_reg);
637
638 if (!(tmp & SDVO_ENABLE))
639 return false;
640
641 if (HAS_PCH_CPT(dev))
642 *pipe = PORT_TO_PIPE_CPT(tmp);
643 else
644 *pipe = PORT_TO_PIPE(tmp);
645
646 return true;
647}
648
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200649static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800650{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200651 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800652 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200653 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800654 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800655 u32 enable_bits = SDVO_ENABLE;
656
657 if (intel_hdmi->has_audio)
658 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800659
Chris Wilsonea5b2132010-08-04 13:50:23 +0100660 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000661
Daniel Vetter7a87c282012-06-05 11:03:39 +0200662 /* HW workaround for IBX, we need to move the port to transcoder A
663 * before disabling it. */
664 if (HAS_PCH_IBX(dev)) {
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200665 struct drm_crtc *crtc = encoder->base.crtc;
Daniel Vetter7a87c282012-06-05 11:03:39 +0200666 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
667
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200668 /* Restore the transcoder select bit. */
669 if (pipe == PIPE_B)
670 enable_bits |= SDVO_PIPE_B_SELECT;
671 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200672
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200673 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
674 * we do this anyway which shows more stable in testing.
675 */
676 if (HAS_PCH_SPLIT(dev)) {
677 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
678 POSTING_READ(intel_hdmi->sdvox_reg);
679 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200680
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200681 temp |= enable_bits;
682
683 I915_WRITE(intel_hdmi->sdvox_reg, temp);
684 POSTING_READ(intel_hdmi->sdvox_reg);
685
686 /* HW workaround, need to write this twice for issue that may result
687 * in first write getting masked.
688 */
689 if (HAS_PCH_SPLIT(dev)) {
690 I915_WRITE(intel_hdmi->sdvox_reg, temp);
691 POSTING_READ(intel_hdmi->sdvox_reg);
692 }
693}
694
695static void intel_disable_hdmi(struct intel_encoder *encoder)
696{
697 struct drm_device *dev = encoder->base.dev;
698 struct drm_i915_private *dev_priv = dev->dev_private;
699 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
700 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800701 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200702
703 temp = I915_READ(intel_hdmi->sdvox_reg);
704
705 /* HW workaround for IBX, we need to move the port to transcoder A
706 * before disabling it. */
707 if (HAS_PCH_IBX(dev)) {
708 struct drm_crtc *crtc = encoder->base.crtc;
709 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
710
711 if (temp & SDVO_PIPE_B_SELECT) {
712 temp &= ~SDVO_PIPE_B_SELECT;
713 I915_WRITE(intel_hdmi->sdvox_reg, temp);
714 POSTING_READ(intel_hdmi->sdvox_reg);
715
716 /* Again we need to write this twice. */
717 I915_WRITE(intel_hdmi->sdvox_reg, temp);
718 POSTING_READ(intel_hdmi->sdvox_reg);
719
720 /* Transcoder selection bits only update
721 * effectively on vblank. */
722 if (crtc)
723 intel_wait_for_vblank(dev, pipe);
724 else
725 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200726 }
727 }
728
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000729 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
730 * we do this anyway which shows more stable in testing.
731 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800732 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100733 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
734 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800735 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000736
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200737 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000738
Chris Wilsonea5b2132010-08-04 13:50:23 +0100739 I915_WRITE(intel_hdmi->sdvox_reg, temp);
740 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000741
742 /* HW workaround, need to write this twice for issue that may result
743 * in first write getting masked.
744 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800745 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100746 I915_WRITE(intel_hdmi->sdvox_reg, temp);
747 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000748 }
Eric Anholt7d573822009-01-02 13:33:00 -0800749}
750
Eric Anholt7d573822009-01-02 13:33:00 -0800751static int intel_hdmi_mode_valid(struct drm_connector *connector,
752 struct drm_display_mode *mode)
753{
754 if (mode->clock > 165000)
755 return MODE_CLOCK_HIGH;
756 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200757 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800758
759 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
760 return MODE_NO_DBLESCAN;
761
762 return MODE_OK;
763}
764
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200765bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
766 const struct drm_display_mode *mode,
767 struct drm_display_mode *adjusted_mode)
Eric Anholt7d573822009-01-02 13:33:00 -0800768{
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200769 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
770
771 if (intel_hdmi->color_range)
772 adjusted_mode->private_flags |= INTEL_MODE_LIMITED_COLOR_RANGE;
773
Eric Anholt7d573822009-01-02 13:33:00 -0800774 return true;
775}
776
Chris Wilson8ec22b22012-05-11 18:01:34 +0100777static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
778{
Paulo Zanoni30add222012-10-26 19:05:45 -0200779 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Chris Wilson8ec22b22012-05-11 18:01:34 +0100780 struct drm_i915_private *dev_priv = dev->dev_private;
781 uint32_t bit;
782
783 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100784 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100785 bit = HDMIB_HOTPLUG_LIVE_STATUS;
786 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100787 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100788 bit = HDMIC_HOTPLUG_LIVE_STATUS;
789 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100790 default:
791 bit = 0;
792 break;
793 }
794
795 return I915_READ(PORT_HOTPLUG_STAT) & bit;
796}
797
Keith Packardaa93d632009-05-05 09:52:46 -0700798static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100799intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800800{
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000801 struct drm_device *dev = connector->dev;
Chris Wilsondf0e9242010-09-09 16:20:55 +0100802 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200803 struct intel_digital_port *intel_dig_port =
804 hdmi_to_dig_port(intel_hdmi);
805 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000806 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700807 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700808 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800809
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000810
811 if (IS_G4X(dev) && !g4x_hdmi_connected(intel_hdmi))
Chris Wilson8ec22b22012-05-11 18:01:34 +0100812 return status;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000813 else if (HAS_PCH_SPLIT(dev) &&
814 !ibx_digital_port_connected(dev_priv, intel_dig_port))
815 return status;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100816
Chris Wilsonea5b2132010-08-04 13:50:23 +0100817 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800818 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700819 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800820 intel_gmbus_get_adapter(dev_priv,
821 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800822
Keith Packardaa93d632009-05-05 09:52:46 -0700823 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700824 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700825 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800826 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
827 intel_hdmi->has_hdmi_sink =
828 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800829 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700830 }
Keith Packardaa93d632009-05-05 09:52:46 -0700831 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800832 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800833
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100834 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800835 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
836 intel_hdmi->has_audio =
837 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200838 intel_encoder->type = INTEL_OUTPUT_HDMI;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100839 }
840
Keith Packardaa93d632009-05-05 09:52:46 -0700841 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800842}
843
Eric Anholt7d573822009-01-02 13:33:00 -0800844static int intel_hdmi_get_modes(struct drm_connector *connector)
845{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100846 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700847 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800848
849 /* We should parse the EDID data and find out if it's an HDMI sink so
850 * we can send audio to it.
851 */
852
Chris Wilsonf899fc62010-07-20 15:44:45 -0700853 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800854 intel_gmbus_get_adapter(dev_priv,
855 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800856}
857
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000858static bool
859intel_hdmi_detect_audio(struct drm_connector *connector)
860{
861 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
862 struct drm_i915_private *dev_priv = connector->dev->dev_private;
863 struct edid *edid;
864 bool has_audio = false;
865
866 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800867 intel_gmbus_get_adapter(dev_priv,
868 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000869 if (edid) {
870 if (edid->input & DRM_EDID_INPUT_DIGITAL)
871 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000872 kfree(edid);
873 }
874
875 return has_audio;
876}
877
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100878static int
879intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300880 struct drm_property *property,
881 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100882{
883 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200884 struct intel_digital_port *intel_dig_port =
885 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +0000886 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100887 int ret;
888
Rob Clark662595d2012-10-11 20:36:04 -0500889 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100890 if (ret)
891 return ret;
892
Chris Wilson3f43c482011-05-12 22:17:24 +0100893 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800894 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000895 bool has_audio;
896
897 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100898 return 0;
899
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000900 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100901
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800902 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000903 has_audio = intel_hdmi_detect_audio(connector);
904 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800905 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000906
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800907 if (i == HDMI_AUDIO_OFF_DVI)
908 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100909
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000910 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100911 goto done;
912 }
913
Chris Wilsone953fd72011-02-21 22:23:52 +0000914 if (property == dev_priv->broadcast_rgb_property) {
915 if (val == !!intel_hdmi->color_range)
916 return 0;
917
918 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
919 goto done;
920 }
921
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100922 return -EINVAL;
923
924done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +0000925 if (intel_dig_port->base.base.crtc)
926 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100927
928 return 0;
929}
930
Eric Anholt7d573822009-01-02 13:33:00 -0800931static void intel_hdmi_destroy(struct drm_connector *connector)
932{
Eric Anholt7d573822009-01-02 13:33:00 -0800933 drm_sysfs_connector_remove(connector);
934 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800935 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800936}
937
938static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
Eric Anholt7d573822009-01-02 13:33:00 -0800939 .mode_fixup = intel_hdmi_mode_fixup,
Eric Anholt7d573822009-01-02 13:33:00 -0800940 .mode_set = intel_hdmi_mode_set,
Daniel Vetter1f703852012-07-11 16:51:39 +0200941 .disable = intel_encoder_noop,
Eric Anholt7d573822009-01-02 13:33:00 -0800942};
943
944static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200945 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800946 .detect = intel_hdmi_detect,
947 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100948 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800949 .destroy = intel_hdmi_destroy,
950};
951
952static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
953 .get_modes = intel_hdmi_get_modes,
954 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100955 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800956};
957
Eric Anholt7d573822009-01-02 13:33:00 -0800958static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100959 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800960};
961
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100962static void
963intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
964{
Chris Wilson3f43c482011-05-12 22:17:24 +0100965 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000966 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100967}
968
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200969void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
970 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -0800971{
Paulo Zanonib9cb2342012-10-26 19:05:47 -0200972 struct drm_connector *connector = &intel_connector->base;
973 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
974 struct intel_encoder *intel_encoder = &intel_dig_port->base;
975 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800976 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -0200977 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -0800978
Eric Anholt7d573822009-01-02 13:33:00 -0800979 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400980 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800981 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
982
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000983 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100984 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800985 connector->doublescan_allowed = 0;
986
Daniel Vetter08d644a2012-07-12 20:19:59 +0200987 switch (port) {
988 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700989 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800990 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200991 break;
992 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700993 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800994 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200995 break;
996 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700997 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800998 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200999 break;
1000 case PORT_A:
1001 /* Internal port only for eDP. */
1002 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001003 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001004 }
Eric Anholt7d573822009-01-02 13:33:00 -08001005
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301006 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +02001007 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001008 intel_hdmi->set_infoframes = g4x_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001009 } else if (IS_VALLEYVIEW(dev)) {
1010 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001011 intel_hdmi->set_infoframes = vlv_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001012 } else if (IS_HASWELL(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001013 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001014 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001015 } else if (HAS_PCH_IBX(dev)) {
1016 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001017 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001018 } else {
1019 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001020 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301021 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001022
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001023 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001024 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1025 else
1026 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001027
1028 intel_hdmi_add_properties(intel_hdmi, connector);
1029
1030 intel_connector_attach_encoder(intel_connector, intel_encoder);
1031 drm_sysfs_connector_add(connector);
1032
1033 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1034 * 0xd. Failure to do so will result in spurious interrupts being
1035 * generated on the port when a cable is not attached.
1036 */
1037 if (IS_G4X(dev) && !IS_GM45(dev)) {
1038 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1039 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1040 }
1041}
1042
1043void intel_hdmi_init(struct drm_device *dev, int sdvox_reg, enum port port)
1044{
1045 struct intel_digital_port *intel_dig_port;
1046 struct intel_encoder *intel_encoder;
1047 struct drm_encoder *encoder;
1048 struct intel_connector *intel_connector;
1049
1050 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1051 if (!intel_dig_port)
1052 return;
1053
1054 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1055 if (!intel_connector) {
1056 kfree(intel_dig_port);
1057 return;
1058 }
1059
1060 intel_encoder = &intel_dig_port->base;
1061 encoder = &intel_encoder->base;
1062
1063 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1064 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001065 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
1066
1067 intel_encoder->enable = intel_enable_hdmi;
1068 intel_encoder->disable = intel_disable_hdmi;
1069 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001070
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001071 intel_encoder->type = INTEL_OUTPUT_HDMI;
1072 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1073 intel_encoder->cloneable = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001074
Paulo Zanoni174edf12012-10-26 19:05:50 -02001075 intel_dig_port->port = port;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001076 intel_dig_port->hdmi.sdvox_reg = sdvox_reg;
1077 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001078
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001079 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001080}