blob: 2f2adc4e511c355e7f1fcfbda20f8bd1630dc873 [file] [log] [blame]
Eric Anholt7d573822009-01-02 13:33:00 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
27 */
28
29#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Eric Anholt7d573822009-01-02 13:33:00 -080031#include <linux/delay.h>
32#include "drmP.h"
33#include "drm.h"
34#include "drm_crtc.h"
Keith Packardaa93d632009-05-05 09:52:46 -070035#include "drm_edid.h"
Eric Anholt7d573822009-01-02 13:33:00 -080036#include "intel_drv.h"
37#include "i915_drm.h"
38#include "i915_drv.h"
39
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030040struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010041{
Chris Wilson4ef69c72010-09-09 15:14:28 +010042 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010043}
44
Chris Wilsondf0e9242010-09-09 16:20:55 +010045static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
46{
47 return container_of(intel_attached_encoder(connector),
48 struct intel_hdmi, base);
49}
50
Jesse Barnes45187ac2011-08-03 09:22:55 -070051void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020052{
Jesse Barnes45187ac2011-08-03 09:22:55 -070053 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020054 uint8_t sum = 0;
55 unsigned i;
56
Jesse Barnes45187ac2011-08-03 09:22:55 -070057 frame->checksum = 0;
58 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020059
Jesse Barnes64a8fc02011-09-22 11:16:00 +053060 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020061 sum += data[i];
62
Jesse Barnes45187ac2011-08-03 09:22:55 -070063 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020064}
65
Daniel Vetterbc2481f2012-05-08 15:18:32 +020066static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020067{
Jesse Barnes45187ac2011-08-03 09:22:55 -070068 switch (frame->type) {
69 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030070 return VIDEO_DIP_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070071 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030072 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070073 default:
74 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030075 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070077}
78
Daniel Vetterbc2481f2012-05-08 15:18:32 +020079static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070080{
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 switch (frame->type) {
82 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030083 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070084 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030085 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030086 default:
87 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030088 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030089 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030090}
91
Paulo Zanoni2da8af52012-05-14 17:12:51 -030092static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
93{
94 switch (frame->type) {
95 case DIP_TYPE_AVI:
96 return VIDEO_DIP_ENABLE_AVI_HSW;
97 case DIP_TYPE_SPD:
98 return VIDEO_DIP_ENABLE_SPD_HSW;
99 default:
100 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
101 return 0;
102 }
103}
104
105static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe)
106{
107 switch (frame->type) {
108 case DIP_TYPE_AVI:
109 return HSW_TVIDEO_DIP_AVI_DATA(pipe);
110 case DIP_TYPE_SPD:
111 return HSW_TVIDEO_DIP_SPD_DATA(pipe);
112 default:
113 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
114 return 0;
115 }
116}
117
Daniel Vettera3da1df2012-05-08 15:19:06 +0200118static void g4x_write_infoframe(struct drm_encoder *encoder,
119 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700120{
121 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200122 struct drm_device *dev = encoder->dev;
123 struct drm_i915_private *dev_priv = dev->dev_private;
124 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300125 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700126 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200127
Paulo Zanoni3e6e6392012-05-04 17:18:19 -0300128 val &= ~VIDEO_DIP_PORT_MASK;
David Härdeman3c17fe42010-09-24 21:44:32 +0200129 if (intel_hdmi->sdvox_reg == SDVOB)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300130 val |= VIDEO_DIP_PORT_B;
David Härdeman3c17fe42010-09-24 21:44:32 +0200131 else if (intel_hdmi->sdvox_reg == SDVOC)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300132 val |= VIDEO_DIP_PORT_C;
David Härdeman3c17fe42010-09-24 21:44:32 +0200133 else
134 return;
135
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300136 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200137 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200139 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300140 val |= VIDEO_DIP_ENABLE;
141
142 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143
144 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200145 I915_WRITE(VIDEO_DIP_DATA, *data);
146 data++;
147 }
148
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200149 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300150 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200151 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300153 I915_WRITE(VIDEO_DIP_CTL, val);
David Härdeman3c17fe42010-09-24 21:44:32 +0200154}
155
Paulo Zanonifdf12502012-05-04 17:18:24 -0300156static void ibx_write_infoframe(struct drm_encoder *encoder,
157 struct dip_infoframe *frame)
158{
159 uint32_t *data = (uint32_t *)frame;
160 struct drm_device *dev = encoder->dev;
161 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300162 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni4e89ee12012-05-04 17:18:26 -0300163 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300164 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
165 unsigned i, len = DIP_HEADER_SIZE + frame->len;
166 u32 val = I915_READ(reg);
167
Paulo Zanoni4e89ee12012-05-04 17:18:26 -0300168 val &= ~VIDEO_DIP_PORT_MASK;
169 switch (intel_hdmi->sdvox_reg) {
170 case HDMIB:
171 val |= VIDEO_DIP_PORT_B;
172 break;
173 case HDMIC:
174 val |= VIDEO_DIP_PORT_C;
175 break;
176 case HDMID:
177 val |= VIDEO_DIP_PORT_D;
178 break;
179 default:
180 return;
181 }
182
Paulo Zanonifdf12502012-05-04 17:18:24 -0300183 intel_wait_for_vblank(dev, intel_crtc->pipe);
184
185 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200186 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300187
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200188 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300189 val |= VIDEO_DIP_ENABLE;
190
191 I915_WRITE(reg, val);
192
193 for (i = 0; i < len; i += 4) {
194 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
195 data++;
196 }
197
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200198 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300199 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200200 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201
202 I915_WRITE(reg, val);
203}
204
205static void cpt_write_infoframe(struct drm_encoder *encoder,
206 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700207{
208 uint32_t *data = (uint32_t *)frame;
209 struct drm_device *dev = encoder->dev;
210 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300211 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700212 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
213 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300214 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700215
216 intel_wait_for_vblank(dev, intel_crtc->pipe);
217
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530218 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200219 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700220
Paulo Zanoniecb97852012-05-04 17:18:21 -0300221 /* The DIP control register spec says that we need to update the AVI
222 * infoframe without clearing its enable bit */
223 if (frame->type == DIP_TYPE_AVI)
224 val |= VIDEO_DIP_ENABLE_AVI;
225 else
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200226 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300227
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300228 val |= VIDEO_DIP_ENABLE;
229
230 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700231
232 for (i = 0; i < len; i += 4) {
233 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
234 data++;
235 }
236
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200237 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300238 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200239 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700240
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300241 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700242}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700243
244static void vlv_write_infoframe(struct drm_encoder *encoder,
245 struct dip_infoframe *frame)
246{
247 uint32_t *data = (uint32_t *)frame;
248 struct drm_device *dev = encoder->dev;
249 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300250 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700251 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
252 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300253 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700254
255 intel_wait_for_vblank(dev, intel_crtc->pipe);
256
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700257 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200258 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700259
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200260 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300261 val |= VIDEO_DIP_ENABLE;
262
263 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700264
265 for (i = 0; i < len; i += 4) {
266 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
267 data++;
268 }
269
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200270 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300271 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200272 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700273
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300274 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700275}
276
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300277static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300278 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300279{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300280 uint32_t *data = (uint32_t *)frame;
281 struct drm_device *dev = encoder->dev;
282 struct drm_i915_private *dev_priv = dev->dev_private;
283 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
284 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
285 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
286 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
287 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300288
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300289 if (data_reg == 0)
290 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300291
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300292 intel_wait_for_vblank(dev, intel_crtc->pipe);
293
294 val &= ~hsw_infoframe_enable(frame);
295 I915_WRITE(ctl_reg, val);
296
297 for (i = 0; i < len; i += 4) {
298 I915_WRITE(data_reg + i, *data);
299 data++;
300 }
301
302 val |= hsw_infoframe_enable(frame);
303 I915_WRITE(ctl_reg, val);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300304}
305
Jesse Barnes45187ac2011-08-03 09:22:55 -0700306static void intel_set_infoframe(struct drm_encoder *encoder,
307 struct dip_infoframe *frame)
308{
309 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
310
Jesse Barnes45187ac2011-08-03 09:22:55 -0700311 intel_dip_infoframe_csum(frame);
312 intel_hdmi->write_infoframe(encoder, frame);
313}
314
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300315static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300316 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700317{
318 struct dip_infoframe avi_if = {
319 .type = DIP_TYPE_AVI,
320 .ver = DIP_VERSION_AVI,
321 .len = DIP_LEN_AVI,
322 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700323
Paulo Zanonic846b612012-04-13 16:31:41 -0300324 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
325 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
326
Jesse Barnes45187ac2011-08-03 09:22:55 -0700327 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700328}
329
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300330static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700331{
332 struct dip_infoframe spd_if;
333
334 memset(&spd_if, 0, sizeof(spd_if));
335 spd_if.type = DIP_TYPE_SPD;
336 spd_if.ver = DIP_VERSION_SPD;
337 spd_if.len = DIP_LEN_SPD;
338 strcpy(spd_if.body.spd.vn, "Intel");
339 strcpy(spd_if.body.spd.pd, "Integrated gfx");
340 spd_if.body.spd.sdi = DIP_SPD_PC;
341
342 intel_set_infoframe(encoder, &spd_if);
343}
344
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300345static void g4x_set_infoframes(struct drm_encoder *encoder,
346 struct drm_display_mode *adjusted_mode)
347{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300348 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
349 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
350 u32 reg = VIDEO_DIP_CTL;
351 u32 val = I915_READ(reg);
352
353 /* If the registers were not initialized yet, they might be zeroes,
354 * which means we're selecting the AVI DIP and we're setting its
355 * frequency to once. This seems to really confuse the HW and make
356 * things stop working (the register spec says the AVI always needs to
357 * be sent every VSync). So here we avoid writing to the register more
358 * than we need and also explicitly select the AVI DIP and explicitly
359 * set its frequency to every VSync. Avoiding to write it twice seems to
360 * be enough to solve the problem, but being defensive shouldn't hurt us
361 * either. */
362 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
363
364 if (!intel_hdmi->has_hdmi_sink) {
365 if (!(val & VIDEO_DIP_ENABLE))
366 return;
367 val &= ~VIDEO_DIP_ENABLE;
368 I915_WRITE(reg, val);
369 return;
370 }
371
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300372 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
373 intel_hdmi_set_spd_infoframe(encoder);
374}
375
376static void ibx_set_infoframes(struct drm_encoder *encoder,
377 struct drm_display_mode *adjusted_mode)
378{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300379 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
380 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
381 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
382 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
383 u32 val = I915_READ(reg);
384
385 /* See the big comment in g4x_set_infoframes() */
386 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
387
388 if (!intel_hdmi->has_hdmi_sink) {
389 if (!(val & VIDEO_DIP_ENABLE))
390 return;
391 val &= ~VIDEO_DIP_ENABLE;
392 I915_WRITE(reg, val);
393 return;
394 }
395
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300396 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
397 intel_hdmi_set_spd_infoframe(encoder);
398}
399
400static void cpt_set_infoframes(struct drm_encoder *encoder,
401 struct drm_display_mode *adjusted_mode)
402{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300403 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
404 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
405 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
406 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
407 u32 val = I915_READ(reg);
408
409 /* See the big comment in g4x_set_infoframes() */
410 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
411
412 if (!intel_hdmi->has_hdmi_sink) {
413 if (!(val & VIDEO_DIP_ENABLE))
414 return;
415 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
416 I915_WRITE(reg, val);
417 return;
418 }
419
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300420 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
421 intel_hdmi_set_spd_infoframe(encoder);
422}
423
424static void vlv_set_infoframes(struct drm_encoder *encoder,
425 struct drm_display_mode *adjusted_mode)
426{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300427 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
428 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
429 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
430 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
431 u32 val = I915_READ(reg);
432
433 /* See the big comment in g4x_set_infoframes() */
434 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
435
436 if (!intel_hdmi->has_hdmi_sink) {
437 if (!(val & VIDEO_DIP_ENABLE))
438 return;
439 val &= ~VIDEO_DIP_ENABLE;
440 I915_WRITE(reg, val);
441 return;
442 }
443
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300444 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
445 intel_hdmi_set_spd_infoframe(encoder);
446}
447
448static void hsw_set_infoframes(struct drm_encoder *encoder,
449 struct drm_display_mode *adjusted_mode)
450{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300451 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
452 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
453 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
454 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
455
456 if (!intel_hdmi->has_hdmi_sink) {
457 I915_WRITE(reg, 0);
458 return;
459 }
460
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300461 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
462 intel_hdmi_set_spd_infoframe(encoder);
463}
464
Eric Anholt7d573822009-01-02 13:33:00 -0800465static void intel_hdmi_mode_set(struct drm_encoder *encoder,
466 struct drm_display_mode *mode,
467 struct drm_display_mode *adjusted_mode)
468{
469 struct drm_device *dev = encoder->dev;
470 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300471 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100472 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800473 u32 sdvox;
474
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400475 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700476 if (!HAS_PCH_SPLIT(dev))
477 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400478 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
479 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
480 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
481 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800482
Jesse Barnes020f6702011-06-24 12:19:25 -0700483 if (intel_crtc->bpp > 24)
484 sdvox |= COLOR_FORMAT_12bpc;
485 else
486 sdvox |= COLOR_FORMAT_8bpc;
487
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800488 /* Required on CPT */
489 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
490 sdvox |= HDMI_MODE_SELECT;
491
David Härdeman3c17fe42010-09-24 21:44:32 +0200492 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800493 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
494 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800495 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200496 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800497 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200498 }
Eric Anholt7d573822009-01-02 13:33:00 -0800499
Jesse Barnes75770562011-10-12 09:01:58 -0700500 if (HAS_PCH_CPT(dev))
501 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
502 else if (intel_crtc->pipe == 1)
503 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800504
Chris Wilsonea5b2132010-08-04 13:50:23 +0100505 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
506 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200507
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300508 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800509}
510
511static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
512{
513 struct drm_device *dev = encoder->dev;
514 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100515 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800516 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800517 u32 enable_bits = SDVO_ENABLE;
518
519 if (intel_hdmi->has_audio)
520 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800521
Chris Wilsonea5b2132010-08-04 13:50:23 +0100522 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000523
524 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
525 * we do this anyway which shows more stable in testing.
526 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800527 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100528 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
529 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800530 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000531
532 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800533 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000534 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800535 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000536 }
537
Chris Wilsonea5b2132010-08-04 13:50:23 +0100538 I915_WRITE(intel_hdmi->sdvox_reg, temp);
539 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000540
541 /* HW workaround, need to write this twice for issue that may result
542 * in first write getting masked.
543 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800544 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100545 I915_WRITE(intel_hdmi->sdvox_reg, temp);
546 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000547 }
Eric Anholt7d573822009-01-02 13:33:00 -0800548}
549
Eric Anholt7d573822009-01-02 13:33:00 -0800550static int intel_hdmi_mode_valid(struct drm_connector *connector,
551 struct drm_display_mode *mode)
552{
553 if (mode->clock > 165000)
554 return MODE_CLOCK_HIGH;
555 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200556 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800557
558 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
559 return MODE_NO_DBLESCAN;
560
561 return MODE_OK;
562}
563
564static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
565 struct drm_display_mode *mode,
566 struct drm_display_mode *adjusted_mode)
567{
568 return true;
569}
570
Chris Wilson8ec22b22012-05-11 18:01:34 +0100571static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
572{
573 struct drm_device *dev = intel_hdmi->base.base.dev;
574 struct drm_i915_private *dev_priv = dev->dev_private;
575 uint32_t bit;
576
577 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100578 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100579 bit = HDMIB_HOTPLUG_LIVE_STATUS;
580 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100581 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100582 bit = HDMIC_HOTPLUG_LIVE_STATUS;
583 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100584 default:
585 bit = 0;
586 break;
587 }
588
589 return I915_READ(PORT_HOTPLUG_STAT) & bit;
590}
591
Keith Packardaa93d632009-05-05 09:52:46 -0700592static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100593intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800594{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100595 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700596 struct drm_i915_private *dev_priv = connector->dev->dev_private;
597 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700598 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800599
Chris Wilson8ec22b22012-05-11 18:01:34 +0100600 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
601 return status;
602
Chris Wilsonea5b2132010-08-04 13:50:23 +0100603 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800604 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700605 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800606 intel_gmbus_get_adapter(dev_priv,
607 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800608
Keith Packardaa93d632009-05-05 09:52:46 -0700609 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700610 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700611 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800612 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
613 intel_hdmi->has_hdmi_sink =
614 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800615 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700616 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800617 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700618 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800619 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800620
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100621 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800622 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
623 intel_hdmi->has_audio =
624 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100625 }
626
Keith Packardaa93d632009-05-05 09:52:46 -0700627 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800628}
629
Eric Anholt7d573822009-01-02 13:33:00 -0800630static int intel_hdmi_get_modes(struct drm_connector *connector)
631{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100632 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700633 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800634
635 /* We should parse the EDID data and find out if it's an HDMI sink so
636 * we can send audio to it.
637 */
638
Chris Wilsonf899fc62010-07-20 15:44:45 -0700639 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800640 intel_gmbus_get_adapter(dev_priv,
641 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800642}
643
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000644static bool
645intel_hdmi_detect_audio(struct drm_connector *connector)
646{
647 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
648 struct drm_i915_private *dev_priv = connector->dev->dev_private;
649 struct edid *edid;
650 bool has_audio = false;
651
652 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800653 intel_gmbus_get_adapter(dev_priv,
654 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000655 if (edid) {
656 if (edid->input & DRM_EDID_INPUT_DIGITAL)
657 has_audio = drm_detect_monitor_audio(edid);
658
659 connector->display_info.raw_edid = NULL;
660 kfree(edid);
661 }
662
663 return has_audio;
664}
665
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100666static int
667intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300668 struct drm_property *property,
669 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100670{
671 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000672 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100673 int ret;
674
675 ret = drm_connector_property_set_value(connector, property, val);
676 if (ret)
677 return ret;
678
Chris Wilson3f43c482011-05-12 22:17:24 +0100679 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800680 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000681 bool has_audio;
682
683 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100684 return 0;
685
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000686 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100687
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800688 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000689 has_audio = intel_hdmi_detect_audio(connector);
690 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800691 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000692
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800693 if (i == HDMI_AUDIO_OFF_DVI)
694 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100695
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000696 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100697 goto done;
698 }
699
Chris Wilsone953fd72011-02-21 22:23:52 +0000700 if (property == dev_priv->broadcast_rgb_property) {
701 if (val == !!intel_hdmi->color_range)
702 return 0;
703
704 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
705 goto done;
706 }
707
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100708 return -EINVAL;
709
710done:
711 if (intel_hdmi->base.base.crtc) {
712 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
713 drm_crtc_helper_set_mode(crtc, &crtc->mode,
714 crtc->x, crtc->y,
715 crtc->fb);
716 }
717
718 return 0;
719}
720
Eric Anholt7d573822009-01-02 13:33:00 -0800721static void intel_hdmi_destroy(struct drm_connector *connector)
722{
Eric Anholt7d573822009-01-02 13:33:00 -0800723 drm_sysfs_connector_remove(connector);
724 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800725 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800726}
727
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300728static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
729 .dpms = intel_ddi_dpms,
730 .mode_fixup = intel_hdmi_mode_fixup,
731 .prepare = intel_encoder_prepare,
732 .mode_set = intel_ddi_mode_set,
733 .commit = intel_encoder_commit,
734};
735
Eric Anholt7d573822009-01-02 13:33:00 -0800736static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
737 .dpms = intel_hdmi_dpms,
738 .mode_fixup = intel_hdmi_mode_fixup,
739 .prepare = intel_encoder_prepare,
740 .mode_set = intel_hdmi_mode_set,
741 .commit = intel_encoder_commit,
742};
743
744static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700745 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800746 .detect = intel_hdmi_detect,
747 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100748 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800749 .destroy = intel_hdmi_destroy,
750};
751
752static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
753 .get_modes = intel_hdmi_get_modes,
754 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100755 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800756};
757
Eric Anholt7d573822009-01-02 13:33:00 -0800758static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100759 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800760};
761
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100762static void
763intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
764{
Chris Wilson3f43c482011-05-12 22:17:24 +0100765 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000766 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100767}
768
Eric Anholt7d573822009-01-02 13:33:00 -0800769void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
770{
771 struct drm_i915_private *dev_priv = dev->dev_private;
772 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700773 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800774 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100775 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530776 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800777
Chris Wilsonea5b2132010-08-04 13:50:23 +0100778 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
779 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800780 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800781
782 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
783 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100784 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800785 return;
786 }
787
Chris Wilsonea5b2132010-08-04 13:50:23 +0100788 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100789 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
790 DRM_MODE_ENCODER_TMDS);
791
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800792 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800793 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400794 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800795 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
796
Eric Anholt21d40d32010-03-25 11:11:14 -0700797 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800798
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000799 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100800 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800801 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700802 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800803
804 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800805 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700806 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700807 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800808 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800809 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700810 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700811 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800812 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800813 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700814 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700815 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800816 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800817 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700818 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700819 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800820 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800821 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700822 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700823 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800824 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300825 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
826 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
827 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
828 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
829 intel_hdmi->ddi_port = PORT_B;
830 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
831 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
832 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
833 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
834 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
835 intel_hdmi->ddi_port = PORT_C;
836 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
837 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
838 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
839 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
840 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
841 intel_hdmi->ddi_port = PORT_D;
842 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300843 } else {
844 /* If we got an unknown sdvox_reg, things are pretty much broken
845 * in a way that we should let the kernel know about it */
846 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800847 }
Eric Anholt7d573822009-01-02 13:33:00 -0800848
Chris Wilsonea5b2132010-08-04 13:50:23 +0100849 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800850
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530851 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200852 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300853 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530854 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700855 } else if (IS_VALLEYVIEW(dev)) {
856 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300857 intel_hdmi->set_infoframes = vlv_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700858 for_each_pipe(i)
859 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300860 } else if (IS_HASWELL(dev)) {
861 /* FIXME: Haswell has a new set of DIP frame registers, but we are
862 * just doing the minimal required for HDMI to work at this stage.
863 */
864 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300865 intel_hdmi->set_infoframes = hsw_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300866 for_each_pipe(i)
867 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300868 } else if (HAS_PCH_IBX(dev)) {
869 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300870 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300871 for_each_pipe(i)
872 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
873 } else {
874 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300875 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530876 for_each_pipe(i)
877 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
878 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700879
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300880 if (IS_HASWELL(dev))
881 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
882 else
883 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800884
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100885 intel_hdmi_add_properties(intel_hdmi, connector);
886
Chris Wilsondf0e9242010-09-09 16:20:55 +0100887 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800888 drm_sysfs_connector_add(connector);
889
890 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
891 * 0xd. Failure to do so will result in spurious interrupts being
892 * generated on the port when a cable is not attached.
893 */
894 if (IS_G4X(dev) && !IS_GM45(dev)) {
895 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
896 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
897 }
Eric Anholt7d573822009-01-02 13:33:00 -0800898}