blob: 620b0dba9e7a87c810a961a556a5fe9dca4029c6 [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 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200162 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300163
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200164 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300165
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
Paulo Zanoni822974a2012-05-28 16:42:51 -0300191 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
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 */
Paulo Zanoni822974a2012-05-28 16:42:51 -0300198 if (frame->type != DIP_TYPE_AVI)
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200199 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300200
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300201 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700202
203 for (i = 0; i < len; i += 4) {
204 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
205 data++;
206 }
207
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200208 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300209 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200210 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700211
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300212 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700213}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700214
215static void vlv_write_infoframe(struct drm_encoder *encoder,
216 struct dip_infoframe *frame)
217{
218 uint32_t *data = (uint32_t *)frame;
219 struct drm_device *dev = encoder->dev;
220 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300221 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700222 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
223 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300224 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700225
Paulo Zanoni822974a2012-05-28 16:42:51 -0300226 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
227
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700228 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200229 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700230
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200231 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300232
233 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700234
235 for (i = 0; i < len; i += 4) {
236 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
237 data++;
238 }
239
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200240 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300241 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200242 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700243
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300244 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700245}
246
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300247static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300248 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300249{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300250 uint32_t *data = (uint32_t *)frame;
251 struct drm_device *dev = encoder->dev;
252 struct drm_i915_private *dev_priv = dev->dev_private;
253 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
254 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
255 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
256 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
257 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300258
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300259 if (data_reg == 0)
260 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300261
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300262 val &= ~hsw_infoframe_enable(frame);
263 I915_WRITE(ctl_reg, val);
264
265 for (i = 0; i < len; i += 4) {
266 I915_WRITE(data_reg + i, *data);
267 data++;
268 }
269
270 val |= hsw_infoframe_enable(frame);
271 I915_WRITE(ctl_reg, val);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300272}
273
Jesse Barnes45187ac2011-08-03 09:22:55 -0700274static void intel_set_infoframe(struct drm_encoder *encoder,
275 struct dip_infoframe *frame)
276{
277 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
278
Jesse Barnes45187ac2011-08-03 09:22:55 -0700279 intel_dip_infoframe_csum(frame);
280 intel_hdmi->write_infoframe(encoder, frame);
281}
282
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300283static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300284 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700285{
286 struct dip_infoframe avi_if = {
287 .type = DIP_TYPE_AVI,
288 .ver = DIP_VERSION_AVI,
289 .len = DIP_LEN_AVI,
290 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700291
Paulo Zanonic846b612012-04-13 16:31:41 -0300292 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
293 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
294
Jesse Barnes45187ac2011-08-03 09:22:55 -0700295 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700296}
297
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300298static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700299{
300 struct dip_infoframe spd_if;
301
302 memset(&spd_if, 0, sizeof(spd_if));
303 spd_if.type = DIP_TYPE_SPD;
304 spd_if.ver = DIP_VERSION_SPD;
305 spd_if.len = DIP_LEN_SPD;
306 strcpy(spd_if.body.spd.vn, "Intel");
307 strcpy(spd_if.body.spd.pd, "Integrated gfx");
308 spd_if.body.spd.sdi = DIP_SPD_PC;
309
310 intel_set_infoframe(encoder, &spd_if);
311}
312
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300313static void g4x_set_infoframes(struct drm_encoder *encoder,
314 struct drm_display_mode *adjusted_mode)
315{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300316 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
317 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
318 u32 reg = VIDEO_DIP_CTL;
319 u32 val = I915_READ(reg);
320
321 /* If the registers were not initialized yet, they might be zeroes,
322 * which means we're selecting the AVI DIP and we're setting its
323 * frequency to once. This seems to really confuse the HW and make
324 * things stop working (the register spec says the AVI always needs to
325 * be sent every VSync). So here we avoid writing to the register more
326 * than we need and also explicitly select the AVI DIP and explicitly
327 * set its frequency to every VSync. Avoiding to write it twice seems to
328 * be enough to solve the problem, but being defensive shouldn't hurt us
329 * either. */
330 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
331
332 if (!intel_hdmi->has_hdmi_sink) {
333 if (!(val & VIDEO_DIP_ENABLE))
334 return;
335 val &= ~VIDEO_DIP_ENABLE;
336 I915_WRITE(reg, val);
337 return;
338 }
339
Paulo Zanonif278d972012-05-28 16:42:50 -0300340 val &= ~VIDEO_DIP_PORT_MASK;
341 switch (intel_hdmi->sdvox_reg) {
342 case SDVOB:
343 val |= VIDEO_DIP_PORT_B;
344 break;
345 case SDVOC:
346 val |= VIDEO_DIP_PORT_C;
347 break;
348 default:
349 return;
350 }
351
Paulo Zanoni822974a2012-05-28 16:42:51 -0300352 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300353 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300354
Paulo Zanonif278d972012-05-28 16:42:50 -0300355 I915_WRITE(reg, val);
356
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300357 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
358 intel_hdmi_set_spd_infoframe(encoder);
359}
360
361static void ibx_set_infoframes(struct drm_encoder *encoder,
362 struct drm_display_mode *adjusted_mode)
363{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300364 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
365 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
366 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
367 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
368 u32 val = I915_READ(reg);
369
370 /* See the big comment in g4x_set_infoframes() */
371 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
372
373 if (!intel_hdmi->has_hdmi_sink) {
374 if (!(val & VIDEO_DIP_ENABLE))
375 return;
376 val &= ~VIDEO_DIP_ENABLE;
377 I915_WRITE(reg, val);
378 return;
379 }
380
Paulo Zanonif278d972012-05-28 16:42:50 -0300381 val &= ~VIDEO_DIP_PORT_MASK;
382 switch (intel_hdmi->sdvox_reg) {
383 case HDMIB:
384 val |= VIDEO_DIP_PORT_B;
385 break;
386 case HDMIC:
387 val |= VIDEO_DIP_PORT_C;
388 break;
389 case HDMID:
390 val |= VIDEO_DIP_PORT_D;
391 break;
392 default:
393 return;
394 }
395
Paulo Zanoni822974a2012-05-28 16:42:51 -0300396 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300397 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
398 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300399
Paulo Zanonif278d972012-05-28 16:42:50 -0300400 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 Zanoni822974a2012-05-28 16:42:51 -0300426 /* Set both together, unset both together: see the spec. */
427 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300428 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
429 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300430
431 I915_WRITE(reg, val);
432
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300433 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
434 intel_hdmi_set_spd_infoframe(encoder);
435}
436
437static void vlv_set_infoframes(struct drm_encoder *encoder,
438 struct drm_display_mode *adjusted_mode)
439{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300440 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
441 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
442 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
443 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
444 u32 val = I915_READ(reg);
445
446 /* See the big comment in g4x_set_infoframes() */
447 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
448
449 if (!intel_hdmi->has_hdmi_sink) {
450 if (!(val & VIDEO_DIP_ENABLE))
451 return;
452 val &= ~VIDEO_DIP_ENABLE;
453 I915_WRITE(reg, val);
454 return;
455 }
456
Paulo Zanoni822974a2012-05-28 16:42:51 -0300457 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300458 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
459 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300460
461 I915_WRITE(reg, val);
462
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300463 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
464 intel_hdmi_set_spd_infoframe(encoder);
465}
466
467static void hsw_set_infoframes(struct drm_encoder *encoder,
468 struct drm_display_mode *adjusted_mode)
469{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300470 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
471 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
472 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
473 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300474 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300475
476 if (!intel_hdmi->has_hdmi_sink) {
477 I915_WRITE(reg, 0);
478 return;
479 }
480
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300481 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
482 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
483
484 I915_WRITE(reg, val);
485
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300486 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
487 intel_hdmi_set_spd_infoframe(encoder);
488}
489
Eric Anholt7d573822009-01-02 13:33:00 -0800490static void intel_hdmi_mode_set(struct drm_encoder *encoder,
491 struct drm_display_mode *mode,
492 struct drm_display_mode *adjusted_mode)
493{
494 struct drm_device *dev = encoder->dev;
495 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300496 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100497 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800498 u32 sdvox;
499
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400500 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700501 if (!HAS_PCH_SPLIT(dev))
502 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400503 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
504 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
505 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
506 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800507
Jesse Barnes020f6702011-06-24 12:19:25 -0700508 if (intel_crtc->bpp > 24)
509 sdvox |= COLOR_FORMAT_12bpc;
510 else
511 sdvox |= COLOR_FORMAT_8bpc;
512
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800513 /* Required on CPT */
514 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
515 sdvox |= HDMI_MODE_SELECT;
516
David Härdeman3c17fe42010-09-24 21:44:32 +0200517 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800518 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
519 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800520 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200521 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800522 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200523 }
Eric Anholt7d573822009-01-02 13:33:00 -0800524
Jesse Barnes75770562011-10-12 09:01:58 -0700525 if (HAS_PCH_CPT(dev))
526 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
527 else if (intel_crtc->pipe == 1)
528 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800529
Chris Wilsonea5b2132010-08-04 13:50:23 +0100530 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
531 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200532
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300533 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800534}
535
536static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
537{
538 struct drm_device *dev = encoder->dev;
539 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100540 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800541 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800542 u32 enable_bits = SDVO_ENABLE;
543
544 if (intel_hdmi->has_audio)
545 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800546
Chris Wilsonea5b2132010-08-04 13:50:23 +0100547 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000548
549 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
550 * we do this anyway which shows more stable in testing.
551 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800552 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100553 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
554 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800555 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000556
557 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800558 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000559 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800560 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000561 }
562
Chris Wilsonea5b2132010-08-04 13:50:23 +0100563 I915_WRITE(intel_hdmi->sdvox_reg, temp);
564 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000565
566 /* HW workaround, need to write this twice for issue that may result
567 * in first write getting masked.
568 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800569 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100570 I915_WRITE(intel_hdmi->sdvox_reg, temp);
571 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000572 }
Eric Anholt7d573822009-01-02 13:33:00 -0800573}
574
Eric Anholt7d573822009-01-02 13:33:00 -0800575static int intel_hdmi_mode_valid(struct drm_connector *connector,
576 struct drm_display_mode *mode)
577{
578 if (mode->clock > 165000)
579 return MODE_CLOCK_HIGH;
580 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200581 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800582
583 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
584 return MODE_NO_DBLESCAN;
585
586 return MODE_OK;
587}
588
589static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
590 struct drm_display_mode *mode,
591 struct drm_display_mode *adjusted_mode)
592{
593 return true;
594}
595
Chris Wilson8ec22b22012-05-11 18:01:34 +0100596static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
597{
598 struct drm_device *dev = intel_hdmi->base.base.dev;
599 struct drm_i915_private *dev_priv = dev->dev_private;
600 uint32_t bit;
601
602 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100603 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100604 bit = HDMIB_HOTPLUG_LIVE_STATUS;
605 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100606 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100607 bit = HDMIC_HOTPLUG_LIVE_STATUS;
608 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100609 default:
610 bit = 0;
611 break;
612 }
613
614 return I915_READ(PORT_HOTPLUG_STAT) & bit;
615}
616
Keith Packardaa93d632009-05-05 09:52:46 -0700617static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100618intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800619{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100620 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700621 struct drm_i915_private *dev_priv = connector->dev->dev_private;
622 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700623 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800624
Chris Wilson8ec22b22012-05-11 18:01:34 +0100625 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
626 return status;
627
Chris Wilsonea5b2132010-08-04 13:50:23 +0100628 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800629 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700630 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800631 intel_gmbus_get_adapter(dev_priv,
632 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800633
Keith Packardaa93d632009-05-05 09:52:46 -0700634 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700635 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700636 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800637 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
638 intel_hdmi->has_hdmi_sink =
639 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800640 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700641 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800642 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700643 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800644 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800645
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100646 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800647 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
648 intel_hdmi->has_audio =
649 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100650 }
651
Keith Packardaa93d632009-05-05 09:52:46 -0700652 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800653}
654
Eric Anholt7d573822009-01-02 13:33:00 -0800655static int intel_hdmi_get_modes(struct drm_connector *connector)
656{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100657 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700658 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800659
660 /* We should parse the EDID data and find out if it's an HDMI sink so
661 * we can send audio to it.
662 */
663
Chris Wilsonf899fc62010-07-20 15:44:45 -0700664 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800665 intel_gmbus_get_adapter(dev_priv,
666 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800667}
668
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000669static bool
670intel_hdmi_detect_audio(struct drm_connector *connector)
671{
672 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
673 struct drm_i915_private *dev_priv = connector->dev->dev_private;
674 struct edid *edid;
675 bool has_audio = false;
676
677 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800678 intel_gmbus_get_adapter(dev_priv,
679 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000680 if (edid) {
681 if (edid->input & DRM_EDID_INPUT_DIGITAL)
682 has_audio = drm_detect_monitor_audio(edid);
683
684 connector->display_info.raw_edid = NULL;
685 kfree(edid);
686 }
687
688 return has_audio;
689}
690
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100691static int
692intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300693 struct drm_property *property,
694 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100695{
696 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000697 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100698 int ret;
699
700 ret = drm_connector_property_set_value(connector, property, val);
701 if (ret)
702 return ret;
703
Chris Wilson3f43c482011-05-12 22:17:24 +0100704 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800705 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000706 bool has_audio;
707
708 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100709 return 0;
710
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000711 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100712
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800713 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000714 has_audio = intel_hdmi_detect_audio(connector);
715 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800716 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000717
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800718 if (i == HDMI_AUDIO_OFF_DVI)
719 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100720
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000721 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100722 goto done;
723 }
724
Chris Wilsone953fd72011-02-21 22:23:52 +0000725 if (property == dev_priv->broadcast_rgb_property) {
726 if (val == !!intel_hdmi->color_range)
727 return 0;
728
729 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
730 goto done;
731 }
732
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100733 return -EINVAL;
734
735done:
736 if (intel_hdmi->base.base.crtc) {
737 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
738 drm_crtc_helper_set_mode(crtc, &crtc->mode,
739 crtc->x, crtc->y,
740 crtc->fb);
741 }
742
743 return 0;
744}
745
Eric Anholt7d573822009-01-02 13:33:00 -0800746static void intel_hdmi_destroy(struct drm_connector *connector)
747{
Eric Anholt7d573822009-01-02 13:33:00 -0800748 drm_sysfs_connector_remove(connector);
749 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800750 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800751}
752
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300753static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
754 .dpms = intel_ddi_dpms,
755 .mode_fixup = intel_hdmi_mode_fixup,
756 .prepare = intel_encoder_prepare,
757 .mode_set = intel_ddi_mode_set,
758 .commit = intel_encoder_commit,
759};
760
Eric Anholt7d573822009-01-02 13:33:00 -0800761static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
762 .dpms = intel_hdmi_dpms,
763 .mode_fixup = intel_hdmi_mode_fixup,
764 .prepare = intel_encoder_prepare,
765 .mode_set = intel_hdmi_mode_set,
766 .commit = intel_encoder_commit,
767};
768
769static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700770 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800771 .detect = intel_hdmi_detect,
772 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100773 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800774 .destroy = intel_hdmi_destroy,
775};
776
777static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
778 .get_modes = intel_hdmi_get_modes,
779 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100780 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800781};
782
Eric Anholt7d573822009-01-02 13:33:00 -0800783static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100784 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800785};
786
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100787static void
788intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
789{
Chris Wilson3f43c482011-05-12 22:17:24 +0100790 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000791 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100792}
793
Eric Anholt7d573822009-01-02 13:33:00 -0800794void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
795{
796 struct drm_i915_private *dev_priv = dev->dev_private;
797 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700798 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800799 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100800 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530801 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800802
Chris Wilsonea5b2132010-08-04 13:50:23 +0100803 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
804 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800805 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800806
807 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
808 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100809 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800810 return;
811 }
812
Chris Wilsonea5b2132010-08-04 13:50:23 +0100813 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100814 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
815 DRM_MODE_ENCODER_TMDS);
816
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800817 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800818 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400819 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800820 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
821
Eric Anholt21d40d32010-03-25 11:11:14 -0700822 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800823
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000824 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100825 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800826 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700827 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800828
829 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800830 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700831 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700832 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800833 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800834 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700835 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700836 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800837 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800838 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700839 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700840 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800841 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800842 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700843 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700844 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800845 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800846 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700847 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700848 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800849 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300850 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
851 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
852 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
853 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
854 intel_hdmi->ddi_port = PORT_B;
855 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
856 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
857 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
858 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
859 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
860 intel_hdmi->ddi_port = PORT_C;
861 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
862 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
863 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
864 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
865 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
866 intel_hdmi->ddi_port = PORT_D;
867 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300868 } else {
869 /* If we got an unknown sdvox_reg, things are pretty much broken
870 * in a way that we should let the kernel know about it */
871 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800872 }
Eric Anholt7d573822009-01-02 13:33:00 -0800873
Chris Wilsonea5b2132010-08-04 13:50:23 +0100874 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800875
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530876 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200877 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300878 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530879 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700880 } else if (IS_VALLEYVIEW(dev)) {
881 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300882 intel_hdmi->set_infoframes = vlv_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700883 for_each_pipe(i)
884 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300885 } else if (IS_HASWELL(dev)) {
886 /* FIXME: Haswell has a new set of DIP frame registers, but we are
887 * just doing the minimal required for HDMI to work at this stage.
888 */
889 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300890 intel_hdmi->set_infoframes = hsw_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300891 for_each_pipe(i)
892 I915_WRITE(HSW_TVIDEO_DIP_CTL(i), 0);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300893 } else if (HAS_PCH_IBX(dev)) {
894 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300895 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300896 for_each_pipe(i)
897 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
898 } else {
899 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300900 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530901 for_each_pipe(i)
902 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
903 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700904
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300905 if (IS_HASWELL(dev))
906 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
907 else
908 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800909
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100910 intel_hdmi_add_properties(intel_hdmi, connector);
911
Chris Wilsondf0e9242010-09-09 16:20:55 +0100912 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800913 drm_sysfs_connector_add(connector);
914
915 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
916 * 0xd. Failure to do so will result in spurious interrupts being
917 * generated on the port when a cable is not attached.
918 */
919 if (IS_G4X(dev) && !IS_GM45(dev)) {
920 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
921 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
922 }
Eric Anholt7d573822009-01-02 13:33:00 -0800923}