blob: 1df1ec764a0185ecb637bf949882ecb5af5364f4 [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 Zanoni1d4f85a2012-05-04 17:18:18 -0300127 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200128 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700129
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200130 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300131 val |= VIDEO_DIP_ENABLE;
132
133 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700134
135 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200136 I915_WRITE(VIDEO_DIP_DATA, *data);
137 data++;
138 }
139
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200140 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300141 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200142 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300144 I915_WRITE(VIDEO_DIP_CTL, val);
David Härdeman3c17fe42010-09-24 21:44:32 +0200145}
146
Paulo Zanonifdf12502012-05-04 17:18:24 -0300147static void ibx_write_infoframe(struct drm_encoder *encoder,
148 struct dip_infoframe *frame)
149{
150 uint32_t *data = (uint32_t *)frame;
151 struct drm_device *dev = encoder->dev;
152 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300153 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300154 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
155 unsigned i, len = DIP_HEADER_SIZE + frame->len;
156 u32 val = I915_READ(reg);
157
158 intel_wait_for_vblank(dev, intel_crtc->pipe);
159
160 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200161 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300162
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200163 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300164 val |= VIDEO_DIP_ENABLE;
165
166 I915_WRITE(reg, val);
167
168 for (i = 0; i < len; i += 4) {
169 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
170 data++;
171 }
172
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200173 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300174 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200175 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300176
177 I915_WRITE(reg, val);
178}
179
180static void cpt_write_infoframe(struct drm_encoder *encoder,
181 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700182{
183 uint32_t *data = (uint32_t *)frame;
184 struct drm_device *dev = encoder->dev;
185 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300186 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700187 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
188 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300189 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700190
191 intel_wait_for_vblank(dev, intel_crtc->pipe);
192
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530193 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200194 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700195
Paulo Zanoniecb97852012-05-04 17:18:21 -0300196 /* The DIP control register spec says that we need to update the AVI
197 * infoframe without clearing its enable bit */
198 if (frame->type == DIP_TYPE_AVI)
199 val |= VIDEO_DIP_ENABLE_AVI;
200 else
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200201 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300202
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300203 val |= VIDEO_DIP_ENABLE;
204
205 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
230 intel_wait_for_vblank(dev, intel_crtc->pipe);
231
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700232 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200233 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700234
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200235 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300236 val |= VIDEO_DIP_ENABLE;
237
238 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700239
240 for (i = 0; i < len; i += 4) {
241 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
242 data++;
243 }
244
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200245 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300246 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200247 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700248
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300249 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700250}
251
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300252static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300253 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300254{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300255 uint32_t *data = (uint32_t *)frame;
256 struct drm_device *dev = encoder->dev;
257 struct drm_i915_private *dev_priv = dev->dev_private;
258 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
259 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
260 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
261 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
262 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300263
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300264 if (data_reg == 0)
265 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300266
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300267 intel_wait_for_vblank(dev, intel_crtc->pipe);
268
269 val &= ~hsw_infoframe_enable(frame);
270 I915_WRITE(ctl_reg, val);
271
272 for (i = 0; i < len; i += 4) {
273 I915_WRITE(data_reg + i, *data);
274 data++;
275 }
276
277 val |= hsw_infoframe_enable(frame);
278 I915_WRITE(ctl_reg, val);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300279}
280
Jesse Barnes45187ac2011-08-03 09:22:55 -0700281static void intel_set_infoframe(struct drm_encoder *encoder,
282 struct dip_infoframe *frame)
283{
284 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
285
Jesse Barnes45187ac2011-08-03 09:22:55 -0700286 intel_dip_infoframe_csum(frame);
287 intel_hdmi->write_infoframe(encoder, frame);
288}
289
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300290static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300291 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700292{
293 struct dip_infoframe avi_if = {
294 .type = DIP_TYPE_AVI,
295 .ver = DIP_VERSION_AVI,
296 .len = DIP_LEN_AVI,
297 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700298
Paulo Zanonic846b612012-04-13 16:31:41 -0300299 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
300 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
301
Jesse Barnes45187ac2011-08-03 09:22:55 -0700302 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700303}
304
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300305static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700306{
307 struct dip_infoframe spd_if;
308
309 memset(&spd_if, 0, sizeof(spd_if));
310 spd_if.type = DIP_TYPE_SPD;
311 spd_if.ver = DIP_VERSION_SPD;
312 spd_if.len = DIP_LEN_SPD;
313 strcpy(spd_if.body.spd.vn, "Intel");
314 strcpy(spd_if.body.spd.pd, "Integrated gfx");
315 spd_if.body.spd.sdi = DIP_SPD_PC;
316
317 intel_set_infoframe(encoder, &spd_if);
318}
319
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300320static void g4x_set_infoframes(struct drm_encoder *encoder,
321 struct drm_display_mode *adjusted_mode)
322{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300323 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
324 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
325 u32 reg = VIDEO_DIP_CTL;
326 u32 val = I915_READ(reg);
327
328 /* If the registers were not initialized yet, they might be zeroes,
329 * which means we're selecting the AVI DIP and we're setting its
330 * frequency to once. This seems to really confuse the HW and make
331 * things stop working (the register spec says the AVI always needs to
332 * be sent every VSync). So here we avoid writing to the register more
333 * than we need and also explicitly select the AVI DIP and explicitly
334 * set its frequency to every VSync. Avoiding to write it twice seems to
335 * be enough to solve the problem, but being defensive shouldn't hurt us
336 * either. */
337 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
338
339 if (!intel_hdmi->has_hdmi_sink) {
340 if (!(val & VIDEO_DIP_ENABLE))
341 return;
342 val &= ~VIDEO_DIP_ENABLE;
343 I915_WRITE(reg, val);
344 return;
345 }
346
Paulo Zanonif278d972012-05-28 16:42:50 -0300347 val &= ~VIDEO_DIP_PORT_MASK;
348 switch (intel_hdmi->sdvox_reg) {
349 case SDVOB:
350 val |= VIDEO_DIP_PORT_B;
351 break;
352 case SDVOC:
353 val |= VIDEO_DIP_PORT_C;
354 break;
355 default:
356 return;
357 }
358
359 I915_WRITE(reg, val);
360
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300361 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
362 intel_hdmi_set_spd_infoframe(encoder);
363}
364
365static void ibx_set_infoframes(struct drm_encoder *encoder,
366 struct drm_display_mode *adjusted_mode)
367{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300368 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
369 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
370 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
371 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
372 u32 val = I915_READ(reg);
373
374 /* See the big comment in g4x_set_infoframes() */
375 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
376
377 if (!intel_hdmi->has_hdmi_sink) {
378 if (!(val & VIDEO_DIP_ENABLE))
379 return;
380 val &= ~VIDEO_DIP_ENABLE;
381 I915_WRITE(reg, val);
382 return;
383 }
384
Paulo Zanonif278d972012-05-28 16:42:50 -0300385 val &= ~VIDEO_DIP_PORT_MASK;
386 switch (intel_hdmi->sdvox_reg) {
387 case HDMIB:
388 val |= VIDEO_DIP_PORT_B;
389 break;
390 case HDMIC:
391 val |= VIDEO_DIP_PORT_C;
392 break;
393 case HDMID:
394 val |= VIDEO_DIP_PORT_D;
395 break;
396 default:
397 return;
398 }
399
400 I915_WRITE(reg, val);
401
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300402 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
403 intel_hdmi_set_spd_infoframe(encoder);
404}
405
406static void cpt_set_infoframes(struct drm_encoder *encoder,
407 struct drm_display_mode *adjusted_mode)
408{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300409 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
410 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
411 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
412 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
413 u32 val = I915_READ(reg);
414
415 /* See the big comment in g4x_set_infoframes() */
416 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
417
418 if (!intel_hdmi->has_hdmi_sink) {
419 if (!(val & VIDEO_DIP_ENABLE))
420 return;
421 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
422 I915_WRITE(reg, val);
423 return;
424 }
425
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300426 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
427 intel_hdmi_set_spd_infoframe(encoder);
428}
429
430static void vlv_set_infoframes(struct drm_encoder *encoder,
431 struct drm_display_mode *adjusted_mode)
432{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300433 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
434 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
435 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
436 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
437 u32 val = I915_READ(reg);
438
439 /* See the big comment in g4x_set_infoframes() */
440 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
441
442 if (!intel_hdmi->has_hdmi_sink) {
443 if (!(val & VIDEO_DIP_ENABLE))
444 return;
445 val &= ~VIDEO_DIP_ENABLE;
446 I915_WRITE(reg, val);
447 return;
448 }
449
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300450 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
451 intel_hdmi_set_spd_infoframe(encoder);
452}
453
454static void hsw_set_infoframes(struct drm_encoder *encoder,
455 struct drm_display_mode *adjusted_mode)
456{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300457 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
458 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
459 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
460 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
461
462 if (!intel_hdmi->has_hdmi_sink) {
463 I915_WRITE(reg, 0);
464 return;
465 }
466
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300467 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
468 intel_hdmi_set_spd_infoframe(encoder);
469}
470
Eric Anholt7d573822009-01-02 13:33:00 -0800471static void intel_hdmi_mode_set(struct drm_encoder *encoder,
472 struct drm_display_mode *mode,
473 struct drm_display_mode *adjusted_mode)
474{
475 struct drm_device *dev = encoder->dev;
476 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300477 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100478 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800479 u32 sdvox;
480
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400481 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700482 if (!HAS_PCH_SPLIT(dev))
483 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400484 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
485 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
486 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
487 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800488
Jesse Barnes020f6702011-06-24 12:19:25 -0700489 if (intel_crtc->bpp > 24)
490 sdvox |= COLOR_FORMAT_12bpc;
491 else
492 sdvox |= COLOR_FORMAT_8bpc;
493
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800494 /* Required on CPT */
495 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
496 sdvox |= HDMI_MODE_SELECT;
497
David Härdeman3c17fe42010-09-24 21:44:32 +0200498 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800499 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
500 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800501 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200502 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800503 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200504 }
Eric Anholt7d573822009-01-02 13:33:00 -0800505
Jesse Barnes75770562011-10-12 09:01:58 -0700506 if (HAS_PCH_CPT(dev))
507 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
508 else if (intel_crtc->pipe == 1)
509 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800510
Chris Wilsonea5b2132010-08-04 13:50:23 +0100511 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
512 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200513
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300514 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800515}
516
517static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
518{
519 struct drm_device *dev = encoder->dev;
520 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100521 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800522 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800523 u32 enable_bits = SDVO_ENABLE;
524
525 if (intel_hdmi->has_audio)
526 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800527
Chris Wilsonea5b2132010-08-04 13:50:23 +0100528 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000529
530 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
531 * we do this anyway which shows more stable in testing.
532 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800533 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100534 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
535 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800536 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000537
538 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800539 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000540 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800541 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000542 }
543
Chris Wilsonea5b2132010-08-04 13:50:23 +0100544 I915_WRITE(intel_hdmi->sdvox_reg, temp);
545 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000546
547 /* HW workaround, need to write this twice for issue that may result
548 * in first write getting masked.
549 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800550 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100551 I915_WRITE(intel_hdmi->sdvox_reg, temp);
552 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000553 }
Eric Anholt7d573822009-01-02 13:33:00 -0800554}
555
Eric Anholt7d573822009-01-02 13:33:00 -0800556static int intel_hdmi_mode_valid(struct drm_connector *connector,
557 struct drm_display_mode *mode)
558{
559 if (mode->clock > 165000)
560 return MODE_CLOCK_HIGH;
561 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200562 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800563
564 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
565 return MODE_NO_DBLESCAN;
566
567 return MODE_OK;
568}
569
570static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
571 struct drm_display_mode *mode,
572 struct drm_display_mode *adjusted_mode)
573{
574 return true;
575}
576
Chris Wilson8ec22b22012-05-11 18:01:34 +0100577static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
578{
579 struct drm_device *dev = intel_hdmi->base.base.dev;
580 struct drm_i915_private *dev_priv = dev->dev_private;
581 uint32_t bit;
582
583 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100584 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100585 bit = HDMIB_HOTPLUG_LIVE_STATUS;
586 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100587 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100588 bit = HDMIC_HOTPLUG_LIVE_STATUS;
589 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100590 default:
591 bit = 0;
592 break;
593 }
594
595 return I915_READ(PORT_HOTPLUG_STAT) & bit;
596}
597
Keith Packardaa93d632009-05-05 09:52:46 -0700598static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100599intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800600{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100601 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700602 struct drm_i915_private *dev_priv = connector->dev->dev_private;
603 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700604 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800605
Chris Wilson8ec22b22012-05-11 18:01:34 +0100606 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
607 return status;
608
Chris Wilsonea5b2132010-08-04 13:50:23 +0100609 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800610 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700611 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800612 intel_gmbus_get_adapter(dev_priv,
613 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800614
Keith Packardaa93d632009-05-05 09:52:46 -0700615 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700616 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700617 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800618 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
619 intel_hdmi->has_hdmi_sink =
620 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800621 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700622 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800623 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700624 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800625 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800626
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100627 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800628 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
629 intel_hdmi->has_audio =
630 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100631 }
632
Keith Packardaa93d632009-05-05 09:52:46 -0700633 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800634}
635
Eric Anholt7d573822009-01-02 13:33:00 -0800636static int intel_hdmi_get_modes(struct drm_connector *connector)
637{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100638 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700639 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800640
641 /* We should parse the EDID data and find out if it's an HDMI sink so
642 * we can send audio to it.
643 */
644
Chris Wilsonf899fc62010-07-20 15:44:45 -0700645 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800646 intel_gmbus_get_adapter(dev_priv,
647 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800648}
649
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000650static bool
651intel_hdmi_detect_audio(struct drm_connector *connector)
652{
653 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
654 struct drm_i915_private *dev_priv = connector->dev->dev_private;
655 struct edid *edid;
656 bool has_audio = false;
657
658 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800659 intel_gmbus_get_adapter(dev_priv,
660 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000661 if (edid) {
662 if (edid->input & DRM_EDID_INPUT_DIGITAL)
663 has_audio = drm_detect_monitor_audio(edid);
664
665 connector->display_info.raw_edid = NULL;
666 kfree(edid);
667 }
668
669 return has_audio;
670}
671
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100672static int
673intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300674 struct drm_property *property,
675 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100676{
677 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000678 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100679 int ret;
680
681 ret = drm_connector_property_set_value(connector, property, val);
682 if (ret)
683 return ret;
684
Chris Wilson3f43c482011-05-12 22:17:24 +0100685 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800686 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000687 bool has_audio;
688
689 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100690 return 0;
691
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000692 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100693
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800694 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000695 has_audio = intel_hdmi_detect_audio(connector);
696 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800697 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000698
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800699 if (i == HDMI_AUDIO_OFF_DVI)
700 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100701
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000702 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100703 goto done;
704 }
705
Chris Wilsone953fd72011-02-21 22:23:52 +0000706 if (property == dev_priv->broadcast_rgb_property) {
707 if (val == !!intel_hdmi->color_range)
708 return 0;
709
710 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
711 goto done;
712 }
713
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100714 return -EINVAL;
715
716done:
717 if (intel_hdmi->base.base.crtc) {
718 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
719 drm_crtc_helper_set_mode(crtc, &crtc->mode,
720 crtc->x, crtc->y,
721 crtc->fb);
722 }
723
724 return 0;
725}
726
Eric Anholt7d573822009-01-02 13:33:00 -0800727static void intel_hdmi_destroy(struct drm_connector *connector)
728{
Eric Anholt7d573822009-01-02 13:33:00 -0800729 drm_sysfs_connector_remove(connector);
730 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800731 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800732}
733
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300734static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
735 .dpms = intel_ddi_dpms,
736 .mode_fixup = intel_hdmi_mode_fixup,
737 .prepare = intel_encoder_prepare,
738 .mode_set = intel_ddi_mode_set,
739 .commit = intel_encoder_commit,
740};
741
Eric Anholt7d573822009-01-02 13:33:00 -0800742static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
743 .dpms = intel_hdmi_dpms,
744 .mode_fixup = intel_hdmi_mode_fixup,
745 .prepare = intel_encoder_prepare,
746 .mode_set = intel_hdmi_mode_set,
747 .commit = intel_encoder_commit,
748};
749
750static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700751 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800752 .detect = intel_hdmi_detect,
753 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100754 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800755 .destroy = intel_hdmi_destroy,
756};
757
758static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
759 .get_modes = intel_hdmi_get_modes,
760 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100761 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800762};
763
Eric Anholt7d573822009-01-02 13:33:00 -0800764static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100765 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800766};
767
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100768static void
769intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
770{
Chris Wilson3f43c482011-05-12 22:17:24 +0100771 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000772 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100773}
774
Eric Anholt7d573822009-01-02 13:33:00 -0800775void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
776{
777 struct drm_i915_private *dev_priv = dev->dev_private;
778 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700779 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800780 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100781 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530782 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800783
Chris Wilsonea5b2132010-08-04 13:50:23 +0100784 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
785 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800786 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800787
788 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
789 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100790 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800791 return;
792 }
793
Chris Wilsonea5b2132010-08-04 13:50:23 +0100794 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100795 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
796 DRM_MODE_ENCODER_TMDS);
797
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800798 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800799 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400800 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800801 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
802
Eric Anholt21d40d32010-03-25 11:11:14 -0700803 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800804
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000805 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100806 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800807 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700808 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800809
810 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800811 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700812 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700813 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800814 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800815 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700816 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700817 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800818 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800819 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700820 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700821 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800822 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800823 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700824 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700825 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800826 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800827 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700828 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700829 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800830 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300831 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
832 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
833 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
834 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
835 intel_hdmi->ddi_port = PORT_B;
836 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
837 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
838 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
839 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
840 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
841 intel_hdmi->ddi_port = PORT_C;
842 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
843 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
844 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
845 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
846 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
847 intel_hdmi->ddi_port = PORT_D;
848 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300849 } else {
850 /* If we got an unknown sdvox_reg, things are pretty much broken
851 * in a way that we should let the kernel know about it */
852 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800853 }
Eric Anholt7d573822009-01-02 13:33:00 -0800854
Chris Wilsonea5b2132010-08-04 13:50:23 +0100855 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800856
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530857 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200858 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300859 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530860 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700861 } else if (IS_VALLEYVIEW(dev)) {
862 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300863 intel_hdmi->set_infoframes = vlv_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700864 for_each_pipe(i)
865 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300866 } else if (IS_HASWELL(dev)) {
867 /* FIXME: Haswell has a new set of DIP frame registers, but we are
868 * just doing the minimal required for HDMI to work at this stage.
869 */
870 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300871 intel_hdmi->set_infoframes = hsw_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300872 for_each_pipe(i)
873 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300874 } else if (HAS_PCH_IBX(dev)) {
875 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300876 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300877 for_each_pipe(i)
878 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
879 } else {
880 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300881 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530882 for_each_pipe(i)
883 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
884 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700885
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300886 if (IS_HASWELL(dev))
887 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
888 else
889 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800890
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100891 intel_hdmi_add_properties(intel_hdmi, connector);
892
Chris Wilsondf0e9242010-09-09 16:20:55 +0100893 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800894 drm_sysfs_connector_add(connector);
895
896 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
897 * 0xd. Failure to do so will result in spurious interrupts being
898 * generated on the port when a cable is not attached.
899 */
900 if (IS_G4X(dev) && !IS_GM45(dev)) {
901 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
902 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
903 }
Eric Anholt7d573822009-01-02 13:33:00 -0800904}