blob: de6f4c2c82acfc430bee0483dd39915004296ff8 [file] [log] [blame]
Eric Anholt7d573822009-01-02 13:33:00 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
27 */
28
29#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Eric Anholt7d573822009-01-02 13:33:00 -080031#include <linux/delay.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
Keith Packardaa93d632009-05-05 09:52:46 -070035#include "drm_edid.h"
Eric Anholt7d573822009-01-02 13:33:00 -080036#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030040struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010041{
Chris Wilson4ef69c72010-09-09 15:14:28 +010042 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010043}
44
Chris Wilsondf0e9242010-09-09 16:20:55 +010045static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
46{
47 return container_of(intel_attached_encoder(connector),
48 struct intel_hdmi, base);
49}
50
Jesse Barnes45187ac2011-08-03 09:22:55 -070051void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020052{
Jesse Barnes45187ac2011-08-03 09:22:55 -070053 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020054 uint8_t sum = 0;
55 unsigned i;
56
Jesse Barnes45187ac2011-08-03 09:22:55 -070057 frame->checksum = 0;
58 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020059
Jesse Barnes64a8fc02011-09-22 11:16:00 +053060 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020061 sum += data[i];
62
Jesse Barnes45187ac2011-08-03 09:22:55 -070063 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020064}
65
Daniel Vetterbc2481f2012-05-08 15:18:32 +020066static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020067{
Jesse Barnes45187ac2011-08-03 09:22:55 -070068 switch (frame->type) {
69 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030070 return VIDEO_DIP_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070071 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030072 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070073 default:
74 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030075 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070077}
78
Daniel Vetterbc2481f2012-05-08 15:18:32 +020079static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070080{
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 switch (frame->type) {
82 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030083 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070084 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030085 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030086 default:
87 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030088 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030089 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030090}
91
Paulo Zanoni2da8af52012-05-14 17:12:51 -030092static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
93{
94 switch (frame->type) {
95 case DIP_TYPE_AVI:
96 return VIDEO_DIP_ENABLE_AVI_HSW;
97 case DIP_TYPE_SPD:
98 return VIDEO_DIP_ENABLE_SPD_HSW;
99 default:
100 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
101 return 0;
102 }
103}
104
105static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe)
106{
107 switch (frame->type) {
108 case DIP_TYPE_AVI:
109 return HSW_TVIDEO_DIP_AVI_DATA(pipe);
110 case DIP_TYPE_SPD:
111 return HSW_TVIDEO_DIP_SPD_DATA(pipe);
112 default:
113 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
114 return 0;
115 }
116}
117
Daniel Vettera3da1df2012-05-08 15:19:06 +0200118static void g4x_write_infoframe(struct drm_encoder *encoder,
119 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700120{
121 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200122 struct drm_device *dev = encoder->dev;
123 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300124 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700125 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200126
Paulo Zanoni822974a2012-05-28 16:42:51 -0300127 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
128
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300129 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200130 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700131
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200132 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300133
134 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700135
136 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200137 I915_WRITE(VIDEO_DIP_DATA, *data);
138 data++;
139 }
140
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200141 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300142 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200143 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700144
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300145 I915_WRITE(VIDEO_DIP_CTL, val);
David Härdeman3c17fe42010-09-24 21:44:32 +0200146}
147
Paulo Zanonifdf12502012-05-04 17:18:24 -0300148static void ibx_write_infoframe(struct drm_encoder *encoder,
149 struct dip_infoframe *frame)
150{
151 uint32_t *data = (uint32_t *)frame;
152 struct drm_device *dev = encoder->dev;
153 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300154 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300155 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
156 unsigned i, len = DIP_HEADER_SIZE + frame->len;
157 u32 val = I915_READ(reg);
158
Paulo Zanoni822974a2012-05-28 16:42:51 -0300159 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
160
Paulo Zanonifdf12502012-05-04 17:18:24 -0300161 intel_wait_for_vblank(dev, intel_crtc->pipe);
162
163 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200164 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300165
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200166 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300167
168 I915_WRITE(reg, val);
169
170 for (i = 0; i < len; i += 4) {
171 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
172 data++;
173 }
174
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200175 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300176 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200177 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300178
179 I915_WRITE(reg, val);
180}
181
182static void cpt_write_infoframe(struct drm_encoder *encoder,
183 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700184{
185 uint32_t *data = (uint32_t *)frame;
186 struct drm_device *dev = encoder->dev;
187 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300188 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700189 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
190 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300191 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700192
Paulo Zanoni822974a2012-05-28 16:42:51 -0300193 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
194
Jesse Barnes45187ac2011-08-03 09:22:55 -0700195 intel_wait_for_vblank(dev, intel_crtc->pipe);
196
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530197 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200198 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700199
Paulo Zanoniecb97852012-05-04 17:18:21 -0300200 /* The DIP control register spec says that we need to update the AVI
201 * infoframe without clearing its enable bit */
Paulo Zanoni822974a2012-05-28 16:42:51 -0300202 if (frame->type != DIP_TYPE_AVI)
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200203 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300204
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300205 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700206
207 for (i = 0; i < len; i += 4) {
208 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
209 data++;
210 }
211
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200212 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300213 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200214 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700215
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300216 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700217}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700218
219static void vlv_write_infoframe(struct drm_encoder *encoder,
220 struct dip_infoframe *frame)
221{
222 uint32_t *data = (uint32_t *)frame;
223 struct drm_device *dev = encoder->dev;
224 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300225 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700226 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
227 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300228 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700229
Paulo Zanoni822974a2012-05-28 16:42:51 -0300230 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
231
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700232 intel_wait_for_vblank(dev, intel_crtc->pipe);
233
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700234 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200235 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700236
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200237 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300238
239 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700240
241 for (i = 0; i < len; i += 4) {
242 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
243 data++;
244 }
245
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200246 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300247 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200248 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700249
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300250 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700251}
252
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300253static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300254 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300255{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300256 uint32_t *data = (uint32_t *)frame;
257 struct drm_device *dev = encoder->dev;
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
260 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
261 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
262 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
263 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300264
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300265 if (data_reg == 0)
266 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300267
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300268 intel_wait_for_vblank(dev, intel_crtc->pipe);
269
270 val &= ~hsw_infoframe_enable(frame);
271 I915_WRITE(ctl_reg, val);
272
273 for (i = 0; i < len; i += 4) {
274 I915_WRITE(data_reg + i, *data);
275 data++;
276 }
277
278 val |= hsw_infoframe_enable(frame);
279 I915_WRITE(ctl_reg, val);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300280}
281
Jesse Barnes45187ac2011-08-03 09:22:55 -0700282static void intel_set_infoframe(struct drm_encoder *encoder,
283 struct dip_infoframe *frame)
284{
285 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
286
Jesse Barnes45187ac2011-08-03 09:22:55 -0700287 intel_dip_infoframe_csum(frame);
288 intel_hdmi->write_infoframe(encoder, frame);
289}
290
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300291static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300292 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700293{
294 struct dip_infoframe avi_if = {
295 .type = DIP_TYPE_AVI,
296 .ver = DIP_VERSION_AVI,
297 .len = DIP_LEN_AVI,
298 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700299
Paulo Zanonic846b612012-04-13 16:31:41 -0300300 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
301 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
302
Jesse Barnes45187ac2011-08-03 09:22:55 -0700303 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700304}
305
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300306static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700307{
308 struct dip_infoframe spd_if;
309
310 memset(&spd_if, 0, sizeof(spd_if));
311 spd_if.type = DIP_TYPE_SPD;
312 spd_if.ver = DIP_VERSION_SPD;
313 spd_if.len = DIP_LEN_SPD;
314 strcpy(spd_if.body.spd.vn, "Intel");
315 strcpy(spd_if.body.spd.pd, "Integrated gfx");
316 spd_if.body.spd.sdi = DIP_SPD_PC;
317
318 intel_set_infoframe(encoder, &spd_if);
319}
320
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300321static void g4x_set_infoframes(struct drm_encoder *encoder,
322 struct drm_display_mode *adjusted_mode)
323{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300324 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
325 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
326 u32 reg = VIDEO_DIP_CTL;
327 u32 val = I915_READ(reg);
328
329 /* If the registers were not initialized yet, they might be zeroes,
330 * which means we're selecting the AVI DIP and we're setting its
331 * frequency to once. This seems to really confuse the HW and make
332 * things stop working (the register spec says the AVI always needs to
333 * be sent every VSync). So here we avoid writing to the register more
334 * than we need and also explicitly select the AVI DIP and explicitly
335 * set its frequency to every VSync. Avoiding to write it twice seems to
336 * be enough to solve the problem, but being defensive shouldn't hurt us
337 * either. */
338 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
339
340 if (!intel_hdmi->has_hdmi_sink) {
341 if (!(val & VIDEO_DIP_ENABLE))
342 return;
343 val &= ~VIDEO_DIP_ENABLE;
344 I915_WRITE(reg, val);
345 return;
346 }
347
Paulo Zanonif278d972012-05-28 16:42:50 -0300348 val &= ~VIDEO_DIP_PORT_MASK;
349 switch (intel_hdmi->sdvox_reg) {
350 case SDVOB:
351 val |= VIDEO_DIP_PORT_B;
352 break;
353 case SDVOC:
354 val |= VIDEO_DIP_PORT_C;
355 break;
356 default:
357 return;
358 }
359
Paulo Zanoni822974a2012-05-28 16:42:51 -0300360 val |= VIDEO_DIP_ENABLE;
361
Paulo Zanonif278d972012-05-28 16:42:50 -0300362 I915_WRITE(reg, val);
363
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300364 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
365 intel_hdmi_set_spd_infoframe(encoder);
366}
367
368static void ibx_set_infoframes(struct drm_encoder *encoder,
369 struct drm_display_mode *adjusted_mode)
370{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300371 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
372 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
373 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
374 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
375 u32 val = I915_READ(reg);
376
377 /* See the big comment in g4x_set_infoframes() */
378 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
379
380 if (!intel_hdmi->has_hdmi_sink) {
381 if (!(val & VIDEO_DIP_ENABLE))
382 return;
383 val &= ~VIDEO_DIP_ENABLE;
384 I915_WRITE(reg, val);
385 return;
386 }
387
Paulo Zanonif278d972012-05-28 16:42:50 -0300388 val &= ~VIDEO_DIP_PORT_MASK;
389 switch (intel_hdmi->sdvox_reg) {
390 case HDMIB:
391 val |= VIDEO_DIP_PORT_B;
392 break;
393 case HDMIC:
394 val |= VIDEO_DIP_PORT_C;
395 break;
396 case HDMID:
397 val |= VIDEO_DIP_PORT_D;
398 break;
399 default:
400 return;
401 }
402
Paulo Zanoni822974a2012-05-28 16:42:51 -0300403 val |= VIDEO_DIP_ENABLE;
404
Paulo Zanonif278d972012-05-28 16:42:50 -0300405 I915_WRITE(reg, val);
406
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300407 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
408 intel_hdmi_set_spd_infoframe(encoder);
409}
410
411static void cpt_set_infoframes(struct drm_encoder *encoder,
412 struct drm_display_mode *adjusted_mode)
413{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300414 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
415 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
416 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
417 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
418 u32 val = I915_READ(reg);
419
420 /* See the big comment in g4x_set_infoframes() */
421 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
422
423 if (!intel_hdmi->has_hdmi_sink) {
424 if (!(val & VIDEO_DIP_ENABLE))
425 return;
426 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
427 I915_WRITE(reg, val);
428 return;
429 }
430
Paulo Zanoni822974a2012-05-28 16:42:51 -0300431 /* Set both together, unset both together: see the spec. */
432 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
433
434 I915_WRITE(reg, val);
435
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300436 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
437 intel_hdmi_set_spd_infoframe(encoder);
438}
439
440static void vlv_set_infoframes(struct drm_encoder *encoder,
441 struct drm_display_mode *adjusted_mode)
442{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300443 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
444 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
445 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
446 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
447 u32 val = I915_READ(reg);
448
449 /* See the big comment in g4x_set_infoframes() */
450 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
451
452 if (!intel_hdmi->has_hdmi_sink) {
453 if (!(val & VIDEO_DIP_ENABLE))
454 return;
455 val &= ~VIDEO_DIP_ENABLE;
456 I915_WRITE(reg, val);
457 return;
458 }
459
Paulo Zanoni822974a2012-05-28 16:42:51 -0300460 val |= VIDEO_DIP_ENABLE;
461
462 I915_WRITE(reg, val);
463
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300464 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
465 intel_hdmi_set_spd_infoframe(encoder);
466}
467
468static void hsw_set_infoframes(struct drm_encoder *encoder,
469 struct drm_display_mode *adjusted_mode)
470{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300471 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
472 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
473 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
474 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
475
476 if (!intel_hdmi->has_hdmi_sink) {
477 I915_WRITE(reg, 0);
478 return;
479 }
480
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300481 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
482 intel_hdmi_set_spd_infoframe(encoder);
483}
484
Eric Anholt7d573822009-01-02 13:33:00 -0800485static void intel_hdmi_mode_set(struct drm_encoder *encoder,
486 struct drm_display_mode *mode,
487 struct drm_display_mode *adjusted_mode)
488{
489 struct drm_device *dev = encoder->dev;
490 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300491 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100492 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800493 u32 sdvox;
494
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400495 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700496 if (!HAS_PCH_SPLIT(dev))
497 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400498 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
499 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
500 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
501 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800502
Jesse Barnes020f6702011-06-24 12:19:25 -0700503 if (intel_crtc->bpp > 24)
504 sdvox |= COLOR_FORMAT_12bpc;
505 else
506 sdvox |= COLOR_FORMAT_8bpc;
507
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800508 /* Required on CPT */
509 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
510 sdvox |= HDMI_MODE_SELECT;
511
David Härdeman3c17fe42010-09-24 21:44:32 +0200512 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800513 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
514 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800515 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200516 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800517 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200518 }
Eric Anholt7d573822009-01-02 13:33:00 -0800519
Jesse Barnes75770562011-10-12 09:01:58 -0700520 if (HAS_PCH_CPT(dev))
521 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
522 else if (intel_crtc->pipe == 1)
523 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800524
Chris Wilsonea5b2132010-08-04 13:50:23 +0100525 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
526 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200527
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300528 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800529}
530
531static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
532{
533 struct drm_device *dev = encoder->dev;
534 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100535 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800536 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800537 u32 enable_bits = SDVO_ENABLE;
538
539 if (intel_hdmi->has_audio)
540 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800541
Chris Wilsonea5b2132010-08-04 13:50:23 +0100542 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000543
544 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
545 * we do this anyway which shows more stable in testing.
546 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800547 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100548 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
549 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800550 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000551
552 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800553 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000554 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800555 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000556 }
557
Chris Wilsonea5b2132010-08-04 13:50:23 +0100558 I915_WRITE(intel_hdmi->sdvox_reg, temp);
559 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000560
561 /* HW workaround, need to write this twice for issue that may result
562 * in first write getting masked.
563 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800564 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100565 I915_WRITE(intel_hdmi->sdvox_reg, temp);
566 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000567 }
Eric Anholt7d573822009-01-02 13:33:00 -0800568}
569
Eric Anholt7d573822009-01-02 13:33:00 -0800570static int intel_hdmi_mode_valid(struct drm_connector *connector,
571 struct drm_display_mode *mode)
572{
573 if (mode->clock > 165000)
574 return MODE_CLOCK_HIGH;
575 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200576 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800577
578 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
579 return MODE_NO_DBLESCAN;
580
581 return MODE_OK;
582}
583
584static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
585 struct drm_display_mode *mode,
586 struct drm_display_mode *adjusted_mode)
587{
588 return true;
589}
590
Chris Wilson8ec22b22012-05-11 18:01:34 +0100591static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
592{
593 struct drm_device *dev = intel_hdmi->base.base.dev;
594 struct drm_i915_private *dev_priv = dev->dev_private;
595 uint32_t bit;
596
597 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100598 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100599 bit = HDMIB_HOTPLUG_LIVE_STATUS;
600 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100601 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100602 bit = HDMIC_HOTPLUG_LIVE_STATUS;
603 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100604 default:
605 bit = 0;
606 break;
607 }
608
609 return I915_READ(PORT_HOTPLUG_STAT) & bit;
610}
611
Keith Packardaa93d632009-05-05 09:52:46 -0700612static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100613intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800614{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100615 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700616 struct drm_i915_private *dev_priv = connector->dev->dev_private;
617 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700618 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800619
Chris Wilson8ec22b22012-05-11 18:01:34 +0100620 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
621 return status;
622
Chris Wilsonea5b2132010-08-04 13:50:23 +0100623 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800624 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700625 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800626 intel_gmbus_get_adapter(dev_priv,
627 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800628
Keith Packardaa93d632009-05-05 09:52:46 -0700629 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700630 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700631 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800632 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
633 intel_hdmi->has_hdmi_sink =
634 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800635 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700636 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800637 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700638 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800639 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800640
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100641 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800642 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
643 intel_hdmi->has_audio =
644 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100645 }
646
Keith Packardaa93d632009-05-05 09:52:46 -0700647 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800648}
649
Eric Anholt7d573822009-01-02 13:33:00 -0800650static int intel_hdmi_get_modes(struct drm_connector *connector)
651{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100652 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700653 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800654
655 /* We should parse the EDID data and find out if it's an HDMI sink so
656 * we can send audio to it.
657 */
658
Chris Wilsonf899fc62010-07-20 15:44:45 -0700659 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800660 intel_gmbus_get_adapter(dev_priv,
661 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800662}
663
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000664static bool
665intel_hdmi_detect_audio(struct drm_connector *connector)
666{
667 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
668 struct drm_i915_private *dev_priv = connector->dev->dev_private;
669 struct edid *edid;
670 bool has_audio = false;
671
672 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800673 intel_gmbus_get_adapter(dev_priv,
674 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000675 if (edid) {
676 if (edid->input & DRM_EDID_INPUT_DIGITAL)
677 has_audio = drm_detect_monitor_audio(edid);
678
679 connector->display_info.raw_edid = NULL;
680 kfree(edid);
681 }
682
683 return has_audio;
684}
685
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100686static int
687intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300688 struct drm_property *property,
689 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100690{
691 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000692 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100693 int ret;
694
695 ret = drm_connector_property_set_value(connector, property, val);
696 if (ret)
697 return ret;
698
Chris Wilson3f43c482011-05-12 22:17:24 +0100699 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800700 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000701 bool has_audio;
702
703 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100704 return 0;
705
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000706 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100707
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800708 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000709 has_audio = intel_hdmi_detect_audio(connector);
710 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800711 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000712
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800713 if (i == HDMI_AUDIO_OFF_DVI)
714 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100715
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000716 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100717 goto done;
718 }
719
Chris Wilsone953fd72011-02-21 22:23:52 +0000720 if (property == dev_priv->broadcast_rgb_property) {
721 if (val == !!intel_hdmi->color_range)
722 return 0;
723
724 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
725 goto done;
726 }
727
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100728 return -EINVAL;
729
730done:
731 if (intel_hdmi->base.base.crtc) {
732 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
733 drm_crtc_helper_set_mode(crtc, &crtc->mode,
734 crtc->x, crtc->y,
735 crtc->fb);
736 }
737
738 return 0;
739}
740
Eric Anholt7d573822009-01-02 13:33:00 -0800741static void intel_hdmi_destroy(struct drm_connector *connector)
742{
Eric Anholt7d573822009-01-02 13:33:00 -0800743 drm_sysfs_connector_remove(connector);
744 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800745 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800746}
747
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300748static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
749 .dpms = intel_ddi_dpms,
750 .mode_fixup = intel_hdmi_mode_fixup,
751 .prepare = intel_encoder_prepare,
752 .mode_set = intel_ddi_mode_set,
753 .commit = intel_encoder_commit,
754};
755
Eric Anholt7d573822009-01-02 13:33:00 -0800756static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
757 .dpms = intel_hdmi_dpms,
758 .mode_fixup = intel_hdmi_mode_fixup,
759 .prepare = intel_encoder_prepare,
760 .mode_set = intel_hdmi_mode_set,
761 .commit = intel_encoder_commit,
762};
763
764static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700765 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800766 .detect = intel_hdmi_detect,
767 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100768 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800769 .destroy = intel_hdmi_destroy,
770};
771
772static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
773 .get_modes = intel_hdmi_get_modes,
774 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100775 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800776};
777
Eric Anholt7d573822009-01-02 13:33:00 -0800778static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100779 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800780};
781
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100782static void
783intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
784{
Chris Wilson3f43c482011-05-12 22:17:24 +0100785 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000786 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100787}
788
Eric Anholt7d573822009-01-02 13:33:00 -0800789void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
790{
791 struct drm_i915_private *dev_priv = dev->dev_private;
792 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700793 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800794 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100795 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530796 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800797
Chris Wilsonea5b2132010-08-04 13:50:23 +0100798 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
799 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800800 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800801
802 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
803 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100804 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800805 return;
806 }
807
Chris Wilsonea5b2132010-08-04 13:50:23 +0100808 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100809 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
810 DRM_MODE_ENCODER_TMDS);
811
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800812 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800813 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400814 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800815 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
816
Eric Anholt21d40d32010-03-25 11:11:14 -0700817 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800818
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000819 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100820 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800821 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700822 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800823
824 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800825 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700826 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700827 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800828 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800829 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700830 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700831 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800832 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800833 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700834 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700835 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800836 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800837 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700838 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700839 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800840 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800841 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700842 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700843 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800844 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300845 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
846 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
847 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
848 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
849 intel_hdmi->ddi_port = PORT_B;
850 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
851 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
852 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
853 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
854 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
855 intel_hdmi->ddi_port = PORT_C;
856 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
857 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
858 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
859 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
860 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
861 intel_hdmi->ddi_port = PORT_D;
862 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300863 } else {
864 /* If we got an unknown sdvox_reg, things are pretty much broken
865 * in a way that we should let the kernel know about it */
866 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800867 }
Eric Anholt7d573822009-01-02 13:33:00 -0800868
Chris Wilsonea5b2132010-08-04 13:50:23 +0100869 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800870
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530871 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200872 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300873 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530874 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700875 } else if (IS_VALLEYVIEW(dev)) {
876 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300877 intel_hdmi->set_infoframes = vlv_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700878 for_each_pipe(i)
879 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300880 } else if (IS_HASWELL(dev)) {
881 /* FIXME: Haswell has a new set of DIP frame registers, but we are
882 * just doing the minimal required for HDMI to work at this stage.
883 */
884 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300885 intel_hdmi->set_infoframes = hsw_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300886 for_each_pipe(i)
887 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300888 } else if (HAS_PCH_IBX(dev)) {
889 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300890 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300891 for_each_pipe(i)
892 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
893 } else {
894 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300895 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530896 for_each_pipe(i)
897 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
898 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700899
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300900 if (IS_HASWELL(dev))
901 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
902 else
903 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800904
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100905 intel_hdmi_add_properties(intel_hdmi, connector);
906
Chris Wilsondf0e9242010-09-09 16:20:55 +0100907 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800908 drm_sysfs_connector_add(connector);
909
910 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
911 * 0xd. Failure to do so will result in spurious interrupts being
912 * generated on the port when a cable is not attached.
913 */
914 if (IS_G4X(dev) && !IS_GM45(dev)) {
915 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
916 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
917 }
Eric Anholt7d573822009-01-02 13:33:00 -0800918}