blob: ef8409794ab6259ccfe1d27f49a78ce5f4d4037d [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
Daniel Vetterafba0182012-06-12 16:36:45 +020040static void
41assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
42{
43 struct drm_device *dev = intel_hdmi->base.base.dev;
44 struct drm_i915_private *dev_priv = dev->dev_private;
45 uint32_t enabled_bits;
46
47 enabled_bits = IS_HASWELL(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
48
49 WARN(I915_READ(intel_hdmi->sdvox_reg) & enabled_bits,
50 "HDMI port enabled, expecting disabled\n");
51}
52
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030053struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010054{
Chris Wilson4ef69c72010-09-09 15:14:28 +010055 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010056}
57
Chris Wilsondf0e9242010-09-09 16:20:55 +010058static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
59{
60 return container_of(intel_attached_encoder(connector),
61 struct intel_hdmi, base);
62}
63
Jesse Barnes45187ac2011-08-03 09:22:55 -070064void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020065{
Jesse Barnes45187ac2011-08-03 09:22:55 -070066 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020067 uint8_t sum = 0;
68 unsigned i;
69
Jesse Barnes45187ac2011-08-03 09:22:55 -070070 frame->checksum = 0;
71 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020072
Jesse Barnes64a8fc02011-09-22 11:16:00 +053073 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020074 sum += data[i];
75
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020077}
78
Daniel Vetterbc2481f2012-05-08 15:18:32 +020079static u32 g4x_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020080{
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_SELECT_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070084 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030085 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070086 default:
87 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030088 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070089 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070090}
91
Daniel Vetterbc2481f2012-05-08 15:18:32 +020092static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -070093{
Jesse Barnes45187ac2011-08-03 09:22:55 -070094 switch (frame->type) {
95 case DIP_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030096 return VIDEO_DIP_ENABLE_AVI;
Jesse Barnes45187ac2011-08-03 09:22:55 -070097 case DIP_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030098 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030099 default:
100 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
Paulo Zanonied517fb2012-05-14 17:12:50 -0300101 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300102 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300103}
104
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300105static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
106{
107 switch (frame->type) {
108 case DIP_TYPE_AVI:
109 return VIDEO_DIP_ENABLE_AVI_HSW;
110 case DIP_TYPE_SPD:
111 return VIDEO_DIP_ENABLE_SPD_HSW;
112 default:
113 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
114 return 0;
115 }
116}
117
118static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, enum pipe pipe)
119{
120 switch (frame->type) {
121 case DIP_TYPE_AVI:
122 return HSW_TVIDEO_DIP_AVI_DATA(pipe);
123 case DIP_TYPE_SPD:
124 return HSW_TVIDEO_DIP_SPD_DATA(pipe);
125 default:
126 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
127 return 0;
128 }
129}
130
Daniel Vettera3da1df2012-05-08 15:19:06 +0200131static void g4x_write_infoframe(struct drm_encoder *encoder,
132 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700133{
134 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200135 struct drm_device *dev = encoder->dev;
136 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300137 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200139
Paulo Zanoni822974a2012-05-28 16:42:51 -0300140 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
141
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300142 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200143 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700144
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200145 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300146
147 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700148
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300149 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700150 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200151 I915_WRITE(VIDEO_DIP_DATA, *data);
152 data++;
153 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300154 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200155
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200156 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300157 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200158 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700159
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300160 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300161 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200162}
163
Paulo Zanonifdf12502012-05-04 17:18:24 -0300164static void ibx_write_infoframe(struct drm_encoder *encoder,
165 struct dip_infoframe *frame)
166{
167 uint32_t *data = (uint32_t *)frame;
168 struct drm_device *dev = encoder->dev;
169 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300170 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300171 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
172 unsigned i, len = DIP_HEADER_SIZE + frame->len;
173 u32 val = I915_READ(reg);
174
Paulo Zanoni822974a2012-05-28 16:42:51 -0300175 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
176
Paulo Zanonifdf12502012-05-04 17:18:24 -0300177 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200178 val |= g4x_infoframe_index(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300179
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200180 val &= ~g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300181
182 I915_WRITE(reg, val);
183
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300184 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300185 for (i = 0; i < len; i += 4) {
186 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
187 data++;
188 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300189 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300190
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200191 val |= g4x_infoframe_enable(frame);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300192 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200193 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300194
195 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300196 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300197}
198
199static void cpt_write_infoframe(struct drm_encoder *encoder,
200 struct dip_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700201{
202 uint32_t *data = (uint32_t *)frame;
203 struct drm_device *dev = encoder->dev;
204 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300205 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700206 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
207 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300208 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700209
Paulo Zanoni822974a2012-05-28 16:42:51 -0300210 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
211
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530212 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200213 val |= g4x_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700214
Paulo Zanoniecb97852012-05-04 17:18:21 -0300215 /* The DIP control register spec says that we need to update the AVI
216 * infoframe without clearing its enable bit */
Paulo Zanoni822974a2012-05-28 16:42:51 -0300217 if (frame->type != DIP_TYPE_AVI)
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200218 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300219
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300220 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700221
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300222 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700223 for (i = 0; i < len; i += 4) {
224 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
225 data++;
226 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300227 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700228
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200229 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300230 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200231 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700232
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300233 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300234 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700235}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700236
237static void vlv_write_infoframe(struct drm_encoder *encoder,
238 struct dip_infoframe *frame)
239{
240 uint32_t *data = (uint32_t *)frame;
241 struct drm_device *dev = encoder->dev;
242 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300243 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700244 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
245 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300246 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700247
Paulo Zanoni822974a2012-05-28 16:42:51 -0300248 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
249
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700250 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200251 val |= g4x_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700252
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200253 val &= ~g4x_infoframe_enable(frame);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300254
255 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700256
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300257 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700258 for (i = 0; i < len; i += 4) {
259 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
260 data++;
261 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300262 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700263
Daniel Vetterbc2481f2012-05-08 15:18:32 +0200264 val |= g4x_infoframe_enable(frame);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300265 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200266 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700267
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300268 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300269 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700270}
271
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300272static void hsw_write_infoframe(struct drm_encoder *encoder,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300273 struct dip_infoframe *frame)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300274{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300275 uint32_t *data = (uint32_t *)frame;
276 struct drm_device *dev = encoder->dev;
277 struct drm_i915_private *dev_priv = dev->dev_private;
278 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
279 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
280 u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->pipe);
281 unsigned int i, len = DIP_HEADER_SIZE + frame->len;
282 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300283
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300284 if (data_reg == 0)
285 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300286
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300287 val &= ~hsw_infoframe_enable(frame);
288 I915_WRITE(ctl_reg, val);
289
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300290 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300291 for (i = 0; i < len; i += 4) {
292 I915_WRITE(data_reg + i, *data);
293 data++;
294 }
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300295 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300296
297 val |= hsw_infoframe_enable(frame);
298 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300299 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300300}
301
Jesse Barnes45187ac2011-08-03 09:22:55 -0700302static void intel_set_infoframe(struct drm_encoder *encoder,
303 struct dip_infoframe *frame)
304{
305 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
306
Jesse Barnes45187ac2011-08-03 09:22:55 -0700307 intel_dip_infoframe_csum(frame);
308 intel_hdmi->write_infoframe(encoder, frame);
309}
310
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300311static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300312 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700313{
314 struct dip_infoframe avi_if = {
315 .type = DIP_TYPE_AVI,
316 .ver = DIP_VERSION_AVI,
317 .len = DIP_LEN_AVI,
318 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700319
Paulo Zanonic846b612012-04-13 16:31:41 -0300320 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
321 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
322
Jesse Barnes45187ac2011-08-03 09:22:55 -0700323 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700324}
325
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300326static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700327{
328 struct dip_infoframe spd_if;
329
330 memset(&spd_if, 0, sizeof(spd_if));
331 spd_if.type = DIP_TYPE_SPD;
332 spd_if.ver = DIP_VERSION_SPD;
333 spd_if.len = DIP_LEN_SPD;
334 strcpy(spd_if.body.spd.vn, "Intel");
335 strcpy(spd_if.body.spd.pd, "Integrated gfx");
336 spd_if.body.spd.sdi = DIP_SPD_PC;
337
338 intel_set_infoframe(encoder, &spd_if);
339}
340
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300341static void g4x_set_infoframes(struct drm_encoder *encoder,
342 struct drm_display_mode *adjusted_mode)
343{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300344 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
345 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
346 u32 reg = VIDEO_DIP_CTL;
347 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300348 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300349
Daniel Vetterafba0182012-06-12 16:36:45 +0200350 assert_hdmi_port_disabled(intel_hdmi);
351
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300352 /* If the registers were not initialized yet, they might be zeroes,
353 * which means we're selecting the AVI DIP and we're setting its
354 * frequency to once. This seems to really confuse the HW and make
355 * things stop working (the register spec says the AVI always needs to
356 * be sent every VSync). So here we avoid writing to the register more
357 * than we need and also explicitly select the AVI DIP and explicitly
358 * set its frequency to every VSync. Avoiding to write it twice seems to
359 * be enough to solve the problem, but being defensive shouldn't hurt us
360 * either. */
361 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
362
363 if (!intel_hdmi->has_hdmi_sink) {
364 if (!(val & VIDEO_DIP_ENABLE))
365 return;
366 val &= ~VIDEO_DIP_ENABLE;
367 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300368 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300369 return;
370 }
371
Paulo Zanonif278d972012-05-28 16:42:50 -0300372 switch (intel_hdmi->sdvox_reg) {
373 case SDVOB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300374 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300375 break;
376 case SDVOC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300377 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300378 break;
379 default:
380 return;
381 }
382
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300383 if (port != (val & VIDEO_DIP_PORT_MASK)) {
384 if (val & VIDEO_DIP_ENABLE) {
385 val &= ~VIDEO_DIP_ENABLE;
386 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300387 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300388 }
389 val &= ~VIDEO_DIP_PORT_MASK;
390 val |= port;
391 }
392
Paulo Zanoni822974a2012-05-28 16:42:51 -0300393 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300394 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300395
Paulo Zanonif278d972012-05-28 16:42:50 -0300396 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300397 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300398
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300399 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
400 intel_hdmi_set_spd_infoframe(encoder);
401}
402
403static void ibx_set_infoframes(struct drm_encoder *encoder,
404 struct drm_display_mode *adjusted_mode)
405{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300406 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
407 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
408 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
409 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
410 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300411 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300412
Daniel Vetterafba0182012-06-12 16:36:45 +0200413 assert_hdmi_port_disabled(intel_hdmi);
414
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300415 /* 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;
422 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300423 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300424 return;
425 }
426
Paulo Zanonif278d972012-05-28 16:42:50 -0300427 switch (intel_hdmi->sdvox_reg) {
428 case HDMIB:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300429 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300430 break;
431 case HDMIC:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300432 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300433 break;
434 case HDMID:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300435 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300436 break;
437 default:
438 return;
439 }
440
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300441 if (port != (val & VIDEO_DIP_PORT_MASK)) {
442 if (val & VIDEO_DIP_ENABLE) {
443 val &= ~VIDEO_DIP_ENABLE;
444 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300445 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300446 }
447 val &= ~VIDEO_DIP_PORT_MASK;
448 val |= port;
449 }
450
Paulo Zanoni822974a2012-05-28 16:42:51 -0300451 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300452 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
453 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300454
Paulo Zanonif278d972012-05-28 16:42:50 -0300455 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300456 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300457
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300458 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
459 intel_hdmi_set_spd_infoframe(encoder);
460}
461
462static void cpt_set_infoframes(struct drm_encoder *encoder,
463 struct drm_display_mode *adjusted_mode)
464{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300465 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
466 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
467 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
468 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
469 u32 val = I915_READ(reg);
470
Daniel Vetterafba0182012-06-12 16:36:45 +0200471 assert_hdmi_port_disabled(intel_hdmi);
472
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300473 /* See the big comment in g4x_set_infoframes() */
474 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
475
476 if (!intel_hdmi->has_hdmi_sink) {
477 if (!(val & VIDEO_DIP_ENABLE))
478 return;
479 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
480 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300481 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300482 return;
483 }
484
Paulo Zanoni822974a2012-05-28 16:42:51 -0300485 /* Set both together, unset both together: see the spec. */
486 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300487 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
488 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300489
490 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300491 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300492
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300493 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
494 intel_hdmi_set_spd_infoframe(encoder);
495}
496
497static void vlv_set_infoframes(struct drm_encoder *encoder,
498 struct drm_display_mode *adjusted_mode)
499{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300500 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
501 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
502 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
503 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
504 u32 val = I915_READ(reg);
505
Daniel Vetterafba0182012-06-12 16:36:45 +0200506 assert_hdmi_port_disabled(intel_hdmi);
507
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300508 /* See the big comment in g4x_set_infoframes() */
509 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
510
511 if (!intel_hdmi->has_hdmi_sink) {
512 if (!(val & VIDEO_DIP_ENABLE))
513 return;
514 val &= ~VIDEO_DIP_ENABLE;
515 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300516 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300517 return;
518 }
519
Paulo Zanoni822974a2012-05-28 16:42:51 -0300520 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300521 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
522 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300523
524 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300525 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300526
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300527 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
528 intel_hdmi_set_spd_infoframe(encoder);
529}
530
531static void hsw_set_infoframes(struct drm_encoder *encoder,
532 struct drm_display_mode *adjusted_mode)
533{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300534 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
535 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
536 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
537 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300538 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300539
Daniel Vetterafba0182012-06-12 16:36:45 +0200540 assert_hdmi_port_disabled(intel_hdmi);
541
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300542 if (!intel_hdmi->has_hdmi_sink) {
543 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300544 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300545 return;
546 }
547
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300548 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
549 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
550
551 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300552 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300553
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300554 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
555 intel_hdmi_set_spd_infoframe(encoder);
556}
557
Eric Anholt7d573822009-01-02 13:33:00 -0800558static void intel_hdmi_mode_set(struct drm_encoder *encoder,
559 struct drm_display_mode *mode,
560 struct drm_display_mode *adjusted_mode)
561{
562 struct drm_device *dev = encoder->dev;
563 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300564 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100565 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800566 u32 sdvox;
567
Paulo Zanonib659c3d2012-05-28 16:42:56 -0300568 sdvox = SDVO_ENCODING_HDMI;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700569 if (!HAS_PCH_SPLIT(dev))
570 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400571 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
572 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
573 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
574 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800575
Jesse Barnes020f6702011-06-24 12:19:25 -0700576 if (intel_crtc->bpp > 24)
577 sdvox |= COLOR_FORMAT_12bpc;
578 else
579 sdvox |= COLOR_FORMAT_8bpc;
580
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800581 /* Required on CPT */
582 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
583 sdvox |= HDMI_MODE_SELECT;
584
David Härdeman3c17fe42010-09-24 21:44:32 +0200585 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800586 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
587 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800588 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200589 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800590 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200591 }
Eric Anholt7d573822009-01-02 13:33:00 -0800592
Jesse Barnes75770562011-10-12 09:01:58 -0700593 if (HAS_PCH_CPT(dev))
594 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200595 else if (intel_crtc->pipe == PIPE_B)
Jesse Barnes75770562011-10-12 09:01:58 -0700596 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800597
Chris Wilsonea5b2132010-08-04 13:50:23 +0100598 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
599 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200600
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300601 intel_hdmi->set_infoframes(encoder, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800602}
603
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200604static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800605{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200606 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800607 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200608 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800609 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800610 u32 enable_bits = SDVO_ENABLE;
611
612 if (intel_hdmi->has_audio)
613 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800614
Chris Wilsonea5b2132010-08-04 13:50:23 +0100615 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000616
Daniel Vetter7a87c282012-06-05 11:03:39 +0200617 /* HW workaround for IBX, we need to move the port to transcoder A
618 * before disabling it. */
619 if (HAS_PCH_IBX(dev)) {
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200620 struct drm_crtc *crtc = encoder->base.crtc;
Daniel Vetter7a87c282012-06-05 11:03:39 +0200621 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
622
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200623 /* Restore the transcoder select bit. */
624 if (pipe == PIPE_B)
625 enable_bits |= SDVO_PIPE_B_SELECT;
626 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200627
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200628 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
629 * we do this anyway which shows more stable in testing.
630 */
631 if (HAS_PCH_SPLIT(dev)) {
632 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
633 POSTING_READ(intel_hdmi->sdvox_reg);
634 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200635
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200636 temp |= enable_bits;
637
638 I915_WRITE(intel_hdmi->sdvox_reg, temp);
639 POSTING_READ(intel_hdmi->sdvox_reg);
640
641 /* HW workaround, need to write this twice for issue that may result
642 * in first write getting masked.
643 */
644 if (HAS_PCH_SPLIT(dev)) {
645 I915_WRITE(intel_hdmi->sdvox_reg, temp);
646 POSTING_READ(intel_hdmi->sdvox_reg);
647 }
648}
649
650static void intel_disable_hdmi(struct intel_encoder *encoder)
651{
652 struct drm_device *dev = encoder->base.dev;
653 struct drm_i915_private *dev_priv = dev->dev_private;
654 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
655 u32 temp;
656 u32 enable_bits = SDVO_ENABLE;
657
658 if (intel_hdmi->has_audio)
659 enable_bits |= SDVO_AUDIO_ENABLE;
660
661 temp = I915_READ(intel_hdmi->sdvox_reg);
662
663 /* HW workaround for IBX, we need to move the port to transcoder A
664 * before disabling it. */
665 if (HAS_PCH_IBX(dev)) {
666 struct drm_crtc *crtc = encoder->base.crtc;
667 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
668
669 if (temp & SDVO_PIPE_B_SELECT) {
670 temp &= ~SDVO_PIPE_B_SELECT;
671 I915_WRITE(intel_hdmi->sdvox_reg, temp);
672 POSTING_READ(intel_hdmi->sdvox_reg);
673
674 /* Again we need to write this twice. */
675 I915_WRITE(intel_hdmi->sdvox_reg, temp);
676 POSTING_READ(intel_hdmi->sdvox_reg);
677
678 /* Transcoder selection bits only update
679 * effectively on vblank. */
680 if (crtc)
681 intel_wait_for_vblank(dev, pipe);
682 else
683 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200684 }
685 }
686
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000687 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
688 * we do this anyway which shows more stable in testing.
689 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800690 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100691 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
692 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800693 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000694
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200695 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000696
Chris Wilsonea5b2132010-08-04 13:50:23 +0100697 I915_WRITE(intel_hdmi->sdvox_reg, temp);
698 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000699
700 /* HW workaround, need to write this twice for issue that may result
701 * in first write getting masked.
702 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800703 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100704 I915_WRITE(intel_hdmi->sdvox_reg, temp);
705 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000706 }
Eric Anholt7d573822009-01-02 13:33:00 -0800707}
708
Eric Anholt7d573822009-01-02 13:33:00 -0800709static int intel_hdmi_mode_valid(struct drm_connector *connector,
710 struct drm_display_mode *mode)
711{
712 if (mode->clock > 165000)
713 return MODE_CLOCK_HIGH;
714 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200715 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800716
717 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
718 return MODE_NO_DBLESCAN;
719
720 return MODE_OK;
721}
722
723static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200724 const struct drm_display_mode *mode,
Eric Anholt7d573822009-01-02 13:33:00 -0800725 struct drm_display_mode *adjusted_mode)
726{
727 return true;
728}
729
Chris Wilson8ec22b22012-05-11 18:01:34 +0100730static bool g4x_hdmi_connected(struct intel_hdmi *intel_hdmi)
731{
732 struct drm_device *dev = intel_hdmi->base.base.dev;
733 struct drm_i915_private *dev_priv = dev->dev_private;
734 uint32_t bit;
735
736 switch (intel_hdmi->sdvox_reg) {
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100737 case SDVOB:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100738 bit = HDMIB_HOTPLUG_LIVE_STATUS;
739 break;
Chris Wilsoneeafaac2012-05-25 10:23:37 +0100740 case SDVOC:
Chris Wilson8ec22b22012-05-11 18:01:34 +0100741 bit = HDMIC_HOTPLUG_LIVE_STATUS;
742 break;
Chris Wilson8ec22b22012-05-11 18:01:34 +0100743 default:
744 bit = 0;
745 break;
746 }
747
748 return I915_READ(PORT_HOTPLUG_STAT) & bit;
749}
750
Keith Packardaa93d632009-05-05 09:52:46 -0700751static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100752intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800753{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100754 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700755 struct drm_i915_private *dev_priv = connector->dev->dev_private;
756 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700757 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800758
Chris Wilson8ec22b22012-05-11 18:01:34 +0100759 if (IS_G4X(connector->dev) && !g4x_hdmi_connected(intel_hdmi))
760 return status;
761
Chris Wilsonea5b2132010-08-04 13:50:23 +0100762 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800763 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700764 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800765 intel_gmbus_get_adapter(dev_priv,
766 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800767
Keith Packardaa93d632009-05-05 09:52:46 -0700768 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700769 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700770 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800771 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
772 intel_hdmi->has_hdmi_sink =
773 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800774 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700775 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800776 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700777 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800778 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800779
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100780 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800781 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
782 intel_hdmi->has_audio =
783 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100784 }
785
Keith Packardaa93d632009-05-05 09:52:46 -0700786 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800787}
788
Eric Anholt7d573822009-01-02 13:33:00 -0800789static int intel_hdmi_get_modes(struct drm_connector *connector)
790{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100791 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700792 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800793
794 /* We should parse the EDID data and find out if it's an HDMI sink so
795 * we can send audio to it.
796 */
797
Chris Wilsonf899fc62010-07-20 15:44:45 -0700798 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800799 intel_gmbus_get_adapter(dev_priv,
800 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800801}
802
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000803static bool
804intel_hdmi_detect_audio(struct drm_connector *connector)
805{
806 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
807 struct drm_i915_private *dev_priv = connector->dev->dev_private;
808 struct edid *edid;
809 bool has_audio = false;
810
811 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800812 intel_gmbus_get_adapter(dev_priv,
813 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000814 if (edid) {
815 if (edid->input & DRM_EDID_INPUT_DIGITAL)
816 has_audio = drm_detect_monitor_audio(edid);
817
818 connector->display_info.raw_edid = NULL;
819 kfree(edid);
820 }
821
822 return has_audio;
823}
824
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100825static int
826intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300827 struct drm_property *property,
828 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100829{
830 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000831 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100832 int ret;
833
834 ret = drm_connector_property_set_value(connector, property, val);
835 if (ret)
836 return ret;
837
Chris Wilson3f43c482011-05-12 22:17:24 +0100838 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800839 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000840 bool has_audio;
841
842 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100843 return 0;
844
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000845 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100846
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800847 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000848 has_audio = intel_hdmi_detect_audio(connector);
849 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800850 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000851
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800852 if (i == HDMI_AUDIO_OFF_DVI)
853 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100854
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000855 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100856 goto done;
857 }
858
Chris Wilsone953fd72011-02-21 22:23:52 +0000859 if (property == dev_priv->broadcast_rgb_property) {
860 if (val == !!intel_hdmi->color_range)
861 return 0;
862
863 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
864 goto done;
865 }
866
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100867 return -EINVAL;
868
869done:
870 if (intel_hdmi->base.base.crtc) {
871 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
Daniel Vettera6778b32012-07-02 09:56:42 +0200872 intel_set_mode(crtc, &crtc->mode,
873 crtc->x, crtc->y, crtc->fb);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100874 }
875
876 return 0;
877}
878
Eric Anholt7d573822009-01-02 13:33:00 -0800879static void intel_hdmi_destroy(struct drm_connector *connector)
880{
Eric Anholt7d573822009-01-02 13:33:00 -0800881 drm_sysfs_connector_remove(connector);
882 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800883 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800884}
885
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300886static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs_hsw = {
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300887 .mode_fixup = intel_hdmi_mode_fixup,
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200888 .prepare = intel_encoder_noop,
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300889 .mode_set = intel_ddi_mode_set,
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200890 .commit = intel_encoder_noop,
891 .disable = intel_encoder_disable,
Eugeni Dodonov72662e12012-05-09 15:37:31 -0300892};
893
Eric Anholt7d573822009-01-02 13:33:00 -0800894static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
Eric Anholt7d573822009-01-02 13:33:00 -0800895 .mode_fixup = intel_hdmi_mode_fixup,
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200896 .prepare = intel_encoder_noop,
Eric Anholt7d573822009-01-02 13:33:00 -0800897 .mode_set = intel_hdmi_mode_set,
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200898 .commit = intel_encoder_noop,
899 .disable = intel_encoder_disable,
Eric Anholt7d573822009-01-02 13:33:00 -0800900};
901
902static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200903 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800904 .detect = intel_hdmi_detect,
905 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100906 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800907 .destroy = intel_hdmi_destroy,
908};
909
910static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
911 .get_modes = intel_hdmi_get_modes,
912 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100913 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800914};
915
Eric Anholt7d573822009-01-02 13:33:00 -0800916static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100917 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800918};
919
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100920static void
921intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
922{
Chris Wilson3f43c482011-05-12 22:17:24 +0100923 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000924 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100925}
926
Daniel Vetter08d644a2012-07-12 20:19:59 +0200927void intel_hdmi_init(struct drm_device *dev, int sdvox_reg, enum port port)
Eric Anholt7d573822009-01-02 13:33:00 -0800928{
929 struct drm_i915_private *dev_priv = dev->dev_private;
930 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700931 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800932 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100933 struct intel_hdmi *intel_hdmi;
Eric Anholt7d573822009-01-02 13:33:00 -0800934
Chris Wilsonea5b2132010-08-04 13:50:23 +0100935 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
936 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800937 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800938
939 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
940 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100941 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800942 return;
943 }
944
Chris Wilsonea5b2132010-08-04 13:50:23 +0100945 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100946 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
947 DRM_MODE_ENCODER_TMDS);
948
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800949 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800950 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400951 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800952 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
953
Eric Anholt21d40d32010-03-25 11:11:14 -0700954 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800955
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000956 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100957 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800958 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700959 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800960
Daniel Vetter66a92782012-07-12 20:08:18 +0200961 intel_encoder->cloneable = false;
962
Daniel Vetter08d644a2012-07-12 20:19:59 +0200963 intel_hdmi->ddi_port = port;
964 switch (port) {
965 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700966 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800967 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200968 break;
969 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700970 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800971 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200972 break;
973 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -0700974 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800975 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Daniel Vetter08d644a2012-07-12 20:19:59 +0200976 break;
977 case PORT_A:
978 /* Internal port only for eDP. */
979 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -0300980 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +0800981 }
Eric Anholt7d573822009-01-02 13:33:00 -0800982
Chris Wilsonea5b2132010-08-04 13:50:23 +0100983 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800984
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530985 if (!HAS_PCH_SPLIT(dev)) {
Daniel Vettera3da1df2012-05-08 15:19:06 +0200986 intel_hdmi->write_infoframe = g4x_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300987 intel_hdmi->set_infoframes = g4x_set_infoframes;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700988 } else if (IS_VALLEYVIEW(dev)) {
989 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300990 intel_hdmi->set_infoframes = vlv_set_infoframes;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300991 } else if (IS_HASWELL(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300992 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300993 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300994 } else if (HAS_PCH_IBX(dev)) {
995 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300996 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300997 } else {
998 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300999 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301000 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001001
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001002 if (IS_HASWELL(dev)) {
1003 intel_encoder->enable = intel_enable_ddi;
1004 intel_encoder->disable = intel_disable_ddi;
1005 drm_encoder_helper_add(&intel_encoder->base,
1006 &intel_hdmi_helper_funcs_hsw);
1007 } else {
1008 intel_encoder->enable = intel_enable_hdmi;
1009 intel_encoder->disable = intel_disable_hdmi;
1010 drm_encoder_helper_add(&intel_encoder->base,
1011 &intel_hdmi_helper_funcs);
1012 }
1013
Eric Anholt7d573822009-01-02 13:33:00 -08001014
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001015 intel_hdmi_add_properties(intel_hdmi, connector);
1016
Chris Wilsondf0e9242010-09-09 16:20:55 +01001017 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -08001018 drm_sysfs_connector_add(connector);
1019
1020 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1021 * 0xd. Failure to do so will result in spurious interrupts being
1022 * generated on the port when a cable is not attached.
1023 */
1024 if (IS_G4X(dev) && !IS_GM45(dev)) {
1025 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1026 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1027 }
Eric Anholt7d573822009-01-02 13:33:00 -08001028}