blob: 194b453b052ceef969c59a2f2b168473dd80ce67 [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);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300320 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300321
322 /* If the registers were not initialized yet, they might be zeroes,
323 * which means we're selecting the AVI DIP and we're setting its
324 * frequency to once. This seems to really confuse the HW and make
325 * things stop working (the register spec says the AVI always needs to
326 * be sent every VSync). So here we avoid writing to the register more
327 * than we need and also explicitly select the AVI DIP and explicitly
328 * set its frequency to every VSync. Avoiding to write it twice seems to
329 * be enough to solve the problem, but being defensive shouldn't hurt us
330 * either. */
331 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
332
333 if (!intel_hdmi->has_hdmi_sink) {
334 if (!(val & VIDEO_DIP_ENABLE))
335 return;
336 val &= ~VIDEO_DIP_ENABLE;
337 I915_WRITE(reg, val);
338 return;
339 }
340
Paulo Zanonif278d972012-05-28 16:42:50 -0300341 switch (intel_hdmi->sdvox_reg) {
342 case SDVOB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300343 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300344 break;
345 case SDVOC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300346 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300347 break;
348 default:
349 return;
350 }
351
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300352 if (port != (val & VIDEO_DIP_PORT_MASK)) {
353 if (val & VIDEO_DIP_ENABLE) {
354 val &= ~VIDEO_DIP_ENABLE;
355 I915_WRITE(reg, val);
356 }
357 val &= ~VIDEO_DIP_PORT_MASK;
358 val |= port;
359 }
360
Paulo Zanoni822974a2012-05-28 16:42:51 -0300361 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300362 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300363
Paulo Zanonif278d972012-05-28 16:42:50 -0300364 I915_WRITE(reg, val);
365
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300366 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
367 intel_hdmi_set_spd_infoframe(encoder);
368}
369
370static void ibx_set_infoframes(struct drm_encoder *encoder,
371 struct drm_display_mode *adjusted_mode)
372{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300373 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
374 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
375 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
376 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
377 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300378 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300379
380 /* See the big comment in g4x_set_infoframes() */
381 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
382
383 if (!intel_hdmi->has_hdmi_sink) {
384 if (!(val & VIDEO_DIP_ENABLE))
385 return;
386 val &= ~VIDEO_DIP_ENABLE;
387 I915_WRITE(reg, val);
388 return;
389 }
390
Paulo Zanonif278d972012-05-28 16:42:50 -0300391 switch (intel_hdmi->sdvox_reg) {
392 case HDMIB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300393 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300394 break;
395 case HDMIC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300396 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300397 break;
398 case HDMID:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300399 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300400 break;
401 default:
402 return;
403 }
404
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300405 if (port != (val & VIDEO_DIP_PORT_MASK)) {
406 if (val & VIDEO_DIP_ENABLE) {
407 val &= ~VIDEO_DIP_ENABLE;
408 I915_WRITE(reg, val);
409 }
410 val &= ~VIDEO_DIP_PORT_MASK;
411 val |= port;
412 }
413
Paulo Zanoni822974a2012-05-28 16:42:51 -0300414 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300415 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
416 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300417
Paulo Zanonif278d972012-05-28 16:42:50 -0300418 I915_WRITE(reg, val);
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 cpt_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 = 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 | VIDEO_DIP_ENABLE_AVI);
440 I915_WRITE(reg, val);
441 return;
442 }
443
Paulo Zanoni822974a2012-05-28 16:42:51 -0300444 /* Set both together, unset both together: see the spec. */
445 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300446 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
447 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300448
449 I915_WRITE(reg, val);
450
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300451 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
452 intel_hdmi_set_spd_infoframe(encoder);
453}
454
455static void vlv_set_infoframes(struct drm_encoder *encoder,
456 struct drm_display_mode *adjusted_mode)
457{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300458 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
459 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
460 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
461 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
462 u32 val = I915_READ(reg);
463
464 /* See the big comment in g4x_set_infoframes() */
465 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
466
467 if (!intel_hdmi->has_hdmi_sink) {
468 if (!(val & VIDEO_DIP_ENABLE))
469 return;
470 val &= ~VIDEO_DIP_ENABLE;
471 I915_WRITE(reg, val);
472 return;
473 }
474
Paulo Zanoni822974a2012-05-28 16:42:51 -0300475 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300476 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
477 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300478
479 I915_WRITE(reg, val);
480
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300481 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
482 intel_hdmi_set_spd_infoframe(encoder);
483}
484
485static void hsw_set_infoframes(struct drm_encoder *encoder,
486 struct drm_display_mode *adjusted_mode)
487{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300488 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
489 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
490 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
491 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300492 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300493
494 if (!intel_hdmi->has_hdmi_sink) {
495 I915_WRITE(reg, 0);
496 return;
497 }
498
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300499 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
500 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
501
502 I915_WRITE(reg, val);
503
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300504 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
505 intel_hdmi_set_spd_infoframe(encoder);
506}
507
Eric Anholt7d573822009-01-02 13:33:00 -0800508static void intel_hdmi_mode_set(struct drm_encoder *encoder,
509 struct drm_display_mode *mode,
510 struct drm_display_mode *adjusted_mode)
511{
512 struct drm_device *dev = encoder->dev;
513 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300514 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
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 sdvox;
517
Paulo Zanonib659c3d2012-05-28 16:42:56 -0300518 sdvox = SDVO_ENCODING_HDMI;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700519 if (!HAS_PCH_SPLIT(dev))
520 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400521 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
522 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
523 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
524 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800525
Jesse Barnes020f6702011-06-24 12:19:25 -0700526 if (intel_crtc->bpp > 24)
527 sdvox |= COLOR_FORMAT_12bpc;
528 else
529 sdvox |= COLOR_FORMAT_8bpc;
530
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800531 /* Required on CPT */
532 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
533 sdvox |= HDMI_MODE_SELECT;
534
David Härdeman3c17fe42010-09-24 21:44:32 +0200535 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800536 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
537 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800538 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200539 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800540 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200541 }
Eric Anholt7d573822009-01-02 13:33:00 -0800542
Jesse Barnes75770562011-10-12 09:01:58 -0700543 if (HAS_PCH_CPT(dev))
544 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
545 else if (intel_crtc->pipe == 1)
546 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800547
Chris Wilsonea5b2132010-08-04 13:50:23 +0100548 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
549 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200550
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300551 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800552}
553
554static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
555{
556 struct drm_device *dev = encoder->dev;
557 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100558 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800559 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800560 u32 enable_bits = SDVO_ENABLE;
561
562 if (intel_hdmi->has_audio)
563 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800564
Chris Wilsonea5b2132010-08-04 13:50:23 +0100565 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000566
567 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
568 * we do this anyway which shows more stable in testing.
569 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800570 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100571 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
572 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800573 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000574
575 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800576 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000577 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800578 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000579 }
580
Chris Wilsonea5b2132010-08-04 13:50:23 +0100581 I915_WRITE(intel_hdmi->sdvox_reg, temp);
582 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000583
584 /* HW workaround, need to write this twice for issue that may result
585 * in first write getting masked.
586 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800587 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100588 I915_WRITE(intel_hdmi->sdvox_reg, temp);
589 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000590 }
Eric Anholt7d573822009-01-02 13:33:00 -0800591}
592
Eric Anholt7d573822009-01-02 13:33:00 -0800593static int intel_hdmi_mode_valid(struct drm_connector *connector,
594 struct drm_display_mode *mode)
595{
596 if (mode->clock > 165000)
597 return MODE_CLOCK_HIGH;
598 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200599 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800600
601 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
602 return MODE_NO_DBLESCAN;
603
604 return MODE_OK;
605}
606
607static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
608 struct drm_display_mode *mode,
609 struct drm_display_mode *adjusted_mode)
610{
611 return true;
612}
613
Chris Wilson8ec22b22012-05-11 18:01:34 +0100614static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
615{
616 struct drm_device *dev = intel_hdmi->base.base.dev;
617 struct drm_i915_private *dev_priv = dev->dev_private;
618 uint32_t bit;
619
620 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100621 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100622 bit = HDMIB_HOTPLUG_LIVE_STATUS;
623 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100624 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100625 bit = HDMIC_HOTPLUG_LIVE_STATUS;
626 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100627 default:
628 bit = 0;
629 break;
630 }
631
632 return I915_READ(PORT_HOTPLUG_STAT) & bit;
633}
634
Keith Packardaa93d632009-05-05 09:52:46 -0700635static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100636intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800637{
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;
640 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700641 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800642
Chris Wilson8ec22b22012-05-11 18:01:34 +0100643 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
644 return status;
645
Chris Wilsonea5b2132010-08-04 13:50:23 +0100646 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800647 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700648 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800649 intel_gmbus_get_adapter(dev_priv,
650 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800651
Keith Packardaa93d632009-05-05 09:52:46 -0700652 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700653 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700654 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800655 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
656 intel_hdmi->has_hdmi_sink =
657 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800658 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700659 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800660 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700661 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800662 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800663
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100664 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800665 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
666 intel_hdmi->has_audio =
667 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100668 }
669
Keith Packardaa93d632009-05-05 09:52:46 -0700670 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800671}
672
Eric Anholt7d573822009-01-02 13:33:00 -0800673static int intel_hdmi_get_modes(struct drm_connector *connector)
674{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100675 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700676 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800677
678 /* We should parse the EDID data and find out if it's an HDMI sink so
679 * we can send audio to it.
680 */
681
Chris Wilsonf899fc62010-07-20 15:44:45 -0700682 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800683 intel_gmbus_get_adapter(dev_priv,
684 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800685}
686
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000687static bool
688intel_hdmi_detect_audio(struct drm_connector *connector)
689{
690 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
691 struct drm_i915_private *dev_priv = connector->dev->dev_private;
692 struct edid *edid;
693 bool has_audio = false;
694
695 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800696 intel_gmbus_get_adapter(dev_priv,
697 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000698 if (edid) {
699 if (edid->input & DRM_EDID_INPUT_DIGITAL)
700 has_audio = drm_detect_monitor_audio(edid);
701
702 connector->display_info.raw_edid = NULL;
703 kfree(edid);
704 }
705
706 return has_audio;
707}
708
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100709static int
710intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300711 struct drm_property *property,
712 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100713{
714 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000715 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100716 int ret;
717
718 ret = drm_connector_property_set_value(connector, property, val);
719 if (ret)
720 return ret;
721
Chris Wilson3f43c482011-05-12 22:17:24 +0100722 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800723 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000724 bool has_audio;
725
726 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100727 return 0;
728
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000729 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100730
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800731 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000732 has_audio = intel_hdmi_detect_audio(connector);
733 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800734 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000735
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800736 if (i == HDMI_AUDIO_OFF_DVI)
737 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100738
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000739 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100740 goto done;
741 }
742
Chris Wilsone953fd72011-02-21 22:23:52 +0000743 if (property == dev_priv->broadcast_rgb_property) {
744 if (val == !!intel_hdmi->color_range)
745 return 0;
746
747 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
748 goto done;
749 }
750
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100751 return -EINVAL;
752
753done:
754 if (intel_hdmi->base.base.crtc) {
755 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
756 drm_crtc_helper_set_mode(crtc, &crtc->mode,
757 crtc->x, crtc->y,
758 crtc->fb);
759 }
760
761 return 0;
762}
763
Eric Anholt7d573822009-01-02 13:33:00 -0800764static void intel_hdmi_destroy(struct drm_connector *connector)
765{
Eric Anholt7d573822009-01-02 13:33:00 -0800766 drm_sysfs_connector_remove(connector);
767 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800768 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800769}
770
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300771static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
772 .dpms = intel_ddi_dpms,
773 .mode_fixup = intel_hdmi_mode_fixup,
774 .prepare = intel_encoder_prepare,
775 .mode_set = intel_ddi_mode_set,
776 .commit = intel_encoder_commit,
777};
778
Eric Anholt7d573822009-01-02 13:33:00 -0800779static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
780 .dpms = intel_hdmi_dpms,
781 .mode_fixup = intel_hdmi_mode_fixup,
782 .prepare = intel_encoder_prepare,
783 .mode_set = intel_hdmi_mode_set,
784 .commit = intel_encoder_commit,
785};
786
787static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700788 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800789 .detect = intel_hdmi_detect,
790 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100791 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800792 .destroy = intel_hdmi_destroy,
793};
794
795static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
796 .get_modes = intel_hdmi_get_modes,
797 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100798 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800799};
800
Eric Anholt7d573822009-01-02 13:33:00 -0800801static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100802 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800803};
804
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100805static void
806intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
807{
Chris Wilson3f43c482011-05-12 22:17:24 +0100808 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000809 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100810}
811
Eric Anholt7d573822009-01-02 13:33:00 -0800812void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
813{
814 struct drm_i915_private *dev_priv = dev->dev_private;
815 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700816 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800817 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100818 struct intel_hdmi *intel_hdmi;
Eric Anholt7d573822009-01-02 13:33:00 -0800819
Chris Wilsonea5b2132010-08-04 13:50:23 +0100820 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
821 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800822 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800823
824 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
825 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100826 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800827 return;
828 }
829
Chris Wilsonea5b2132010-08-04 13:50:23 +0100830 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100831 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
832 DRM_MODE_ENCODER_TMDS);
833
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800834 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800835 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400836 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800837 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
838
Eric Anholt21d40d32010-03-25 11:11:14 -0700839 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800840
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000841 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100842 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800843 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700844 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800845
846 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800847 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700848 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700849 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800850 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800851 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700852 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700853 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800854 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800855 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700856 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700857 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800858 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800859 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700860 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700861 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800862 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800863 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700864 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700865 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800866 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov7ceae0a2012-05-09 15:37:28 -0300867 } else if (sdvox_reg == DDI_BUF_CTL(PORT_B)) {
868 DRM_DEBUG_DRIVER("LPT: detected output on DDI B\n");
869 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
870 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
871 intel_hdmi->ddi_port = PORT_B;
872 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
873 } else if (sdvox_reg == DDI_BUF_CTL(PORT_C)) {
874 DRM_DEBUG_DRIVER("LPT: detected output on DDI C\n");
875 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
876 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
877 intel_hdmi->ddi_port = PORT_C;
878 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
879 } else if (sdvox_reg == DDI_BUF_CTL(PORT_D)) {
880 DRM_DEBUG_DRIVER("LPT: detected output on DDI D\n");
881 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
882 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
883 intel_hdmi->ddi_port = PORT_D;
884 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300885 } else {
886 /* If we got an unknown sdvox_reg, things are pretty much broken
887 * in a way that we should let the kernel know about it */
888 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800889 }
Eric Anholt7d573822009-01-02 13:33:00 -0800890
Chris Wilsonea5b2132010-08-04 13:50:23 +0100891 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800892
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530893 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200894 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300895 intel_hdmi->set_infoframes = g4x_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700896 } else if (IS_VALLEYVIEW(dev)) {
897 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300898 intel_hdmi->set_infoframes = vlv_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300899 } else if (IS_HASWELL(dev)) {
900 /* FIXME: Haswell has a new set of DIP frame registers, but we are
901 * just doing the minimal required for HDMI to work at this stage.
902 */
903 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300904 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300905 } else if (HAS_PCH_IBX(dev)) {
906 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300907 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300908 } else {
909 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300910 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530911 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700912
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300913 if (IS_HASWELL(dev))
914 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs_hsw);
915 else
916 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800917
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100918 intel_hdmi_add_properties(intel_hdmi, connector);
919
Chris Wilsondf0e9242010-09-09 16:20:55 +0100920 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800921 drm_sysfs_connector_add(connector);
922
923 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
924 * 0xd. Failure to do so will result in spurious interrupts being
925 * generated on the port when a cable is not attached.
926 */
927 if (IS_G4X(dev) && !IS_GM45(dev)) {
928 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
929 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
930 }
Eric Anholt7d573822009-01-02 13:33:00 -0800931}