blob: 4148cc85bf7fb303bde9ec151773480542b7f5f8 [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;
716
717 tmp = I915_READ(intel_hdmi->hdmi_reg);
718
719 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
720 flags |= DRM_MODE_FLAG_PHSYNC;
721 else
722 flags |= DRM_MODE_FLAG_NHSYNC;
723
724 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
725 flags |= DRM_MODE_FLAG_PVSYNC;
726 else
727 flags |= DRM_MODE_FLAG_NVSYNC;
728
729 pipe_config->adjusted_mode.flags |= flags;
730}
731
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200732static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800733{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200734 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800735 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300736 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200737 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800738 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800739 u32 enable_bits = SDVO_ENABLE;
740
741 if (intel_hdmi->has_audio)
742 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800743
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300744 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000745
Daniel Vetter7a87c282012-06-05 11:03:39 +0200746 /* HW workaround for IBX, we need to move the port to transcoder A
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300747 * before disabling it, so restore the transcoder select bit here. */
748 if (HAS_PCH_IBX(dev))
749 enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200750
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200751 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
752 * we do this anyway which shows more stable in testing.
753 */
754 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300755 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
756 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200757 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200758
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200759 temp |= enable_bits;
760
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300761 I915_WRITE(intel_hdmi->hdmi_reg, temp);
762 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200763
764 /* HW workaround, need to write this twice for issue that may result
765 * in first write getting masked.
766 */
767 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300768 I915_WRITE(intel_hdmi->hdmi_reg, temp);
769 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200770 }
Jani Nikulab76cf762013-07-30 12:20:31 +0300771}
Jesse Barnes89b667f2013-04-18 14:51:36 -0700772
Jani Nikulab76cf762013-07-30 12:20:31 +0300773static void vlv_enable_hdmi(struct intel_encoder *encoder)
774{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200775}
776
777static void intel_disable_hdmi(struct intel_encoder *encoder)
778{
779 struct drm_device *dev = encoder->base.dev;
780 struct drm_i915_private *dev_priv = dev->dev_private;
781 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
782 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800783 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200784
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300785 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200786
787 /* HW workaround for IBX, we need to move the port to transcoder A
788 * before disabling it. */
789 if (HAS_PCH_IBX(dev)) {
790 struct drm_crtc *crtc = encoder->base.crtc;
791 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
792
793 if (temp & SDVO_PIPE_B_SELECT) {
794 temp &= ~SDVO_PIPE_B_SELECT;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300795 I915_WRITE(intel_hdmi->hdmi_reg, temp);
796 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200797
798 /* Again we need to write this twice. */
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300799 I915_WRITE(intel_hdmi->hdmi_reg, temp);
800 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200801
802 /* Transcoder selection bits only update
803 * effectively on vblank. */
804 if (crtc)
805 intel_wait_for_vblank(dev, pipe);
806 else
807 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200808 }
809 }
810
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000811 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
812 * we do this anyway which shows more stable in testing.
813 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800814 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300815 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
816 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800817 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000818
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200819 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000820
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300821 I915_WRITE(intel_hdmi->hdmi_reg, temp);
822 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000823
824 /* HW workaround, need to write this twice for issue that may result
825 * in first write getting masked.
826 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800827 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300828 I915_WRITE(intel_hdmi->hdmi_reg, temp);
829 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000830 }
Eric Anholt7d573822009-01-02 13:33:00 -0800831}
832
Daniel Vetter7d148ef52013-07-22 18:02:39 +0200833static int hdmi_portclock_limit(struct intel_hdmi *hdmi)
834{
835 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
836
837 if (IS_G4X(dev))
838 return 165000;
839 else if (IS_HASWELL(dev))
840 return 300000;
841 else
842 return 225000;
843}
844
Eric Anholt7d573822009-01-02 13:33:00 -0800845static int intel_hdmi_mode_valid(struct drm_connector *connector,
846 struct drm_display_mode *mode)
847{
Daniel Vetter7d148ef52013-07-22 18:02:39 +0200848 if (mode->clock > hdmi_portclock_limit(intel_attached_hdmi(connector)))
Eric Anholt7d573822009-01-02 13:33:00 -0800849 return MODE_CLOCK_HIGH;
850 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200851 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800852
853 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
854 return MODE_NO_DBLESCAN;
855
856 return MODE_OK;
857}
858
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100859bool intel_hdmi_compute_config(struct intel_encoder *encoder,
860 struct intel_crtc_config *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -0800861{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100862 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
863 struct drm_device *dev = encoder->base.dev;
864 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200865 int clock_12bpc = pipe_config->requested_mode.clock * 3 / 2;
Daniel Vetter7d148ef52013-07-22 18:02:39 +0200866 int portclock_limit = hdmi_portclock_limit(intel_hdmi);
Daniel Vettere29c22c2013-02-21 00:00:16 +0100867 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200868
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200869 if (intel_hdmi->color_range_auto) {
870 /* See CEA-861-E - 5.1 Default Encoding Parameters */
871 if (intel_hdmi->has_hdmi_sink &&
Thierry Reding18316c82012-12-20 15:41:44 +0100872 drm_match_cea_mode(adjusted_mode) > 1)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300873 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200874 else
875 intel_hdmi->color_range = 0;
876 }
877
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200878 if (intel_hdmi->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100879 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200880
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100881 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
882 pipe_config->has_pch_encoder = true;
883
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100884 /*
885 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
886 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +0200887 * outputs. We also need to check that the higher clock still fits
888 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100889 */
Daniel Vetter7d148ef52013-07-22 18:02:39 +0200890 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit
Daniel Vetter325b9d02013-04-19 11:24:33 +0200891 && HAS_PCH_SPLIT(dev)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100892 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
893 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200894
895 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +0200896 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100897 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100898 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
899 desired_bpp = 8*3;
900 }
901
902 if (!pipe_config->bw_constrained) {
903 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
904 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100905 }
906
Daniel Vetter7d148ef52013-07-22 18:02:39 +0200907 if (adjusted_mode->clock > portclock_limit) {
Daniel Vetter325b9d02013-04-19 11:24:33 +0200908 DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
909 return false;
910 }
911
Eric Anholt7d573822009-01-02 13:33:00 -0800912 return true;
913}
914
Keith Packardaa93d632009-05-05 09:52:46 -0700915static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100916intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800917{
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000918 struct drm_device *dev = connector->dev;
Chris Wilsondf0e9242010-09-09 16:20:55 +0100919 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200920 struct intel_digital_port *intel_dig_port =
921 hdmi_to_dig_port(intel_hdmi);
922 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000923 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700924 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700925 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800926
Chris Wilson164c8592013-07-20 20:27:08 +0100927 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
928 connector->base.id, drm_get_connector_name(connector));
929
Chris Wilsonea5b2132010-08-04 13:50:23 +0100930 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800931 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200932 intel_hdmi->rgb_quant_range_selectable = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700933 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800934 intel_gmbus_get_adapter(dev_priv,
935 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800936
Keith Packardaa93d632009-05-05 09:52:46 -0700937 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700938 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700939 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800940 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
941 intel_hdmi->has_hdmi_sink =
942 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800943 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200944 intel_hdmi->rgb_quant_range_selectable =
945 drm_rgb_quant_range_selectable(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700946 }
Keith Packardaa93d632009-05-05 09:52:46 -0700947 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800948 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800949
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100950 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800951 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
952 intel_hdmi->has_audio =
953 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200954 intel_encoder->type = INTEL_OUTPUT_HDMI;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100955 }
956
Keith Packardaa93d632009-05-05 09:52:46 -0700957 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800958}
959
Eric Anholt7d573822009-01-02 13:33:00 -0800960static int intel_hdmi_get_modes(struct drm_connector *connector)
961{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100962 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700963 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800964
965 /* We should parse the EDID data and find out if it's an HDMI sink so
966 * we can send audio to it.
967 */
968
Chris Wilsonf899fc62010-07-20 15:44:45 -0700969 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800970 intel_gmbus_get_adapter(dev_priv,
971 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800972}
973
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000974static bool
975intel_hdmi_detect_audio(struct drm_connector *connector)
976{
977 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
978 struct drm_i915_private *dev_priv = connector->dev->dev_private;
979 struct edid *edid;
980 bool has_audio = false;
981
982 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800983 intel_gmbus_get_adapter(dev_priv,
984 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000985 if (edid) {
986 if (edid->input & DRM_EDID_INPUT_DIGITAL)
987 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000988 kfree(edid);
989 }
990
991 return has_audio;
992}
993
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100994static int
995intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300996 struct drm_property *property,
997 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100998{
999 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001000 struct intel_digital_port *intel_dig_port =
1001 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +00001002 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001003 int ret;
1004
Rob Clark662595d2012-10-11 20:36:04 -05001005 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001006 if (ret)
1007 return ret;
1008
Chris Wilson3f43c482011-05-12 22:17:24 +01001009 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001010 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001011 bool has_audio;
1012
1013 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001014 return 0;
1015
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001016 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001017
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001018 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001019 has_audio = intel_hdmi_detect_audio(connector);
1020 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001021 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001022
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001023 if (i == HDMI_AUDIO_OFF_DVI)
1024 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001025
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001026 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001027 goto done;
1028 }
1029
Chris Wilsone953fd72011-02-21 22:23:52 +00001030 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001031 bool old_auto = intel_hdmi->color_range_auto;
1032 uint32_t old_range = intel_hdmi->color_range;
1033
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001034 switch (val) {
1035 case INTEL_BROADCAST_RGB_AUTO:
1036 intel_hdmi->color_range_auto = true;
1037 break;
1038 case INTEL_BROADCAST_RGB_FULL:
1039 intel_hdmi->color_range_auto = false;
1040 intel_hdmi->color_range = 0;
1041 break;
1042 case INTEL_BROADCAST_RGB_LIMITED:
1043 intel_hdmi->color_range_auto = false;
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -03001044 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001045 break;
1046 default:
1047 return -EINVAL;
1048 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001049
1050 if (old_auto == intel_hdmi->color_range_auto &&
1051 old_range == intel_hdmi->color_range)
1052 return 0;
1053
Chris Wilsone953fd72011-02-21 22:23:52 +00001054 goto done;
1055 }
1056
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001057 return -EINVAL;
1058
1059done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001060 if (intel_dig_port->base.base.crtc)
1061 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001062
1063 return 0;
1064}
1065
Jesse Barnes89b667f2013-04-18 14:51:36 -07001066static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1067{
1068 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1069 struct drm_device *dev = encoder->base.dev;
1070 struct drm_i915_private *dev_priv = dev->dev_private;
1071 struct intel_crtc *intel_crtc =
1072 to_intel_crtc(encoder->base.crtc);
1073 int port = vlv_dport_to_channel(dport);
1074 int pipe = intel_crtc->pipe;
1075 u32 val;
1076
1077 if (!IS_VALLEYVIEW(dev))
1078 return;
1079
Jesse Barnes89b667f2013-04-18 14:51:36 -07001080 /* Enable clock channels for this port */
Chris Wilson0980a602013-07-26 19:57:35 +01001081 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001082 val = vlv_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001083 val = 0;
1084 if (pipe)
1085 val |= (1<<21);
1086 else
1087 val &= ~(1<<21);
1088 val |= 0x001000c4;
Jani Nikulaae992582013-05-22 15:36:19 +03001089 vlv_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001090
1091 /* HDMI 1.0V-2dB */
Jani Nikulaae992582013-05-22 15:36:19 +03001092 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
1093 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001094 0x2b245f5f);
Jani Nikulaae992582013-05-22 15:36:19 +03001095 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001096 0x5578b83a);
Jani Nikulaae992582013-05-22 15:36:19 +03001097 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001098 0x0c782040);
Jani Nikulaae992582013-05-22 15:36:19 +03001099 vlv_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001100 0x2b247878);
Jani Nikulaae992582013-05-22 15:36:19 +03001101 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
1102 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001103 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001104 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001105 DPIO_TX_OCALINIT_EN);
1106
1107 /* Program lane clock */
Jani Nikulaae992582013-05-22 15:36:19 +03001108 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001109 0x00760018);
Jani Nikulaae992582013-05-22 15:36:19 +03001110 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001111 0x00400888);
Chris Wilson0980a602013-07-26 19:57:35 +01001112 mutex_unlock(&dev_priv->dpio_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001113
1114 intel_enable_hdmi(encoder);
1115
1116 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001117}
1118
1119static void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1120{
1121 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1122 struct drm_device *dev = encoder->base.dev;
1123 struct drm_i915_private *dev_priv = dev->dev_private;
1124 int port = vlv_dport_to_channel(dport);
1125
1126 if (!IS_VALLEYVIEW(dev))
1127 return;
1128
Jesse Barnes89b667f2013-04-18 14:51:36 -07001129 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001130 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001131 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001132 DPIO_PCS_TX_LANE2_RESET |
1133 DPIO_PCS_TX_LANE1_RESET);
Jani Nikulaae992582013-05-22 15:36:19 +03001134 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001135 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1136 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1137 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1138 DPIO_PCS_CLK_SOFT_RESET);
1139
1140 /* Fix up inter-pair skew failure */
Jani Nikulaae992582013-05-22 15:36:19 +03001141 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
1142 vlv_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
1143 vlv_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001144
Jani Nikulaae992582013-05-22 15:36:19 +03001145 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001146 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001147 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001148 DPIO_TX_OCALINIT_EN);
Chris Wilson0980a602013-07-26 19:57:35 +01001149 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001150}
1151
1152static void intel_hdmi_post_disable(struct intel_encoder *encoder)
1153{
1154 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1155 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1156 int port = vlv_dport_to_channel(dport);
1157
1158 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1159 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001160 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
1161 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001162 mutex_unlock(&dev_priv->dpio_lock);
1163}
1164
Eric Anholt7d573822009-01-02 13:33:00 -08001165static void intel_hdmi_destroy(struct drm_connector *connector)
1166{
Eric Anholt7d573822009-01-02 13:33:00 -08001167 drm_sysfs_connector_remove(connector);
1168 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001169 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001170}
1171
Eric Anholt7d573822009-01-02 13:33:00 -08001172static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001173 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001174 .detect = intel_hdmi_detect,
1175 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001176 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001177 .destroy = intel_hdmi_destroy,
1178};
1179
1180static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1181 .get_modes = intel_hdmi_get_modes,
1182 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001183 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001184};
1185
Eric Anholt7d573822009-01-02 13:33:00 -08001186static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001187 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001188};
1189
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001190static void
1191intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1192{
Chris Wilson3f43c482011-05-12 22:17:24 +01001193 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001194 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001195 intel_hdmi->color_range_auto = true;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001196}
1197
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001198void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1199 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001200{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001201 struct drm_connector *connector = &intel_connector->base;
1202 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1203 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1204 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08001205 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001206 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001207
Eric Anholt7d573822009-01-02 13:33:00 -08001208 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001209 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001210 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1211
Peter Rossc3febcc2012-01-28 14:49:26 +01001212 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001213 connector->doublescan_allowed = 0;
1214
Daniel Vetter08d644a2012-07-12 20:19:59 +02001215 switch (port) {
1216 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001217 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Egbert Eich1d843f92013-02-25 12:06:49 -05001218 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001219 break;
1220 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001221 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05001222 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001223 break;
1224 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001225 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05001226 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001227 break;
1228 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05001229 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001230 /* Internal port only for eDP. */
1231 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001232 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001233 }
Eric Anholt7d573822009-01-02 13:33:00 -08001234
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001235 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001236 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001237 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001238 } else if (!HAS_PCH_SPLIT(dev)) {
1239 intel_hdmi->write_infoframe = g4x_write_infoframe;
1240 intel_hdmi->set_infoframes = g4x_set_infoframes;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001241 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001242 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001243 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001244 } else if (HAS_PCH_IBX(dev)) {
1245 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001246 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001247 } else {
1248 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001249 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301250 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001251
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001252 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001253 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1254 else
1255 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001256
1257 intel_hdmi_add_properties(intel_hdmi, connector);
1258
1259 intel_connector_attach_encoder(intel_connector, intel_encoder);
1260 drm_sysfs_connector_add(connector);
1261
1262 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1263 * 0xd. Failure to do so will result in spurious interrupts being
1264 * generated on the port when a cable is not attached.
1265 */
1266 if (IS_G4X(dev) && !IS_GM45(dev)) {
1267 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1268 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1269 }
1270}
1271
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001272void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001273{
1274 struct intel_digital_port *intel_dig_port;
1275 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001276 struct intel_connector *intel_connector;
1277
1278 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1279 if (!intel_dig_port)
1280 return;
1281
1282 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1283 if (!intel_connector) {
1284 kfree(intel_dig_port);
1285 return;
1286 }
1287
1288 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001289
1290 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1291 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001292
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001293 intel_encoder->compute_config = intel_hdmi_compute_config;
Daniel Vetterc59423a2013-07-21 21:37:04 +02001294 intel_encoder->mode_set = intel_hdmi_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001295 intel_encoder->disable = intel_disable_hdmi;
1296 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001297 intel_encoder->get_config = intel_hdmi_get_config;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001298 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07001299 intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001300 intel_encoder->pre_enable = intel_hdmi_pre_enable;
1301 intel_encoder->enable = vlv_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001302 intel_encoder->post_disable = intel_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001303 } else {
1304 intel_encoder->enable = intel_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001305 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001306
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001307 intel_encoder->type = INTEL_OUTPUT_HDMI;
1308 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1309 intel_encoder->cloneable = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001310
Paulo Zanoni174edf12012-10-26 19:05:50 -02001311 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001312 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001313 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001314
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001315 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001316}