blob: 51a8336dec2e0d40452f178704b6c3d753ff1f6b [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>
Damien Lespiau178f7362013-08-06 20:32:18 +010032#include <linux/hdmi.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
34#include <drm/drm_crtc.h>
35#include <drm/drm_edid.h>
Eric Anholt7d573822009-01-02 13:33:00 -080036#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Eric Anholt7d573822009-01-02 13:33:00 -080038#include "i915_drv.h"
39
Paulo Zanoni30add222012-10-26 19:05:45 -020040static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
41{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020042 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020043}
44
Daniel Vetterafba0182012-06-12 16:36:45 +020045static void
46assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
47{
Paulo Zanoni30add222012-10-26 19:05:45 -020048 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Daniel Vetterafba0182012-06-12 16:36:45 +020049 struct drm_i915_private *dev_priv = dev->dev_private;
50 uint32_t enabled_bits;
51
Paulo Zanoniaffa9352012-11-23 15:30:39 -020052 enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020053
Paulo Zanonib242b7f2013-02-18 19:00:26 -030054 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020055 "HDMI port enabled, expecting disabled\n");
56}
57
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030058struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010059{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020060 struct intel_digital_port *intel_dig_port =
61 container_of(encoder, struct intel_digital_port, base.base);
62 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010063}
64
Chris Wilsondf0e9242010-09-09 16:20:55 +010065static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
66{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020067 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010068}
69
Damien Lespiau178f7362013-08-06 20:32:18 +010070static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020071{
Damien Lespiau178f7362013-08-06 20:32:18 +010072 switch (type) {
73 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030074 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010075 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030076 return VIDEO_DIP_SELECT_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010077 case HDMI_INFOFRAME_TYPE_VENDOR:
78 return VIDEO_DIP_SELECT_VENDOR;
Jesse Barnes45187ac2011-08-03 09:22:55 -070079 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010080 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030081 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070082 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070083}
84
Damien Lespiau178f7362013-08-06 20:32:18 +010085static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070086{
Damien Lespiau178f7362013-08-06 20:32:18 +010087 switch (type) {
88 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030089 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010090 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030091 return VIDEO_DIP_ENABLE_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010092 case HDMI_INFOFRAME_TYPE_VENDOR:
93 return VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030094 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010095 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030096 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030097 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030098}
99
Damien Lespiau178f7362013-08-06 20:32:18 +0100100static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300101{
Damien Lespiau178f7362013-08-06 20:32:18 +0100102 switch (type) {
103 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300104 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100105 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300106 return VIDEO_DIP_ENABLE_SPD_HSW;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100107 case HDMI_INFOFRAME_TYPE_VENDOR:
108 return VIDEO_DIP_ENABLE_VS_HSW;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300109 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100110 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300111 return 0;
112 }
113}
114
Damien Lespiau178f7362013-08-06 20:32:18 +0100115static u32 hsw_infoframe_data_reg(enum hdmi_infoframe_type type,
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300116 enum transcoder cpu_transcoder)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300117{
Damien Lespiau178f7362013-08-06 20:32:18 +0100118 switch (type) {
119 case HDMI_INFOFRAME_TYPE_AVI:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300120 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100121 case HDMI_INFOFRAME_TYPE_SPD:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300122 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100123 case HDMI_INFOFRAME_TYPE_VENDOR:
124 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300125 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100126 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300127 return 0;
128 }
129}
130
Daniel Vettera3da1df2012-05-08 15:19:06 +0200131static void g4x_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100132 enum hdmi_infoframe_type type,
133 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700134{
135 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200136 struct drm_device *dev = encoder->dev;
137 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300138 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100139 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200140
Paulo Zanoni822974a2012-05-28 16:42:51 -0300141 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
142
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300143 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100144 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700145
Damien Lespiau178f7362013-08-06 20:32:18 +0100146 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300147
148 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700149
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300150 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700151 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200152 I915_WRITE(VIDEO_DIP_DATA, *data);
153 data++;
154 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300155 /* Write every possible data byte to force correct ECC calculation. */
156 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
157 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300158 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200159
Damien Lespiau178f7362013-08-06 20:32:18 +0100160 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300161 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200162 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700163
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300164 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300165 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200166}
167
Paulo Zanonifdf12502012-05-04 17:18:24 -0300168static void ibx_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100169 enum hdmi_infoframe_type type,
170 const uint8_t *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300171{
172 uint32_t *data = (uint32_t *)frame;
173 struct drm_device *dev = encoder->dev;
174 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300175 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100176 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300177 u32 val = I915_READ(reg);
178
Paulo Zanoni822974a2012-05-28 16:42:51 -0300179 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
180
Paulo Zanonifdf12502012-05-04 17:18:24 -0300181 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100182 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300183
Damien Lespiau178f7362013-08-06 20:32:18 +0100184 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300185
186 I915_WRITE(reg, val);
187
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300188 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300189 for (i = 0; i < len; i += 4) {
190 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
191 data++;
192 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300193 /* Write every possible data byte to force correct ECC calculation. */
194 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
195 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300196 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300197
Damien Lespiau178f7362013-08-06 20:32:18 +0100198 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300199 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200200 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201
202 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300203 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300204}
205
206static void cpt_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100207 enum hdmi_infoframe_type type,
208 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700209{
210 uint32_t *data = (uint32_t *)frame;
211 struct drm_device *dev = encoder->dev;
212 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300213 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100214 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300215 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700216
Paulo Zanoni822974a2012-05-28 16:42:51 -0300217 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
218
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530219 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100220 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700221
Paulo Zanoniecb97852012-05-04 17:18:21 -0300222 /* The DIP control register spec says that we need to update the AVI
223 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100224 if (type != HDMI_INFOFRAME_TYPE_AVI)
225 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300226
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300227 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700228
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300229 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700230 for (i = 0; i < len; i += 4) {
231 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
232 data++;
233 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300234 /* Write every possible data byte to force correct ECC calculation. */
235 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
236 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300237 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700238
Damien Lespiau178f7362013-08-06 20:32:18 +0100239 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300240 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200241 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700242
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300243 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300244 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700245}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700246
247static void vlv_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100248 enum hdmi_infoframe_type type,
249 const uint8_t *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700250{
251 uint32_t *data = (uint32_t *)frame;
252 struct drm_device *dev = encoder->dev;
253 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300254 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100255 int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300256 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700257
Paulo Zanoni822974a2012-05-28 16:42:51 -0300258 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
259
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700260 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100261 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700262
Damien Lespiau178f7362013-08-06 20:32:18 +0100263 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300264
265 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700266
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300267 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700268 for (i = 0; i < len; i += 4) {
269 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
270 data++;
271 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300272 /* Write every possible data byte to force correct ECC calculation. */
273 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
274 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300275 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700276
Damien Lespiau178f7362013-08-06 20:32:18 +0100277 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300278 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200279 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700280
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300281 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300282 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700283}
284
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300285static void hsw_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100286 enum hdmi_infoframe_type type,
287 const uint8_t *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300288{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300289 uint32_t *data = (uint32_t *)frame;
290 struct drm_device *dev = encoder->dev;
291 struct drm_i915_private *dev_priv = dev->dev_private;
292 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200293 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100294 u32 data_reg;
295 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300296 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300297
Damien Lespiau178f7362013-08-06 20:32:18 +0100298 data_reg = hsw_infoframe_data_reg(type,
299 intel_crtc->config.cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300300 if (data_reg == 0)
301 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300302
Damien Lespiau178f7362013-08-06 20:32:18 +0100303 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300304 I915_WRITE(ctl_reg, val);
305
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300306 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300307 for (i = 0; i < len; i += 4) {
308 I915_WRITE(data_reg + i, *data);
309 data++;
310 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300311 /* Write every possible data byte to force correct ECC calculation. */
312 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
313 I915_WRITE(data_reg + i, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300314 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300315
Damien Lespiau178f7362013-08-06 20:32:18 +0100316 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300317 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300318 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300319}
320
Damien Lespiau5adaea72013-08-06 20:32:19 +0100321/*
322 * The data we write to the DIP data buffer registers is 1 byte bigger than the
323 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
324 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
325 * used for both technologies.
326 *
327 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
328 * DW1: DB3 | DB2 | DB1 | DB0
329 * DW2: DB7 | DB6 | DB5 | DB4
330 * DW3: ...
331 *
332 * (HB is Header Byte, DB is Data Byte)
333 *
334 * The hdmi pack() functions don't know about that hardware specific hole so we
335 * trick them by giving an offset into the buffer and moving back the header
336 * bytes by one.
337 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100338static void intel_write_infoframe(struct drm_encoder *encoder,
339 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700340{
341 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100342 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
343 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700344
Damien Lespiau5adaea72013-08-06 20:32:19 +0100345 /* see comment above for the reason for this offset */
346 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
347 if (len < 0)
348 return;
349
350 /* Insert the 'hole' (see big comment above) at position 3 */
351 buffer[0] = buffer[1];
352 buffer[1] = buffer[2];
353 buffer[2] = buffer[3];
354 buffer[3] = 0;
355 len++;
356
357 intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700358}
359
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300360static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300361 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700362{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200363 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter50f3b012013-03-27 00:44:56 +0100364 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100365 union hdmi_infoframe frame;
366 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700367
Damien Lespiau5adaea72013-08-06 20:32:19 +0100368 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
369 adjusted_mode);
370 if (ret < 0) {
371 DRM_ERROR("couldn't fill AVI infoframe\n");
372 return;
373 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300374
Ville Syrjäläabedc072013-01-17 16:31:31 +0200375 if (intel_hdmi->rgb_quant_range_selectable) {
Daniel Vetter50f3b012013-03-27 00:44:56 +0100376 if (intel_crtc->config.limited_color_range)
Damien Lespiau5adaea72013-08-06 20:32:19 +0100377 frame.avi.quantization_range =
378 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200379 else
Damien Lespiau5adaea72013-08-06 20:32:19 +0100380 frame.avi.quantization_range =
381 HDMI_QUANTIZATION_RANGE_FULL;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200382 }
383
Damien Lespiau9198ee52013-08-06 20:32:24 +0100384 intel_write_infoframe(encoder, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700385}
386
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300387static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700388{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100389 union hdmi_infoframe frame;
390 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700391
Damien Lespiau5adaea72013-08-06 20:32:19 +0100392 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
393 if (ret < 0) {
394 DRM_ERROR("couldn't fill SPD infoframe\n");
395 return;
396 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700397
Damien Lespiau5adaea72013-08-06 20:32:19 +0100398 frame.spd.sdi = HDMI_SPD_SDI_PC;
399
Damien Lespiau9198ee52013-08-06 20:32:24 +0100400 intel_write_infoframe(encoder, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700401}
402
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100403static void
404intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
405 struct drm_display_mode *adjusted_mode)
406{
407 union hdmi_infoframe frame;
408 int ret;
409
410 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
411 adjusted_mode);
412 if (ret < 0)
413 return;
414
415 intel_write_infoframe(encoder, &frame);
416}
417
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300418static void g4x_set_infoframes(struct drm_encoder *encoder,
419 struct drm_display_mode *adjusted_mode)
420{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300421 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200422 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
423 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300424 u32 reg = VIDEO_DIP_CTL;
425 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300426 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300427
Daniel Vetterafba0182012-06-12 16:36:45 +0200428 assert_hdmi_port_disabled(intel_hdmi);
429
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300430 /* If the registers were not initialized yet, they might be zeroes,
431 * which means we're selecting the AVI DIP and we're setting its
432 * frequency to once. This seems to really confuse the HW and make
433 * things stop working (the register spec says the AVI always needs to
434 * be sent every VSync). So here we avoid writing to the register more
435 * than we need and also explicitly select the AVI DIP and explicitly
436 * set its frequency to every VSync. Avoiding to write it twice seems to
437 * be enough to solve the problem, but being defensive shouldn't hurt us
438 * either. */
439 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
440
441 if (!intel_hdmi->has_hdmi_sink) {
442 if (!(val & VIDEO_DIP_ENABLE))
443 return;
444 val &= ~VIDEO_DIP_ENABLE;
445 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300446 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300447 return;
448 }
449
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200450 switch (intel_dig_port->port) {
451 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300452 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300453 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200454 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300455 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300456 break;
457 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300458 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300459 return;
460 }
461
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300462 if (port != (val & VIDEO_DIP_PORT_MASK)) {
463 if (val & VIDEO_DIP_ENABLE) {
464 val &= ~VIDEO_DIP_ENABLE;
465 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300466 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300467 }
468 val &= ~VIDEO_DIP_PORT_MASK;
469 val |= port;
470 }
471
Paulo Zanoni822974a2012-05-28 16:42:51 -0300472 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300473 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300474
Paulo Zanonif278d972012-05-28 16:42:50 -0300475 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300476 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300477
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300478 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
479 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100480 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300481}
482
483static void ibx_set_infoframes(struct drm_encoder *encoder,
484 struct drm_display_mode *adjusted_mode)
485{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300486 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
487 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200488 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
489 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300490 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
491 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300492 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300493
Daniel Vetterafba0182012-06-12 16:36:45 +0200494 assert_hdmi_port_disabled(intel_hdmi);
495
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300496 /* See the big comment in g4x_set_infoframes() */
497 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
498
499 if (!intel_hdmi->has_hdmi_sink) {
500 if (!(val & VIDEO_DIP_ENABLE))
501 return;
502 val &= ~VIDEO_DIP_ENABLE;
503 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300504 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300505 return;
506 }
507
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200508 switch (intel_dig_port->port) {
509 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300510 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300511 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200512 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300513 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300514 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200515 case PORT_D:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300516 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300517 break;
518 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300519 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300520 return;
521 }
522
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300523 if (port != (val & VIDEO_DIP_PORT_MASK)) {
524 if (val & VIDEO_DIP_ENABLE) {
525 val &= ~VIDEO_DIP_ENABLE;
526 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300527 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300528 }
529 val &= ~VIDEO_DIP_PORT_MASK;
530 val |= port;
531 }
532
Paulo Zanoni822974a2012-05-28 16:42:51 -0300533 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300534 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
535 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300536
Paulo Zanonif278d972012-05-28 16:42:50 -0300537 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300538 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300539
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300540 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
541 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100542 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300543}
544
545static void cpt_set_infoframes(struct drm_encoder *encoder,
546 struct drm_display_mode *adjusted_mode)
547{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300548 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
549 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
550 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
551 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
552 u32 val = I915_READ(reg);
553
Daniel Vetterafba0182012-06-12 16:36:45 +0200554 assert_hdmi_port_disabled(intel_hdmi);
555
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300556 /* See the big comment in g4x_set_infoframes() */
557 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
558
559 if (!intel_hdmi->has_hdmi_sink) {
560 if (!(val & VIDEO_DIP_ENABLE))
561 return;
562 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
563 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300564 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300565 return;
566 }
567
Paulo Zanoni822974a2012-05-28 16:42:51 -0300568 /* Set both together, unset both together: see the spec. */
569 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300570 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
571 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300572
573 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300574 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300575
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300576 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
577 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100578 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300579}
580
581static void vlv_set_infoframes(struct drm_encoder *encoder,
582 struct drm_display_mode *adjusted_mode)
583{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300584 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
585 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
586 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
587 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
588 u32 val = I915_READ(reg);
589
Daniel Vetterafba0182012-06-12 16:36:45 +0200590 assert_hdmi_port_disabled(intel_hdmi);
591
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300592 /* See the big comment in g4x_set_infoframes() */
593 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
594
595 if (!intel_hdmi->has_hdmi_sink) {
596 if (!(val & VIDEO_DIP_ENABLE))
597 return;
598 val &= ~VIDEO_DIP_ENABLE;
599 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300600 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300601 return;
602 }
603
Paulo Zanoni822974a2012-05-28 16:42:51 -0300604 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300605 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
606 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300607
608 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300609 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300610
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300611 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
612 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100613 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300614}
615
616static void hsw_set_infoframes(struct drm_encoder *encoder,
617 struct drm_display_mode *adjusted_mode)
618{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300619 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
620 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
621 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200622 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300623 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300624
Daniel Vetterafba0182012-06-12 16:36:45 +0200625 assert_hdmi_port_disabled(intel_hdmi);
626
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300627 if (!intel_hdmi->has_hdmi_sink) {
628 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300629 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300630 return;
631 }
632
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300633 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
634 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
635
636 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300637 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300638
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300639 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
640 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100641 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300642}
643
Daniel Vetterc59423a2013-07-21 21:37:04 +0200644static void intel_hdmi_mode_set(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800645{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200646 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800647 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200648 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
649 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
650 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300651 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800652
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300653 hdmi_val = SDVO_ENCODING_HDMI;
Ville Syrjälä2af2c492013-06-25 14:16:34 +0300654 if (!HAS_PCH_SPLIT(dev))
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300655 hdmi_val |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400656 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300657 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400658 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300659 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800660
Daniel Vetterc59423a2013-07-21 21:37:04 +0200661 if (crtc->config.pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300662 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700663 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300664 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700665
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800666 /* Required on CPT */
667 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300668 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800669
David Härdeman3c17fe42010-09-24 21:44:32 +0200670 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800671 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
Daniel Vetterc59423a2013-07-21 21:37:04 +0200672 pipe_name(crtc->pipe));
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300673 hdmi_val |= SDVO_AUDIO_ENABLE;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300674 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200675 intel_write_eld(&encoder->base, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200676 }
Eric Anholt7d573822009-01-02 13:33:00 -0800677
Jesse Barnes75770562011-10-12 09:01:58 -0700678 if (HAS_PCH_CPT(dev))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200679 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300680 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200681 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800682
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300683 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
684 POSTING_READ(intel_hdmi->hdmi_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200685
Daniel Vetterc59423a2013-07-21 21:37:04 +0200686 intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800687}
688
Daniel Vetter85234cd2012-07-02 13:27:29 +0200689static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
690 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800691{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200692 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800693 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200694 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
695 u32 tmp;
696
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300697 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200698
699 if (!(tmp & SDVO_ENABLE))
700 return false;
701
702 if (HAS_PCH_CPT(dev))
703 *pipe = PORT_TO_PIPE_CPT(tmp);
704 else
705 *pipe = PORT_TO_PIPE(tmp);
706
707 return true;
708}
709
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700710static void intel_hdmi_get_config(struct intel_encoder *encoder,
711 struct intel_crtc_config *pipe_config)
712{
713 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
714 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
715 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300716 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700717
718 tmp = I915_READ(intel_hdmi->hdmi_reg);
719
720 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
721 flags |= DRM_MODE_FLAG_PHSYNC;
722 else
723 flags |= DRM_MODE_FLAG_NHSYNC;
724
725 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
726 flags |= DRM_MODE_FLAG_PVSYNC;
727 else
728 flags |= DRM_MODE_FLAG_NVSYNC;
729
730 pipe_config->adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300731
732 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
733 dotclock = pipe_config->port_clock * 2 / 3;
734 else
735 dotclock = pipe_config->port_clock;
736
737 if (HAS_PCH_SPLIT(dev_priv->dev))
738 ironlake_check_encoder_dotclock(pipe_config, dotclock);
739
Damien Lespiau241bfc32013-09-25 16:45:37 +0100740 pipe_config->adjusted_mode.crtc_clock = dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700741}
742
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200743static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800744{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200745 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800746 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300747 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200748 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800749 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800750 u32 enable_bits = SDVO_ENABLE;
751
752 if (intel_hdmi->has_audio)
753 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800754
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300755 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000756
Daniel Vetter7a87c282012-06-05 11:03:39 +0200757 /* HW workaround for IBX, we need to move the port to transcoder A
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300758 * before disabling it, so restore the transcoder select bit here. */
759 if (HAS_PCH_IBX(dev))
760 enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200761
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200762 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
763 * we do this anyway which shows more stable in testing.
764 */
765 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300766 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
767 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200768 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200769
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200770 temp |= enable_bits;
771
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300772 I915_WRITE(intel_hdmi->hdmi_reg, temp);
773 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200774
775 /* HW workaround, need to write this twice for issue that may result
776 * in first write getting masked.
777 */
778 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300779 I915_WRITE(intel_hdmi->hdmi_reg, temp);
780 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200781 }
Jani Nikulab76cf762013-07-30 12:20:31 +0300782}
Jesse Barnes89b667f2013-04-18 14:51:36 -0700783
Jani Nikulab76cf762013-07-30 12:20:31 +0300784static void vlv_enable_hdmi(struct intel_encoder *encoder)
785{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200786}
787
788static void intel_disable_hdmi(struct intel_encoder *encoder)
789{
790 struct drm_device *dev = encoder->base.dev;
791 struct drm_i915_private *dev_priv = dev->dev_private;
792 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
793 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800794 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200795
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300796 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200797
798 /* HW workaround for IBX, we need to move the port to transcoder A
799 * before disabling it. */
800 if (HAS_PCH_IBX(dev)) {
801 struct drm_crtc *crtc = encoder->base.crtc;
802 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
803
804 if (temp & SDVO_PIPE_B_SELECT) {
805 temp &= ~SDVO_PIPE_B_SELECT;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300806 I915_WRITE(intel_hdmi->hdmi_reg, temp);
807 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200808
809 /* Again we need to write this twice. */
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300810 I915_WRITE(intel_hdmi->hdmi_reg, temp);
811 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200812
813 /* Transcoder selection bits only update
814 * effectively on vblank. */
815 if (crtc)
816 intel_wait_for_vblank(dev, pipe);
817 else
818 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200819 }
820 }
821
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000822 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
823 * we do this anyway which shows more stable in testing.
824 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800825 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300826 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
827 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800828 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000829
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200830 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000831
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300832 I915_WRITE(intel_hdmi->hdmi_reg, temp);
833 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000834
835 /* HW workaround, need to write this twice for issue that may result
836 * in first write getting masked.
837 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800838 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300839 I915_WRITE(intel_hdmi->hdmi_reg, temp);
840 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000841 }
Eric Anholt7d573822009-01-02 13:33:00 -0800842}
843
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200844static int hdmi_portclock_limit(struct intel_hdmi *hdmi)
845{
846 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
847
848 if (IS_G4X(dev))
849 return 165000;
850 else if (IS_HASWELL(dev))
851 return 300000;
852 else
853 return 225000;
854}
855
Eric Anholt7d573822009-01-02 13:33:00 -0800856static int intel_hdmi_mode_valid(struct drm_connector *connector,
857 struct drm_display_mode *mode)
858{
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200859 if (mode->clock > hdmi_portclock_limit(intel_attached_hdmi(connector)))
Eric Anholt7d573822009-01-02 13:33:00 -0800860 return MODE_CLOCK_HIGH;
861 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200862 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800863
864 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
865 return MODE_NO_DBLESCAN;
866
867 return MODE_OK;
868}
869
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100870bool intel_hdmi_compute_config(struct intel_encoder *encoder,
871 struct intel_crtc_config *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -0800872{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100873 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
874 struct drm_device *dev = encoder->base.dev;
875 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Damien Lespiau241bfc32013-09-25 16:45:37 +0100876 int clock_12bpc = pipe_config->adjusted_mode.crtc_clock * 3 / 2;
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200877 int portclock_limit = hdmi_portclock_limit(intel_hdmi);
Daniel Vettere29c22c2013-02-21 00:00:16 +0100878 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200879
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200880 if (intel_hdmi->color_range_auto) {
881 /* See CEA-861-E - 5.1 Default Encoding Parameters */
882 if (intel_hdmi->has_hdmi_sink &&
Thierry Reding18316c82012-12-20 15:41:44 +0100883 drm_match_cea_mode(adjusted_mode) > 1)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300884 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200885 else
886 intel_hdmi->color_range = 0;
887 }
888
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200889 if (intel_hdmi->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100890 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200891
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100892 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
893 pipe_config->has_pch_encoder = true;
894
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100895 /*
896 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
897 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +0200898 * outputs. We also need to check that the higher clock still fits
899 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100900 */
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200901 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit
Daniel Vetter325b9d02013-04-19 11:24:33 +0200902 && HAS_PCH_SPLIT(dev)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100903 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
904 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200905
906 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +0200907 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100908 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100909 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
910 desired_bpp = 8*3;
911 }
912
913 if (!pipe_config->bw_constrained) {
914 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
915 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100916 }
917
Damien Lespiau241bfc32013-09-25 16:45:37 +0100918 if (adjusted_mode->crtc_clock > portclock_limit) {
Daniel Vetter325b9d02013-04-19 11:24:33 +0200919 DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
920 return false;
921 }
922
Eric Anholt7d573822009-01-02 13:33:00 -0800923 return true;
924}
925
Keith Packardaa93d632009-05-05 09:52:46 -0700926static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100927intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800928{
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000929 struct drm_device *dev = connector->dev;
Chris Wilsondf0e9242010-09-09 16:20:55 +0100930 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200931 struct intel_digital_port *intel_dig_port =
932 hdmi_to_dig_port(intel_hdmi);
933 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000934 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700935 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700936 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800937
Chris Wilson164c8592013-07-20 20:27:08 +0100938 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
939 connector->base.id, drm_get_connector_name(connector));
940
Chris Wilsonea5b2132010-08-04 13:50:23 +0100941 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800942 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200943 intel_hdmi->rgb_quant_range_selectable = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700944 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800945 intel_gmbus_get_adapter(dev_priv,
946 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800947
Keith Packardaa93d632009-05-05 09:52:46 -0700948 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700949 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700950 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800951 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
952 intel_hdmi->has_hdmi_sink =
953 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800954 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200955 intel_hdmi->rgb_quant_range_selectable =
956 drm_rgb_quant_range_selectable(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700957 }
Keith Packardaa93d632009-05-05 09:52:46 -0700958 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800959 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800960
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100961 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800962 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
963 intel_hdmi->has_audio =
964 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200965 intel_encoder->type = INTEL_OUTPUT_HDMI;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100966 }
967
Keith Packardaa93d632009-05-05 09:52:46 -0700968 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800969}
970
Eric Anholt7d573822009-01-02 13:33:00 -0800971static int intel_hdmi_get_modes(struct drm_connector *connector)
972{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100973 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700974 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800975
976 /* We should parse the EDID data and find out if it's an HDMI sink so
977 * we can send audio to it.
978 */
979
Chris Wilsonf899fc62010-07-20 15:44:45 -0700980 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800981 intel_gmbus_get_adapter(dev_priv,
982 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800983}
984
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000985static bool
986intel_hdmi_detect_audio(struct drm_connector *connector)
987{
988 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
989 struct drm_i915_private *dev_priv = connector->dev->dev_private;
990 struct edid *edid;
991 bool has_audio = false;
992
993 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800994 intel_gmbus_get_adapter(dev_priv,
995 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000996 if (edid) {
997 if (edid->input & DRM_EDID_INPUT_DIGITAL)
998 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000999 kfree(edid);
1000 }
1001
1002 return has_audio;
1003}
1004
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001005static int
1006intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001007 struct drm_property *property,
1008 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001009{
1010 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001011 struct intel_digital_port *intel_dig_port =
1012 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +00001013 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001014 int ret;
1015
Rob Clark662595d2012-10-11 20:36:04 -05001016 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001017 if (ret)
1018 return ret;
1019
Chris Wilson3f43c482011-05-12 22:17:24 +01001020 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001021 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001022 bool has_audio;
1023
1024 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001025 return 0;
1026
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001027 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001028
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001029 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001030 has_audio = intel_hdmi_detect_audio(connector);
1031 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001032 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001033
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001034 if (i == HDMI_AUDIO_OFF_DVI)
1035 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001036
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001037 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001038 goto done;
1039 }
1040
Chris Wilsone953fd72011-02-21 22:23:52 +00001041 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001042 bool old_auto = intel_hdmi->color_range_auto;
1043 uint32_t old_range = intel_hdmi->color_range;
1044
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001045 switch (val) {
1046 case INTEL_BROADCAST_RGB_AUTO:
1047 intel_hdmi->color_range_auto = true;
1048 break;
1049 case INTEL_BROADCAST_RGB_FULL:
1050 intel_hdmi->color_range_auto = false;
1051 intel_hdmi->color_range = 0;
1052 break;
1053 case INTEL_BROADCAST_RGB_LIMITED:
1054 intel_hdmi->color_range_auto = false;
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -03001055 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001056 break;
1057 default:
1058 return -EINVAL;
1059 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001060
1061 if (old_auto == intel_hdmi->color_range_auto &&
1062 old_range == intel_hdmi->color_range)
1063 return 0;
1064
Chris Wilsone953fd72011-02-21 22:23:52 +00001065 goto done;
1066 }
1067
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001068 return -EINVAL;
1069
1070done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001071 if (intel_dig_port->base.base.crtc)
1072 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001073
1074 return 0;
1075}
1076
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001077static void vlv_hdmi_pre_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001078{
1079 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1080 struct drm_device *dev = encoder->base.dev;
1081 struct drm_i915_private *dev_priv = dev->dev_private;
1082 struct intel_crtc *intel_crtc =
1083 to_intel_crtc(encoder->base.crtc);
1084 int port = vlv_dport_to_channel(dport);
1085 int pipe = intel_crtc->pipe;
1086 u32 val;
1087
1088 if (!IS_VALLEYVIEW(dev))
1089 return;
1090
Jesse Barnes89b667f2013-04-18 14:51:36 -07001091 /* Enable clock channels for this port */
Chris Wilson0980a602013-07-26 19:57:35 +01001092 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001093 val = vlv_dpio_read(dev_priv, pipe, DPIO_DATA_LANE_A(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001094 val = 0;
1095 if (pipe)
1096 val |= (1<<21);
1097 else
1098 val &= ~(1<<21);
1099 val |= 0x001000c4;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001100 vlv_dpio_write(dev_priv, pipe, DPIO_DATA_CHANNEL(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001101
1102 /* HDMI 1.0V-2dB */
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001103 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port), 0);
1104 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001105 0x2b245f5f);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001106 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL2(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001107 0x5578b83a);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001108 vlv_dpio_write(dev_priv, pipe, DPIO_TX_SWING_CTL3(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001109 0x0c782040);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001110 vlv_dpio_write(dev_priv, pipe, DPIO_TX3_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001111 0x2b247878);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001112 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER0(port), 0x00030000);
1113 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001114 0x00002000);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001115 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001116 DPIO_TX_OCALINIT_EN);
1117
1118 /* Program lane clock */
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001119 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001120 0x00760018);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001121 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLOCKBUF8(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001122 0x00400888);
Chris Wilson0980a602013-07-26 19:57:35 +01001123 mutex_unlock(&dev_priv->dpio_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001124
1125 intel_enable_hdmi(encoder);
1126
1127 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001128}
1129
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001130static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001131{
1132 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1133 struct drm_device *dev = encoder->base.dev;
1134 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001135 struct intel_crtc *intel_crtc =
1136 to_intel_crtc(encoder->base.crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001137 int port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001138 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001139
1140 if (!IS_VALLEYVIEW(dev))
1141 return;
1142
Jesse Barnes89b667f2013-04-18 14:51:36 -07001143 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001144 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001145 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001146 DPIO_PCS_TX_LANE2_RESET |
1147 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001148 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001149 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1150 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1151 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1152 DPIO_PCS_CLK_SOFT_RESET);
1153
1154 /* Fix up inter-pair skew failure */
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001155 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_STAGGER1(port), 0x00750f00);
1156 vlv_dpio_write(dev_priv, pipe, DPIO_TX_CTL(port), 0x00001500);
1157 vlv_dpio_write(dev_priv, pipe, DPIO_TX_LANE(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001158
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001159 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001160 0x00002000);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001161 vlv_dpio_write(dev_priv, pipe, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001162 DPIO_TX_OCALINIT_EN);
Chris Wilson0980a602013-07-26 19:57:35 +01001163 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001164}
1165
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001166static void vlv_hdmi_post_disable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001167{
1168 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1169 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001170 struct intel_crtc *intel_crtc =
1171 to_intel_crtc(encoder->base.crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001172 int port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001173 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001174
1175 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1176 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001177 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_TX(port), 0x00000000);
1178 vlv_dpio_write(dev_priv, pipe, DPIO_PCS_CLK(port), 0x00e00060);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001179 mutex_unlock(&dev_priv->dpio_lock);
1180}
1181
Eric Anholt7d573822009-01-02 13:33:00 -08001182static void intel_hdmi_destroy(struct drm_connector *connector)
1183{
Eric Anholt7d573822009-01-02 13:33:00 -08001184 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001185 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001186}
1187
Eric Anholt7d573822009-01-02 13:33:00 -08001188static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001189 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001190 .detect = intel_hdmi_detect,
1191 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001192 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001193 .destroy = intel_hdmi_destroy,
1194};
1195
1196static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1197 .get_modes = intel_hdmi_get_modes,
1198 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001199 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001200};
1201
Eric Anholt7d573822009-01-02 13:33:00 -08001202static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001203 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001204};
1205
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001206static void
1207intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1208{
Chris Wilson3f43c482011-05-12 22:17:24 +01001209 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001210 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001211 intel_hdmi->color_range_auto = true;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001212}
1213
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001214void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1215 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001216{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001217 struct drm_connector *connector = &intel_connector->base;
1218 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1219 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1220 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08001221 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001222 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001223
Eric Anholt7d573822009-01-02 13:33:00 -08001224 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001225 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001226 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1227
Peter Rossc3febcc2012-01-28 14:49:26 +01001228 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001229 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01001230 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001231
Daniel Vetter08d644a2012-07-12 20:19:59 +02001232 switch (port) {
1233 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001234 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Egbert Eich1d843f92013-02-25 12:06:49 -05001235 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001236 break;
1237 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001238 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05001239 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001240 break;
1241 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001242 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05001243 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001244 break;
1245 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05001246 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001247 /* Internal port only for eDP. */
1248 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001249 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001250 }
Eric Anholt7d573822009-01-02 13:33:00 -08001251
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001252 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001253 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001254 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001255 } else if (!HAS_PCH_SPLIT(dev)) {
1256 intel_hdmi->write_infoframe = g4x_write_infoframe;
1257 intel_hdmi->set_infoframes = g4x_set_infoframes;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001258 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001259 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001260 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001261 } else if (HAS_PCH_IBX(dev)) {
1262 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001263 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001264 } else {
1265 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001266 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301267 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001268
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001269 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001270 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1271 else
1272 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001273
1274 intel_hdmi_add_properties(intel_hdmi, connector);
1275
1276 intel_connector_attach_encoder(intel_connector, intel_encoder);
1277 drm_sysfs_connector_add(connector);
1278
1279 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1280 * 0xd. Failure to do so will result in spurious interrupts being
1281 * generated on the port when a cable is not attached.
1282 */
1283 if (IS_G4X(dev) && !IS_GM45(dev)) {
1284 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1285 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1286 }
1287}
1288
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001289void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001290{
1291 struct intel_digital_port *intel_dig_port;
1292 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001293 struct intel_connector *intel_connector;
1294
Daniel Vetterb14c5672013-09-19 12:18:32 +02001295 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001296 if (!intel_dig_port)
1297 return;
1298
Daniel Vetterb14c5672013-09-19 12:18:32 +02001299 intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001300 if (!intel_connector) {
1301 kfree(intel_dig_port);
1302 return;
1303 }
1304
1305 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001306
1307 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1308 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001309
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001310 intel_encoder->compute_config = intel_hdmi_compute_config;
Daniel Vetterc59423a2013-07-21 21:37:04 +02001311 intel_encoder->mode_set = intel_hdmi_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001312 intel_encoder->disable = intel_disable_hdmi;
1313 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001314 intel_encoder->get_config = intel_hdmi_get_config;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001315 if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001316 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
1317 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001318 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001319 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001320 } else {
1321 intel_encoder->enable = intel_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001322 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001323
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001324 intel_encoder->type = INTEL_OUTPUT_HDMI;
1325 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1326 intel_encoder->cloneable = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001327
Paulo Zanoni174edf12012-10-26 19:05:50 -02001328 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001329 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001330 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001331
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001332 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001333}