blob: bf218753cbaf818086704aa9217c81bf713407f5 [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
Chris Wilsonea5b2132010-08-04 13:50:23 +010040struct intel_hdmi {
41 struct intel_encoder base;
Eric Anholt7d573822009-01-02 13:33:00 -080042 u32 sdvox_reg;
Chris Wilsonf899fc62010-07-20 15:44:45 -070043 int ddc_bus;
Chris Wilsone953fd72011-02-21 22:23:52 +000044 uint32_t color_range;
Ma Ling9dff6af2009-04-02 13:13:26 +080045 bool has_hdmi_sink;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +080046 bool has_audio;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +080047 enum hdmi_force_audio force_audio;
Jesse Barnes45187ac2011-08-03 09:22:55 -070048 void (*write_infoframe)(struct drm_encoder *encoder,
49 struct dip_infoframe *frame);
Eric Anholt7d573822009-01-02 13:33:00 -080050};
51
Chris Wilsonea5b2132010-08-04 13:50:23 +010052static struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
53{
Chris Wilson4ef69c72010-09-09 15:14:28 +010054 return container_of(encoder, struct intel_hdmi, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010055}
56
Chris Wilsondf0e9242010-09-09 16:20:55 +010057static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
58{
59 return container_of(intel_attached_encoder(connector),
60 struct intel_hdmi, base);
61}
62
Jesse Barnes45187ac2011-08-03 09:22:55 -070063void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020064{
Jesse Barnes45187ac2011-08-03 09:22:55 -070065 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020066 uint8_t sum = 0;
67 unsigned i;
68
Jesse Barnes45187ac2011-08-03 09:22:55 -070069 frame->checksum = 0;
70 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020071
Jesse Barnes64a8fc02011-09-22 11:16:00 +053072 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020073 sum += data[i];
74
Jesse Barnes45187ac2011-08-03 09:22:55 -070075 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020076}
77
Jesse Barnes45187ac2011-08-03 09:22:55 -070078static u32 intel_infoframe_index(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020079{
Jesse Barnes45187ac2011-08-03 09:22:55 -070080 u32 flags = 0;
81
82 switch (frame->type) {
83 case DIP_TYPE_AVI:
84 flags |= VIDEO_DIP_SELECT_AVI;
85 break;
86 case DIP_TYPE_SPD:
87 flags |= VIDEO_DIP_SELECT_SPD;
88 break;
89 default:
90 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
91 break;
92 }
93
94 return flags;
95}
96
97static u32 intel_infoframe_flags(struct dip_infoframe *frame)
98{
99 u32 flags = 0;
100
101 switch (frame->type) {
102 case DIP_TYPE_AVI:
103 flags |= VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_FREQ_VSYNC;
104 break;
105 case DIP_TYPE_SPD:
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530106 flags |= VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700107 break;
108 default:
109 DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
110 break;
111 }
112
113 return flags;
114}
115
116static void i9xx_write_infoframe(struct drm_encoder *encoder,
117 struct dip_infoframe *frame)
118{
119 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200120 struct drm_device *dev = encoder->dev;
121 struct drm_i915_private *dev_priv = dev->dev_private;
122 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700123 u32 port, flags, val = I915_READ(VIDEO_DIP_CTL);
124 unsigned i, len = DIP_HEADER_SIZE + frame->len;
David Härdeman3c17fe42010-09-24 21:44:32 +0200125
David Härdeman3c17fe42010-09-24 21:44:32 +0200126
127 /* XXX first guess at handling video port, is this corrent? */
128 if (intel_hdmi->sdvox_reg == SDVOB)
129 port = VIDEO_DIP_PORT_B;
130 else if (intel_hdmi->sdvox_reg == SDVOC)
131 port = VIDEO_DIP_PORT_C;
132 else
133 return;
134
Jesse Barnes45187ac2011-08-03 09:22:55 -0700135 flags = intel_infoframe_index(frame);
David Härdeman3c17fe42010-09-24 21:44:32 +0200136
Jesse Barnes45187ac2011-08-03 09:22:55 -0700137 val &= ~VIDEO_DIP_SELECT_MASK;
138
Paulo Zanonic1230df2012-05-02 22:55:43 -0300139 I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700140
141 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200142 I915_WRITE(VIDEO_DIP_DATA, *data);
143 data++;
144 }
145
Jesse Barnes45187ac2011-08-03 09:22:55 -0700146 flags |= intel_infoframe_flags(frame);
147
148 I915_WRITE(VIDEO_DIP_CTL, VIDEO_DIP_ENABLE | val | port | flags);
David Härdeman3c17fe42010-09-24 21:44:32 +0200149}
150
Jesse Barnes45187ac2011-08-03 09:22:55 -0700151static void ironlake_write_infoframe(struct drm_encoder *encoder,
152 struct dip_infoframe *frame)
153{
154 uint32_t *data = (uint32_t *)frame;
155 struct drm_device *dev = encoder->dev;
156 struct drm_i915_private *dev_priv = dev->dev_private;
157 struct drm_crtc *crtc = encoder->crtc;
158 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
159 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
160 unsigned i, len = DIP_HEADER_SIZE + frame->len;
161 u32 flags, val = I915_READ(reg);
162
163 intel_wait_for_vblank(dev, intel_crtc->pipe);
164
165 flags = intel_infoframe_index(frame);
166
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530167 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Jesse Barnes45187ac2011-08-03 09:22:55 -0700168
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530169 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700170
171 for (i = 0; i < len; i += 4) {
172 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
173 data++;
174 }
175
176 flags |= intel_infoframe_flags(frame);
177
178 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
179}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700180
181static void vlv_write_infoframe(struct drm_encoder *encoder,
182 struct dip_infoframe *frame)
183{
184 uint32_t *data = (uint32_t *)frame;
185 struct drm_device *dev = encoder->dev;
186 struct drm_i915_private *dev_priv = dev->dev_private;
187 struct drm_crtc *crtc = encoder->crtc;
188 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
189 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
190 unsigned i, len = DIP_HEADER_SIZE + frame->len;
191 u32 flags, val = I915_READ(reg);
192
193 intel_wait_for_vblank(dev, intel_crtc->pipe);
194
195 flags = intel_infoframe_index(frame);
196
197 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
198
199 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
200
201 for (i = 0; i < len; i += 4) {
202 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
203 data++;
204 }
205
206 flags |= intel_infoframe_flags(frame);
207
208 I915_WRITE(reg, VIDEO_DIP_ENABLE | val | flags);
209}
210
Jesse Barnes45187ac2011-08-03 09:22:55 -0700211static void intel_set_infoframe(struct drm_encoder *encoder,
212 struct dip_infoframe *frame)
213{
214 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
215
216 if (!intel_hdmi->has_hdmi_sink)
217 return;
218
219 intel_dip_infoframe_csum(frame);
220 intel_hdmi->write_infoframe(encoder, frame);
221}
222
Paulo Zanonic846b612012-04-13 16:31:41 -0300223static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
224 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700225{
226 struct dip_infoframe avi_if = {
227 .type = DIP_TYPE_AVI,
228 .ver = DIP_VERSION_AVI,
229 .len = DIP_LEN_AVI,
230 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700231
Paulo Zanonic846b612012-04-13 16:31:41 -0300232 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
233 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
234
Jesse Barnes45187ac2011-08-03 09:22:55 -0700235 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700236}
237
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700238static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
239{
240 struct dip_infoframe spd_if;
241
242 memset(&spd_if, 0, sizeof(spd_if));
243 spd_if.type = DIP_TYPE_SPD;
244 spd_if.ver = DIP_VERSION_SPD;
245 spd_if.len = DIP_LEN_SPD;
246 strcpy(spd_if.body.spd.vn, "Intel");
247 strcpy(spd_if.body.spd.pd, "Integrated gfx");
248 spd_if.body.spd.sdi = DIP_SPD_PC;
249
250 intel_set_infoframe(encoder, &spd_if);
251}
252
Eric Anholt7d573822009-01-02 13:33:00 -0800253static void intel_hdmi_mode_set(struct drm_encoder *encoder,
254 struct drm_display_mode *mode,
255 struct drm_display_mode *adjusted_mode)
256{
257 struct drm_device *dev = encoder->dev;
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 struct drm_crtc *crtc = encoder->crtc;
260 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100261 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800262 u32 sdvox;
263
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400264 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700265 if (!HAS_PCH_SPLIT(dev))
266 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400267 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
268 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
269 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
270 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800271
Jesse Barnes020f6702011-06-24 12:19:25 -0700272 if (intel_crtc->bpp > 24)
273 sdvox |= COLOR_FORMAT_12bpc;
274 else
275 sdvox |= COLOR_FORMAT_8bpc;
276
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800277 /* Required on CPT */
278 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
279 sdvox |= HDMI_MODE_SELECT;
280
David Härdeman3c17fe42010-09-24 21:44:32 +0200281 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800282 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
283 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800284 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200285 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800286 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200287 }
Eric Anholt7d573822009-01-02 13:33:00 -0800288
Jesse Barnes75770562011-10-12 09:01:58 -0700289 if (HAS_PCH_CPT(dev))
290 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
291 else if (intel_crtc->pipe == 1)
292 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800293
Chris Wilsonea5b2132010-08-04 13:50:23 +0100294 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
295 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200296
Paulo Zanonic846b612012-04-13 16:31:41 -0300297 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700298 intel_hdmi_set_spd_infoframe(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800299}
300
301static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
302{
303 struct drm_device *dev = encoder->dev;
304 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100305 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800306 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800307 u32 enable_bits = SDVO_ENABLE;
308
309 if (intel_hdmi->has_audio)
310 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800311
Chris Wilsonea5b2132010-08-04 13:50:23 +0100312 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000313
314 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
315 * we do this anyway which shows more stable in testing.
316 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800317 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100318 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
319 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800320 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000321
322 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800323 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000324 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800325 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000326 }
327
Chris Wilsonea5b2132010-08-04 13:50:23 +0100328 I915_WRITE(intel_hdmi->sdvox_reg, temp);
329 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000330
331 /* HW workaround, need to write this twice for issue that may result
332 * in first write getting masked.
333 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800334 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100335 I915_WRITE(intel_hdmi->sdvox_reg, temp);
336 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000337 }
Eric Anholt7d573822009-01-02 13:33:00 -0800338}
339
Eric Anholt7d573822009-01-02 13:33:00 -0800340static int intel_hdmi_mode_valid(struct drm_connector *connector,
341 struct drm_display_mode *mode)
342{
343 if (mode->clock > 165000)
344 return MODE_CLOCK_HIGH;
345 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200346 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800347
348 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
349 return MODE_NO_DBLESCAN;
350
351 return MODE_OK;
352}
353
354static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
355 struct drm_display_mode *mode,
356 struct drm_display_mode *adjusted_mode)
357{
358 return true;
359}
360
Keith Packardaa93d632009-05-05 09:52:46 -0700361static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100362intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800363{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100364 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700365 struct drm_i915_private *dev_priv = connector->dev->dev_private;
366 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700367 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800368
Chris Wilsonea5b2132010-08-04 13:50:23 +0100369 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800370 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700371 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800372 intel_gmbus_get_adapter(dev_priv,
373 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800374
Keith Packardaa93d632009-05-05 09:52:46 -0700375 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700376 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700377 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800378 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
379 intel_hdmi->has_hdmi_sink =
380 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800381 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700382 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800383 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700384 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800385 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800386
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100387 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800388 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
389 intel_hdmi->has_audio =
390 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100391 }
392
Keith Packardaa93d632009-05-05 09:52:46 -0700393 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800394}
395
Eric Anholt7d573822009-01-02 13:33:00 -0800396static int intel_hdmi_get_modes(struct drm_connector *connector)
397{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100398 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700399 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800400
401 /* We should parse the EDID data and find out if it's an HDMI sink so
402 * we can send audio to it.
403 */
404
Chris Wilsonf899fc62010-07-20 15:44:45 -0700405 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800406 intel_gmbus_get_adapter(dev_priv,
407 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800408}
409
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000410static bool
411intel_hdmi_detect_audio(struct drm_connector *connector)
412{
413 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
414 struct drm_i915_private *dev_priv = connector->dev->dev_private;
415 struct edid *edid;
416 bool has_audio = false;
417
418 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800419 intel_gmbus_get_adapter(dev_priv,
420 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000421 if (edid) {
422 if (edid->input & DRM_EDID_INPUT_DIGITAL)
423 has_audio = drm_detect_monitor_audio(edid);
424
425 connector->display_info.raw_edid = NULL;
426 kfree(edid);
427 }
428
429 return has_audio;
430}
431
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100432static int
433intel_hdmi_set_property(struct drm_connector *connector,
434 struct drm_property *property,
435 uint64_t val)
436{
437 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000438 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100439 int ret;
440
441 ret = drm_connector_property_set_value(connector, property, val);
442 if (ret)
443 return ret;
444
Chris Wilson3f43c482011-05-12 22:17:24 +0100445 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800446 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000447 bool has_audio;
448
449 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100450 return 0;
451
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000452 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100453
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800454 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000455 has_audio = intel_hdmi_detect_audio(connector);
456 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800457 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000458
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800459 if (i == HDMI_AUDIO_OFF_DVI)
460 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100461
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000462 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100463 goto done;
464 }
465
Chris Wilsone953fd72011-02-21 22:23:52 +0000466 if (property == dev_priv->broadcast_rgb_property) {
467 if (val == !!intel_hdmi->color_range)
468 return 0;
469
470 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
471 goto done;
472 }
473
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100474 return -EINVAL;
475
476done:
477 if (intel_hdmi->base.base.crtc) {
478 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
479 drm_crtc_helper_set_mode(crtc, &crtc->mode,
480 crtc->x, crtc->y,
481 crtc->fb);
482 }
483
484 return 0;
485}
486
Eric Anholt7d573822009-01-02 13:33:00 -0800487static void intel_hdmi_destroy(struct drm_connector *connector)
488{
Eric Anholt7d573822009-01-02 13:33:00 -0800489 drm_sysfs_connector_remove(connector);
490 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800491 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800492}
493
494static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
495 .dpms = intel_hdmi_dpms,
496 .mode_fixup = intel_hdmi_mode_fixup,
497 .prepare = intel_encoder_prepare,
498 .mode_set = intel_hdmi_mode_set,
499 .commit = intel_encoder_commit,
500};
501
502static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700503 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800504 .detect = intel_hdmi_detect,
505 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100506 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800507 .destroy = intel_hdmi_destroy,
508};
509
510static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
511 .get_modes = intel_hdmi_get_modes,
512 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100513 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800514};
515
Eric Anholt7d573822009-01-02 13:33:00 -0800516static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100517 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800518};
519
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100520static void
521intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
522{
Chris Wilson3f43c482011-05-12 22:17:24 +0100523 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000524 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100525}
526
Eric Anholt7d573822009-01-02 13:33:00 -0800527void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
528{
529 struct drm_i915_private *dev_priv = dev->dev_private;
530 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700531 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800532 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100533 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530534 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800535
Chris Wilsonea5b2132010-08-04 13:50:23 +0100536 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
537 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800538 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800539
540 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
541 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100542 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800543 return;
544 }
545
Chris Wilsonea5b2132010-08-04 13:50:23 +0100546 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100547 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
548 DRM_MODE_ENCODER_TMDS);
549
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800550 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800551 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400552 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800553 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
554
Eric Anholt21d40d32010-03-25 11:11:14 -0700555 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800556
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000557 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100558 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800559 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700560 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800561
562 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800563 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700564 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700565 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800566 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800567 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700568 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700569 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800570 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800571 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700572 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700573 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800574 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800575 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700576 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700577 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800578 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800579 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700580 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700581 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800582 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800583 }
Eric Anholt7d573822009-01-02 13:33:00 -0800584
Chris Wilsonea5b2132010-08-04 13:50:23 +0100585 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800586
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530587 if (!HAS_PCH_SPLIT(dev)) {
Jesse Barnes45187ac2011-08-03 09:22:55 -0700588 intel_hdmi->write_infoframe = i9xx_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530589 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700590 } else if (IS_VALLEYVIEW(dev)) {
591 intel_hdmi->write_infoframe = vlv_write_infoframe;
592 for_each_pipe(i)
593 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
594 } else {
Jesse Barnes45187ac2011-08-03 09:22:55 -0700595 intel_hdmi->write_infoframe = ironlake_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530596 for_each_pipe(i)
597 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
598 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700599
Chris Wilson4ef69c72010-09-09 15:14:28 +0100600 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800601
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100602 intel_hdmi_add_properties(intel_hdmi, connector);
603
Chris Wilsondf0e9242010-09-09 16:20:55 +0100604 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800605 drm_sysfs_connector_add(connector);
606
607 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
608 * 0xd. Failure to do so will result in spurious interrupts being
609 * generated on the port when a cable is not attached.
610 */
611 if (IS_G4X(dev) && !IS_GM45(dev)) {
612 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
613 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
614 }
Eric Anholt7d573822009-01-02 13:33:00 -0800615}