blob: 952eaf777ac5fa747d62a9b44e699ee3103487a7 [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);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300123 u32 val = I915_READ(VIDEO_DIP_CTL);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700124 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? */
Paulo Zanoni3e6e6392012-05-04 17:18:19 -0300128 val &= ~VIDEO_DIP_PORT_MASK;
David Härdeman3c17fe42010-09-24 21:44:32 +0200129 if (intel_hdmi->sdvox_reg == SDVOB)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300130 val |= VIDEO_DIP_PORT_B;
David Härdeman3c17fe42010-09-24 21:44:32 +0200131 else if (intel_hdmi->sdvox_reg == SDVOC)
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300132 val |= VIDEO_DIP_PORT_C;
David Härdeman3c17fe42010-09-24 21:44:32 +0200133 else
134 return;
135
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300136 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300137 val |= intel_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700138
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300139 val |= VIDEO_DIP_ENABLE;
140
141 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700142
143 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200144 I915_WRITE(VIDEO_DIP_DATA, *data);
145 data++;
146 }
147
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300148 val |= intel_infoframe_flags(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700149
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300150 I915_WRITE(VIDEO_DIP_CTL, val);
David Härdeman3c17fe42010-09-24 21:44:32 +0200151}
152
Jesse Barnes45187ac2011-08-03 09:22:55 -0700153static void ironlake_write_infoframe(struct drm_encoder *encoder,
154 struct dip_infoframe *frame)
155{
156 uint32_t *data = (uint32_t *)frame;
157 struct drm_device *dev = encoder->dev;
158 struct drm_i915_private *dev_priv = dev->dev_private;
159 struct drm_crtc *crtc = encoder->crtc;
160 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
161 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
162 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300163 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700164
165 intel_wait_for_vblank(dev, intel_crtc->pipe);
166
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530167 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300168 val |= intel_infoframe_index(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700169
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300170 val |= VIDEO_DIP_ENABLE;
171
172 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700173
174 for (i = 0; i < len; i += 4) {
175 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
176 data++;
177 }
178
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300179 val |= intel_infoframe_flags(frame);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700180
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300181 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700182}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700183
184static void vlv_write_infoframe(struct drm_encoder *encoder,
185 struct dip_infoframe *frame)
186{
187 uint32_t *data = (uint32_t *)frame;
188 struct drm_device *dev = encoder->dev;
189 struct drm_i915_private *dev_priv = dev->dev_private;
190 struct drm_crtc *crtc = encoder->crtc;
191 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
192 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
193 unsigned i, len = DIP_HEADER_SIZE + frame->len;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300194 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700195
196 intel_wait_for_vblank(dev, intel_crtc->pipe);
197
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700198 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300199 val |= intel_infoframe_index(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700200
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300201 val |= VIDEO_DIP_ENABLE;
202
203 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700204
205 for (i = 0; i < len; i += 4) {
206 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
207 data++;
208 }
209
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300210 val |= intel_infoframe_flags(frame);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700211
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300212 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700213}
214
Jesse Barnes45187ac2011-08-03 09:22:55 -0700215static void intel_set_infoframe(struct drm_encoder *encoder,
216 struct dip_infoframe *frame)
217{
218 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
219
220 if (!intel_hdmi->has_hdmi_sink)
221 return;
222
223 intel_dip_infoframe_csum(frame);
224 intel_hdmi->write_infoframe(encoder, frame);
225}
226
Paulo Zanonic846b612012-04-13 16:31:41 -0300227static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
228 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700229{
230 struct dip_infoframe avi_if = {
231 .type = DIP_TYPE_AVI,
232 .ver = DIP_VERSION_AVI,
233 .len = DIP_LEN_AVI,
234 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700235
Paulo Zanonic846b612012-04-13 16:31:41 -0300236 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
237 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
238
Jesse Barnes45187ac2011-08-03 09:22:55 -0700239 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700240}
241
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700242static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
243{
244 struct dip_infoframe spd_if;
245
246 memset(&spd_if, 0, sizeof(spd_if));
247 spd_if.type = DIP_TYPE_SPD;
248 spd_if.ver = DIP_VERSION_SPD;
249 spd_if.len = DIP_LEN_SPD;
250 strcpy(spd_if.body.spd.vn, "Intel");
251 strcpy(spd_if.body.spd.pd, "Integrated gfx");
252 spd_if.body.spd.sdi = DIP_SPD_PC;
253
254 intel_set_infoframe(encoder, &spd_if);
255}
256
Eric Anholt7d573822009-01-02 13:33:00 -0800257static void intel_hdmi_mode_set(struct drm_encoder *encoder,
258 struct drm_display_mode *mode,
259 struct drm_display_mode *adjusted_mode)
260{
261 struct drm_device *dev = encoder->dev;
262 struct drm_i915_private *dev_priv = dev->dev_private;
263 struct drm_crtc *crtc = encoder->crtc;
264 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100265 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800266 u32 sdvox;
267
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400268 sdvox = SDVO_ENCODING_HDMI | SDVO_BORDER_ENABLE;
Jesse Barnes5d4fac92011-06-24 12:19:19 -0700269 if (!HAS_PCH_SPLIT(dev))
270 sdvox |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400271 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
272 sdvox |= SDVO_VSYNC_ACTIVE_HIGH;
273 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
274 sdvox |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800275
Jesse Barnes020f6702011-06-24 12:19:25 -0700276 if (intel_crtc->bpp > 24)
277 sdvox |= COLOR_FORMAT_12bpc;
278 else
279 sdvox |= COLOR_FORMAT_8bpc;
280
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800281 /* Required on CPT */
282 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
283 sdvox |= HDMI_MODE_SELECT;
284
David Härdeman3c17fe42010-09-24 21:44:32 +0200285 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800286 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
287 pipe_name(intel_crtc->pipe));
Eric Anholt7d573822009-01-02 13:33:00 -0800288 sdvox |= SDVO_AUDIO_ENABLE;
David Härdeman3c17fe42010-09-24 21:44:32 +0200289 sdvox |= SDVO_NULL_PACKETS_DURING_VSYNC;
Wu Fengguange0dac652011-09-05 14:25:34 +0800290 intel_write_eld(encoder, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200291 }
Eric Anholt7d573822009-01-02 13:33:00 -0800292
Jesse Barnes75770562011-10-12 09:01:58 -0700293 if (HAS_PCH_CPT(dev))
294 sdvox |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
295 else if (intel_crtc->pipe == 1)
296 sdvox |= SDVO_PIPE_B_SELECT;
Eric Anholt7d573822009-01-02 13:33:00 -0800297
Chris Wilsonea5b2132010-08-04 13:50:23 +0100298 I915_WRITE(intel_hdmi->sdvox_reg, sdvox);
299 POSTING_READ(intel_hdmi->sdvox_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200300
Paulo Zanonic846b612012-04-13 16:31:41 -0300301 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700302 intel_hdmi_set_spd_infoframe(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800303}
304
305static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode)
306{
307 struct drm_device *dev = encoder->dev;
308 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100309 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800310 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800311 u32 enable_bits = SDVO_ENABLE;
312
313 if (intel_hdmi->has_audio)
314 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800315
Chris Wilsonea5b2132010-08-04 13:50:23 +0100316 temp = I915_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000317
318 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
319 * we do this anyway which shows more stable in testing.
320 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800321 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100322 I915_WRITE(intel_hdmi->sdvox_reg, temp & ~SDVO_ENABLE);
323 POSTING_READ(intel_hdmi->sdvox_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800324 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000325
326 if (mode != DRM_MODE_DPMS_ON) {
Wu Fengguang2deed762011-12-09 20:42:20 +0800327 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000328 } else {
Wu Fengguang2deed762011-12-09 20:42:20 +0800329 temp |= enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000330 }
331
Chris Wilsonea5b2132010-08-04 13:50:23 +0100332 I915_WRITE(intel_hdmi->sdvox_reg, temp);
333 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000334
335 /* HW workaround, need to write this twice for issue that may result
336 * in first write getting masked.
337 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800338 if (HAS_PCH_SPLIT(dev)) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100339 I915_WRITE(intel_hdmi->sdvox_reg, temp);
340 POSTING_READ(intel_hdmi->sdvox_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000341 }
Eric Anholt7d573822009-01-02 13:33:00 -0800342}
343
Eric Anholt7d573822009-01-02 13:33:00 -0800344static int intel_hdmi_mode_valid(struct drm_connector *connector,
345 struct drm_display_mode *mode)
346{
347 if (mode->clock > 165000)
348 return MODE_CLOCK_HIGH;
349 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200350 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800351
352 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
353 return MODE_NO_DBLESCAN;
354
355 return MODE_OK;
356}
357
358static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
359 struct drm_display_mode *mode,
360 struct drm_display_mode *adjusted_mode)
361{
362 return true;
363}
364
Keith Packardaa93d632009-05-05 09:52:46 -0700365static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100366intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800367{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100368 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700369 struct drm_i915_private *dev_priv = connector->dev->dev_private;
370 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700371 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800372
Chris Wilsonea5b2132010-08-04 13:50:23 +0100373 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800374 intel_hdmi->has_audio = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700375 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800376 intel_gmbus_get_adapter(dev_priv,
377 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800378
Keith Packardaa93d632009-05-05 09:52:46 -0700379 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700380 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700381 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800382 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
383 intel_hdmi->has_hdmi_sink =
384 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800385 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700386 }
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800387 connector->display_info.raw_edid = NULL;
Keith Packardaa93d632009-05-05 09:52:46 -0700388 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800389 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800390
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100391 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800392 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
393 intel_hdmi->has_audio =
394 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100395 }
396
Keith Packardaa93d632009-05-05 09:52:46 -0700397 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800398}
399
Eric Anholt7d573822009-01-02 13:33:00 -0800400static int intel_hdmi_get_modes(struct drm_connector *connector)
401{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100402 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700403 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800404
405 /* We should parse the EDID data and find out if it's an HDMI sink so
406 * we can send audio to it.
407 */
408
Chris Wilsonf899fc62010-07-20 15:44:45 -0700409 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800410 intel_gmbus_get_adapter(dev_priv,
411 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800412}
413
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000414static bool
415intel_hdmi_detect_audio(struct drm_connector *connector)
416{
417 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
418 struct drm_i915_private *dev_priv = connector->dev->dev_private;
419 struct edid *edid;
420 bool has_audio = false;
421
422 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800423 intel_gmbus_get_adapter(dev_priv,
424 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000425 if (edid) {
426 if (edid->input & DRM_EDID_INPUT_DIGITAL)
427 has_audio = drm_detect_monitor_audio(edid);
428
429 connector->display_info.raw_edid = NULL;
430 kfree(edid);
431 }
432
433 return has_audio;
434}
435
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100436static int
437intel_hdmi_set_property(struct drm_connector *connector,
438 struct drm_property *property,
439 uint64_t val)
440{
441 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000442 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100443 int ret;
444
445 ret = drm_connector_property_set_value(connector, property, val);
446 if (ret)
447 return ret;
448
Chris Wilson3f43c482011-05-12 22:17:24 +0100449 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800450 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000451 bool has_audio;
452
453 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100454 return 0;
455
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000456 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100457
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800458 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000459 has_audio = intel_hdmi_detect_audio(connector);
460 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800461 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000462
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800463 if (i == HDMI_AUDIO_OFF_DVI)
464 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100465
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000466 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100467 goto done;
468 }
469
Chris Wilsone953fd72011-02-21 22:23:52 +0000470 if (property == dev_priv->broadcast_rgb_property) {
471 if (val == !!intel_hdmi->color_range)
472 return 0;
473
474 intel_hdmi->color_range = val ? SDVO_COLOR_RANGE_16_235 : 0;
475 goto done;
476 }
477
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100478 return -EINVAL;
479
480done:
481 if (intel_hdmi->base.base.crtc) {
482 struct drm_crtc *crtc = intel_hdmi->base.base.crtc;
483 drm_crtc_helper_set_mode(crtc, &crtc->mode,
484 crtc->x, crtc->y,
485 crtc->fb);
486 }
487
488 return 0;
489}
490
Eric Anholt7d573822009-01-02 13:33:00 -0800491static void intel_hdmi_destroy(struct drm_connector *connector)
492{
Eric Anholt7d573822009-01-02 13:33:00 -0800493 drm_sysfs_connector_remove(connector);
494 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800495 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -0800496}
497
498static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
499 .dpms = intel_hdmi_dpms,
500 .mode_fixup = intel_hdmi_mode_fixup,
501 .prepare = intel_encoder_prepare,
502 .mode_set = intel_hdmi_mode_set,
503 .commit = intel_encoder_commit,
504};
505
506static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700507 .dpms = drm_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -0800508 .detect = intel_hdmi_detect,
509 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100510 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -0800511 .destroy = intel_hdmi_destroy,
512};
513
514static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
515 .get_modes = intel_hdmi_get_modes,
516 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100517 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -0800518};
519
Eric Anholt7d573822009-01-02 13:33:00 -0800520static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100521 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -0800522};
523
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100524static void
525intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
526{
Chris Wilson3f43c482011-05-12 22:17:24 +0100527 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +0000528 intel_attach_broadcast_rgb_property(connector);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100529}
530
Eric Anholt7d573822009-01-02 13:33:00 -0800531void intel_hdmi_init(struct drm_device *dev, int sdvox_reg)
532{
533 struct drm_i915_private *dev_priv = dev->dev_private;
534 struct drm_connector *connector;
Eric Anholt21d40d32010-03-25 11:11:14 -0700535 struct intel_encoder *intel_encoder;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800536 struct intel_connector *intel_connector;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100537 struct intel_hdmi *intel_hdmi;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530538 int i;
Eric Anholt7d573822009-01-02 13:33:00 -0800539
Chris Wilsonea5b2132010-08-04 13:50:23 +0100540 intel_hdmi = kzalloc(sizeof(struct intel_hdmi), GFP_KERNEL);
541 if (!intel_hdmi)
Eric Anholt7d573822009-01-02 13:33:00 -0800542 return;
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800543
544 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
545 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100546 kfree(intel_hdmi);
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800547 return;
548 }
549
Chris Wilsonea5b2132010-08-04 13:50:23 +0100550 intel_encoder = &intel_hdmi->base;
Chris Wilson373a3cf2010-09-15 12:03:59 +0100551 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
552 DRM_MODE_ENCODER_TMDS);
553
Zhenyu Wang674e2d02010-03-29 15:57:42 +0800554 connector = &intel_connector->base;
Eric Anholt7d573822009-01-02 13:33:00 -0800555 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -0400556 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -0800557 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
558
Eric Anholt21d40d32010-03-25 11:11:14 -0700559 intel_encoder->type = INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -0800560
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000561 connector->polled = DRM_CONNECTOR_POLL_HPD;
Peter Rossc3febcc2012-01-28 14:49:26 +0100562 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -0800563 connector->doublescan_allowed = 0;
Jesse Barnes27f82272011-09-02 12:54:37 -0700564 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Eric Anholt7d573822009-01-02 13:33:00 -0800565
566 /* Set up the DDC bus. */
Ma Lingf8aed702009-08-24 13:50:24 +0800567 if (sdvox_reg == SDVOB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700568 intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700569 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800570 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800571 } else if (sdvox_reg == SDVOC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700572 intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700573 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800574 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800575 } else if (sdvox_reg == HDMIB) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700576 intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700577 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800578 dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800579 } else if (sdvox_reg == HDMIC) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700580 intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700581 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800582 dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800583 } else if (sdvox_reg == HDMID) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700584 intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700585 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Jesse Barnesb01f2c32009-12-11 11:07:17 -0800586 dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS;
Ma Lingf8aed702009-08-24 13:50:24 +0800587 }
Eric Anholt7d573822009-01-02 13:33:00 -0800588
Chris Wilsonea5b2132010-08-04 13:50:23 +0100589 intel_hdmi->sdvox_reg = sdvox_reg;
Eric Anholt7d573822009-01-02 13:33:00 -0800590
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530591 if (!HAS_PCH_SPLIT(dev)) {
Jesse Barnes45187ac2011-08-03 09:22:55 -0700592 intel_hdmi->write_infoframe = i9xx_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530593 I915_WRITE(VIDEO_DIP_CTL, 0);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700594 } else if (IS_VALLEYVIEW(dev)) {
595 intel_hdmi->write_infoframe = vlv_write_infoframe;
596 for_each_pipe(i)
597 I915_WRITE(VLV_TVIDEO_DIP_CTL(i), 0);
598 } else {
Jesse Barnes45187ac2011-08-03 09:22:55 -0700599 intel_hdmi->write_infoframe = ironlake_write_infoframe;
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530600 for_each_pipe(i)
601 I915_WRITE(TVIDEO_DIP_CTL(i), 0);
602 }
Jesse Barnes45187ac2011-08-03 09:22:55 -0700603
Chris Wilson4ef69c72010-09-09 15:14:28 +0100604 drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
Eric Anholt7d573822009-01-02 13:33:00 -0800605
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100606 intel_hdmi_add_properties(intel_hdmi, connector);
607
Chris Wilsondf0e9242010-09-09 16:20:55 +0100608 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt7d573822009-01-02 13:33:00 -0800609 drm_sysfs_connector_add(connector);
610
611 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
612 * 0xd. Failure to do so will result in spurious interrupts being
613 * generated on the port when a cable is not attached.
614 */
615 if (IS_G4X(dev) && !IS_GM45(dev)) {
616 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
617 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
618 }
Eric Anholt7d573822009-01-02 13:33:00 -0800619}