blob: 3b9c1176be5b534a21c78ebcf4313a2a57b1fb23 [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>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_edid.h>
Eric Anholt7d573822009-01-02 13:33:00 -080037#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010038#include <drm/i915_drm.h>
Eric Anholt7d573822009-01-02 13:33:00 -080039#include "i915_drv.h"
40
Paulo Zanoni30add222012-10-26 19:05:45 -020041static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
42{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020043 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020044}
45
Daniel Vetterafba0182012-06-12 16:36:45 +020046static void
47assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
48{
Paulo Zanoni30add222012-10-26 19:05:45 -020049 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Daniel Vetterafba0182012-06-12 16:36:45 +020050 struct drm_i915_private *dev_priv = dev->dev_private;
51 uint32_t enabled_bits;
52
Paulo Zanoniaffa9352012-11-23 15:30:39 -020053 enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020054
Paulo Zanonib242b7f2013-02-18 19:00:26 -030055 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020056 "HDMI port enabled, expecting disabled\n");
57}
58
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030059struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010060{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020061 struct intel_digital_port *intel_dig_port =
62 container_of(encoder, struct intel_digital_port, base.base);
63 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010064}
65
Chris Wilsondf0e9242010-09-09 16:20:55 +010066static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
67{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020068 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010069}
70
Damien Lespiau178f7362013-08-06 20:32:18 +010071static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020072{
Damien Lespiau178f7362013-08-06 20:32:18 +010073 switch (type) {
74 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030075 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010076 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030077 return VIDEO_DIP_SELECT_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010078 case HDMI_INFOFRAME_TYPE_VENDOR:
79 return VIDEO_DIP_SELECT_VENDOR;
Jesse Barnes45187ac2011-08-03 09:22:55 -070080 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010081 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030082 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070083 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070084}
85
Damien Lespiau178f7362013-08-06 20:32:18 +010086static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070087{
Damien Lespiau178f7362013-08-06 20:32:18 +010088 switch (type) {
89 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030090 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010091 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030092 return VIDEO_DIP_ENABLE_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010093 case HDMI_INFOFRAME_TYPE_VENDOR:
94 return VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030095 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010096 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030097 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030098 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030099}
100
Damien Lespiau178f7362013-08-06 20:32:18 +0100101static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300102{
Damien Lespiau178f7362013-08-06 20:32:18 +0100103 switch (type) {
104 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300105 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100106 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300107 return VIDEO_DIP_ENABLE_SPD_HSW;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100108 case HDMI_INFOFRAME_TYPE_VENDOR:
109 return VIDEO_DIP_ENABLE_VS_HSW;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300110 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100111 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300112 return 0;
113 }
114}
115
Damien Lespiau178f7362013-08-06 20:32:18 +0100116static u32 hsw_infoframe_data_reg(enum hdmi_infoframe_type type,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200117 enum transcoder cpu_transcoder,
118 struct drm_i915_private *dev_priv)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300119{
Damien Lespiau178f7362013-08-06 20:32:18 +0100120 switch (type) {
121 case HDMI_INFOFRAME_TYPE_AVI:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300122 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100123 case HDMI_INFOFRAME_TYPE_SPD:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300124 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100125 case HDMI_INFOFRAME_TYPE_VENDOR:
126 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300127 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100128 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300129 return 0;
130 }
131}
132
Daniel Vettera3da1df2012-05-08 15:19:06 +0200133static void g4x_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100134 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200135 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700136{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200137 const uint32_t *data = frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200138 struct drm_device *dev = encoder->dev;
139 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300140 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100141 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200142
Paulo Zanoni822974a2012-05-28 16:42:51 -0300143 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
144
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300145 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100146 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700147
Damien Lespiau178f7362013-08-06 20:32:18 +0100148 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300149
150 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700151
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300152 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700153 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200154 I915_WRITE(VIDEO_DIP_DATA, *data);
155 data++;
156 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300157 /* Write every possible data byte to force correct ECC calculation. */
158 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
159 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300160 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200161
Damien Lespiau178f7362013-08-06 20:32:18 +0100162 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300163 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200164 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700165
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300166 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300167 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200168}
169
Jesse Barnese43823e2014-11-05 14:26:08 -0800170static bool g4x_infoframe_enabled(struct drm_encoder *encoder)
171{
172 struct drm_device *dev = encoder->dev;
173 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800174 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800175 u32 val = I915_READ(VIDEO_DIP_CTL);
176
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800177 if (VIDEO_DIP_PORT(intel_dig_port->port) == (val & VIDEO_DIP_PORT_MASK))
178 return val & VIDEO_DIP_ENABLE;
179
180 return false;
Jesse Barnese43823e2014-11-05 14:26:08 -0800181}
182
Paulo Zanonifdf12502012-05-04 17:18:24 -0300183static void ibx_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100184 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200185 const void *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300186{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200187 const uint32_t *data = frame;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300188 struct drm_device *dev = encoder->dev;
189 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300190 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100191 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300192 u32 val = I915_READ(reg);
193
Paulo Zanoni822974a2012-05-28 16:42:51 -0300194 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
195
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100197 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300198
Damien Lespiau178f7362013-08-06 20:32:18 +0100199 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300200
201 I915_WRITE(reg, val);
202
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300203 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300204 for (i = 0; i < len; i += 4) {
205 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
206 data++;
207 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300208 /* Write every possible data byte to force correct ECC calculation. */
209 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
210 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300211 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300212
Damien Lespiau178f7362013-08-06 20:32:18 +0100213 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300214 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200215 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300216
217 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300218 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300219}
220
Jesse Barnese43823e2014-11-05 14:26:08 -0800221static bool ibx_infoframe_enabled(struct drm_encoder *encoder)
222{
223 struct drm_device *dev = encoder->dev;
224 struct drm_i915_private *dev_priv = dev->dev_private;
225 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
226 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
227 u32 val = I915_READ(reg);
228
229 return val & VIDEO_DIP_ENABLE;
230}
231
Paulo Zanonifdf12502012-05-04 17:18:24 -0300232static void cpt_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100233 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200234 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700235{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200236 const uint32_t *data = frame;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700237 struct drm_device *dev = encoder->dev;
238 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300239 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100240 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300241 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700242
Paulo Zanoni822974a2012-05-28 16:42:51 -0300243 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
244
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530245 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100246 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700247
Paulo Zanoniecb97852012-05-04 17:18:21 -0300248 /* The DIP control register spec says that we need to update the AVI
249 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100250 if (type != HDMI_INFOFRAME_TYPE_AVI)
251 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300252
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300253 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700254
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300255 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700256 for (i = 0; i < len; i += 4) {
257 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
258 data++;
259 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300260 /* Write every possible data byte to force correct ECC calculation. */
261 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
262 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300263 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700264
Damien Lespiau178f7362013-08-06 20:32:18 +0100265 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300266 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200267 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700268
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300269 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300270 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700271}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700272
Jesse Barnese43823e2014-11-05 14:26:08 -0800273static bool cpt_infoframe_enabled(struct drm_encoder *encoder)
274{
275 struct drm_device *dev = encoder->dev;
276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
278 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
279 u32 val = I915_READ(reg);
280
281 return val & VIDEO_DIP_ENABLE;
282}
283
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700284static void vlv_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100285 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200286 const void *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700287{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200288 const uint32_t *data = frame;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700289 struct drm_device *dev = encoder->dev;
290 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300291 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100292 int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300293 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700294
Paulo Zanoni822974a2012-05-28 16:42:51 -0300295 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
296
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700297 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100298 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700299
Damien Lespiau178f7362013-08-06 20:32:18 +0100300 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300301
302 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700303
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300304 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700305 for (i = 0; i < len; i += 4) {
306 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
307 data++;
308 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300309 /* Write every possible data byte to force correct ECC calculation. */
310 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
311 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300312 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700313
Damien Lespiau178f7362013-08-06 20:32:18 +0100314 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300315 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200316 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700317
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300318 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300319 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700320}
321
Jesse Barnese43823e2014-11-05 14:26:08 -0800322static bool vlv_infoframe_enabled(struct drm_encoder *encoder)
323{
324 struct drm_device *dev = encoder->dev;
325 struct drm_i915_private *dev_priv = dev->dev_private;
326 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes535afa22015-04-15 16:52:29 -0700327 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800328 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
329 u32 val = I915_READ(reg);
330
Jani Nikulaeeea3e62015-04-29 14:29:39 +0300331 if (VIDEO_DIP_PORT(intel_dig_port->port) == (val & VIDEO_DIP_PORT_MASK))
Jesse Barnes535afa22015-04-15 16:52:29 -0700332 return val & VIDEO_DIP_ENABLE;
333
334 return false;
Jesse Barnese43823e2014-11-05 14:26:08 -0800335}
336
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300337static void hsw_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100338 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200339 const void *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300340{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200341 const uint32_t *data = frame;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300342 struct drm_device *dev = encoder->dev;
343 struct drm_i915_private *dev_priv = dev->dev_private;
344 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200345 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100346 u32 data_reg;
347 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300348 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300349
Damien Lespiau178f7362013-08-06 20:32:18 +0100350 data_reg = hsw_infoframe_data_reg(type,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200351 intel_crtc->config->cpu_transcoder,
Antti Koskipaaa57c7742014-02-04 14:22:24 +0200352 dev_priv);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300353 if (data_reg == 0)
354 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300355
Damien Lespiau178f7362013-08-06 20:32:18 +0100356 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300357 I915_WRITE(ctl_reg, val);
358
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300359 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300360 for (i = 0; i < len; i += 4) {
361 I915_WRITE(data_reg + i, *data);
362 data++;
363 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300364 /* Write every possible data byte to force correct ECC calculation. */
365 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
366 I915_WRITE(data_reg + i, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300367 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300368
Damien Lespiau178f7362013-08-06 20:32:18 +0100369 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300370 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300371 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300372}
373
Jesse Barnese43823e2014-11-05 14:26:08 -0800374static bool hsw_infoframe_enabled(struct drm_encoder *encoder)
375{
376 struct drm_device *dev = encoder->dev;
377 struct drm_i915_private *dev_priv = dev->dev_private;
378 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200379 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800380 u32 val = I915_READ(ctl_reg);
381
382 return val & (VIDEO_DIP_ENABLE_AVI_HSW | VIDEO_DIP_ENABLE_SPD_HSW |
383 VIDEO_DIP_ENABLE_VS_HSW);
384}
385
Damien Lespiau5adaea72013-08-06 20:32:19 +0100386/*
387 * The data we write to the DIP data buffer registers is 1 byte bigger than the
388 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
389 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
390 * used for both technologies.
391 *
392 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
393 * DW1: DB3 | DB2 | DB1 | DB0
394 * DW2: DB7 | DB6 | DB5 | DB4
395 * DW3: ...
396 *
397 * (HB is Header Byte, DB is Data Byte)
398 *
399 * The hdmi pack() functions don't know about that hardware specific hole so we
400 * trick them by giving an offset into the buffer and moving back the header
401 * bytes by one.
402 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100403static void intel_write_infoframe(struct drm_encoder *encoder,
404 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700405{
406 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100407 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
408 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700409
Damien Lespiau5adaea72013-08-06 20:32:19 +0100410 /* see comment above for the reason for this offset */
411 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
412 if (len < 0)
413 return;
414
415 /* Insert the 'hole' (see big comment above) at position 3 */
416 buffer[0] = buffer[1];
417 buffer[1] = buffer[2];
418 buffer[2] = buffer[3];
419 buffer[3] = 0;
420 len++;
421
422 intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700423}
424
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300425static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300426 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700427{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200428 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter50f3b012013-03-27 00:44:56 +0100429 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100430 union hdmi_infoframe frame;
431 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700432
Vandana Kannan94a11dd2014-06-11 11:06:01 +0530433 /* Set user selected PAR to incoming mode's member */
434 adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
435
Damien Lespiau5adaea72013-08-06 20:32:19 +0100436 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
437 adjusted_mode);
438 if (ret < 0) {
439 DRM_ERROR("couldn't fill AVI infoframe\n");
440 return;
441 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300442
Ville Syrjäläabedc072013-01-17 16:31:31 +0200443 if (intel_hdmi->rgb_quant_range_selectable) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200444 if (intel_crtc->config->limited_color_range)
Damien Lespiau5adaea72013-08-06 20:32:19 +0100445 frame.avi.quantization_range =
446 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200447 else
Damien Lespiau5adaea72013-08-06 20:32:19 +0100448 frame.avi.quantization_range =
449 HDMI_QUANTIZATION_RANGE_FULL;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200450 }
451
Damien Lespiau9198ee52013-08-06 20:32:24 +0100452 intel_write_infoframe(encoder, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700453}
454
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300455static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700456{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100457 union hdmi_infoframe frame;
458 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700459
Damien Lespiau5adaea72013-08-06 20:32:19 +0100460 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
461 if (ret < 0) {
462 DRM_ERROR("couldn't fill SPD infoframe\n");
463 return;
464 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700465
Damien Lespiau5adaea72013-08-06 20:32:19 +0100466 frame.spd.sdi = HDMI_SPD_SDI_PC;
467
Damien Lespiau9198ee52013-08-06 20:32:24 +0100468 intel_write_infoframe(encoder, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700469}
470
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100471static void
472intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
473 struct drm_display_mode *adjusted_mode)
474{
475 union hdmi_infoframe frame;
476 int ret;
477
478 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
479 adjusted_mode);
480 if (ret < 0)
481 return;
482
483 intel_write_infoframe(encoder, &frame);
484}
485
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300486static void g4x_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200487 bool enable,
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300488 struct drm_display_mode *adjusted_mode)
489{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300490 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200491 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
492 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300493 u32 reg = VIDEO_DIP_CTL;
494 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200495 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300496
Daniel Vetterafba0182012-06-12 16:36:45 +0200497 assert_hdmi_port_disabled(intel_hdmi);
498
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300499 /* If the registers were not initialized yet, they might be zeroes,
500 * which means we're selecting the AVI DIP and we're setting its
501 * frequency to once. This seems to really confuse the HW and make
502 * things stop working (the register spec says the AVI always needs to
503 * be sent every VSync). So here we avoid writing to the register more
504 * than we need and also explicitly select the AVI DIP and explicitly
505 * set its frequency to every VSync. Avoiding to write it twice seems to
506 * be enough to solve the problem, but being defensive shouldn't hurt us
507 * either. */
508 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
509
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200510 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300511 if (!(val & VIDEO_DIP_ENABLE))
512 return;
513 val &= ~VIDEO_DIP_ENABLE;
514 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300515 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300516 return;
517 }
518
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300519 if (port != (val & VIDEO_DIP_PORT_MASK)) {
520 if (val & VIDEO_DIP_ENABLE) {
521 val &= ~VIDEO_DIP_ENABLE;
522 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300523 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300524 }
525 val &= ~VIDEO_DIP_PORT_MASK;
526 val |= port;
527 }
528
Paulo Zanoni822974a2012-05-28 16:42:51 -0300529 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300530 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300531
Paulo Zanonif278d972012-05-28 16:42:50 -0300532 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300533 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300534
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300535 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
536 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100537 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300538}
539
540static void ibx_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200541 bool enable,
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300542 struct drm_display_mode *adjusted_mode)
543{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300544 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
545 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200546 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
547 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300548 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
549 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200550 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300551
Daniel Vetterafba0182012-06-12 16:36:45 +0200552 assert_hdmi_port_disabled(intel_hdmi);
553
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300554 /* See the big comment in g4x_set_infoframes() */
555 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
556
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200557 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300558 if (!(val & VIDEO_DIP_ENABLE))
559 return;
560 val &= ~VIDEO_DIP_ENABLE;
561 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300562 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300563 return;
564 }
565
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300566 if (port != (val & VIDEO_DIP_PORT_MASK)) {
567 if (val & VIDEO_DIP_ENABLE) {
568 val &= ~VIDEO_DIP_ENABLE;
569 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300570 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300571 }
572 val &= ~VIDEO_DIP_PORT_MASK;
573 val |= port;
574 }
575
Paulo Zanoni822974a2012-05-28 16:42:51 -0300576 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300577 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
578 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300579
Paulo Zanonif278d972012-05-28 16:42:50 -0300580 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300581 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300582
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300583 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
584 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100585 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300586}
587
588static void cpt_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200589 bool enable,
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300590 struct drm_display_mode *adjusted_mode)
591{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300592 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
593 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
594 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
595 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
596 u32 val = I915_READ(reg);
597
Daniel Vetterafba0182012-06-12 16:36:45 +0200598 assert_hdmi_port_disabled(intel_hdmi);
599
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300600 /* See the big comment in g4x_set_infoframes() */
601 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
602
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200603 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300604 if (!(val & VIDEO_DIP_ENABLE))
605 return;
606 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
607 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300608 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300609 return;
610 }
611
Paulo Zanoni822974a2012-05-28 16:42:51 -0300612 /* Set both together, unset both together: see the spec. */
613 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300614 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
615 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300616
617 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300618 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300619
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300620 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
621 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100622 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300623}
624
625static void vlv_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200626 bool enable,
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300627 struct drm_display_mode *adjusted_mode)
628{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300629 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700630 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300631 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
632 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
633 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
634 u32 val = I915_READ(reg);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700635 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300636
Daniel Vetterafba0182012-06-12 16:36:45 +0200637 assert_hdmi_port_disabled(intel_hdmi);
638
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300639 /* See the big comment in g4x_set_infoframes() */
640 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
641
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200642 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300643 if (!(val & VIDEO_DIP_ENABLE))
644 return;
645 val &= ~VIDEO_DIP_ENABLE;
646 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300647 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300648 return;
649 }
650
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700651 if (port != (val & VIDEO_DIP_PORT_MASK)) {
652 if (val & VIDEO_DIP_ENABLE) {
653 val &= ~VIDEO_DIP_ENABLE;
654 I915_WRITE(reg, val);
655 POSTING_READ(reg);
656 }
657 val &= ~VIDEO_DIP_PORT_MASK;
658 val |= port;
659 }
660
Paulo Zanoni822974a2012-05-28 16:42:51 -0300661 val |= VIDEO_DIP_ENABLE;
Jesse Barnes4d47dfb2014-04-02 10:08:52 -0700662 val &= ~(VIDEO_DIP_ENABLE_AVI | VIDEO_DIP_ENABLE_VENDOR |
663 VIDEO_DIP_ENABLE_GAMUT | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300664
665 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300666 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300667
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300668 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
669 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100670 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300671}
672
673static void hsw_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200674 bool enable,
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300675 struct drm_display_mode *adjusted_mode)
676{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300677 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
678 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
679 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200680 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300681 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300682
Daniel Vetterafba0182012-06-12 16:36:45 +0200683 assert_hdmi_port_disabled(intel_hdmi);
684
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200685 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300686 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300687 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300688 return;
689 }
690
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300691 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
692 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
693
694 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300695 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300696
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300697 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
698 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100699 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300700}
701
Daniel Vetter4cde8a22014-04-24 23:54:56 +0200702static void intel_hdmi_prepare(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800703{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200704 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800705 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200706 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
707 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200708 struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300709 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800710
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300711 hdmi_val = SDVO_ENCODING_HDMI;
Ville Syrjälä2af2c492013-06-25 14:16:34 +0300712 if (!HAS_PCH_SPLIT(dev))
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300713 hdmi_val |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400714 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300715 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400716 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300717 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800718
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200719 if (crtc->config->pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300720 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700721 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300722 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700723
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200724 if (crtc->config->has_hdmi_sink)
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300725 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800726
Jesse Barnes75770562011-10-12 09:01:58 -0700727 if (HAS_PCH_CPT(dev))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200728 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Chon Ming Lee44f37d12014-04-09 13:28:21 +0300729 else if (IS_CHERRYVIEW(dev))
730 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300731 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200732 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800733
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300734 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
735 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800736}
737
Daniel Vetter85234cd2012-07-02 13:27:29 +0200738static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
739 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800740{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200741 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800742 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200743 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Imre Deak6d129be2014-03-05 16:20:54 +0200744 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200745 u32 tmp;
746
Imre Deak6d129be2014-03-05 16:20:54 +0200747 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200748 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200749 return false;
750
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300751 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200752
753 if (!(tmp & SDVO_ENABLE))
754 return false;
755
756 if (HAS_PCH_CPT(dev))
757 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä71485e02014-04-09 13:28:55 +0300758 else if (IS_CHERRYVIEW(dev))
759 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200760 else
761 *pipe = PORT_TO_PIPE(tmp);
762
763 return true;
764}
765
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700766static void intel_hdmi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200767 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700768{
769 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300770 struct drm_device *dev = encoder->base.dev;
771 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700772 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300773 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700774
775 tmp = I915_READ(intel_hdmi->hdmi_reg);
776
777 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
778 flags |= DRM_MODE_FLAG_PHSYNC;
779 else
780 flags |= DRM_MODE_FLAG_NHSYNC;
781
782 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
783 flags |= DRM_MODE_FLAG_PVSYNC;
784 else
785 flags |= DRM_MODE_FLAG_NVSYNC;
786
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200787 if (tmp & HDMI_MODE_SELECT_HDMI)
788 pipe_config->has_hdmi_sink = true;
789
Jesse Barnese43823e2014-11-05 14:26:08 -0800790 if (intel_hdmi->infoframe_enabled(&encoder->base))
791 pipe_config->has_infoframe = true;
792
Jani Nikulac84db772014-09-17 15:34:58 +0300793 if (tmp & SDVO_AUDIO_ENABLE)
Daniel Vetter9ed109a2014-04-24 23:54:52 +0200794 pipe_config->has_audio = true;
795
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300796 if (!HAS_PCH_SPLIT(dev) &&
797 tmp & HDMI_COLOR_RANGE_16_235)
798 pipe_config->limited_color_range = true;
799
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200800 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300801
802 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
803 dotclock = pipe_config->port_clock * 2 / 3;
804 else
805 dotclock = pipe_config->port_clock;
806
807 if (HAS_PCH_SPLIT(dev_priv->dev))
808 ironlake_check_encoder_dotclock(pipe_config, dotclock);
809
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200810 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700811}
812
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200813static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800814{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200815 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800816 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300817 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200818 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800819 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800820 u32 enable_bits = SDVO_ENABLE;
821
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200822 if (intel_crtc->config->has_audio)
Wu Fengguang2deed762011-12-09 20:42:20 +0800823 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800824
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300825 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000826
Daniel Vetter7a87c282012-06-05 11:03:39 +0200827 /* HW workaround for IBX, we need to move the port to transcoder A
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300828 * before disabling it, so restore the transcoder select bit here. */
829 if (HAS_PCH_IBX(dev))
830 enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200831
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200832 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
833 * we do this anyway which shows more stable in testing.
834 */
835 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300836 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
837 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200838 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200839
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200840 temp |= enable_bits;
841
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300842 I915_WRITE(intel_hdmi->hdmi_reg, temp);
843 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200844
845 /* HW workaround, need to write this twice for issue that may result
846 * in first write getting masked.
847 */
848 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300849 I915_WRITE(intel_hdmi->hdmi_reg, temp);
850 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200851 }
Jani Nikulac1dec792014-10-27 16:26:56 +0200852
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200853 if (intel_crtc->config->has_audio) {
854 WARN_ON(!intel_crtc->config->has_hdmi_sink);
Jani Nikulac1dec792014-10-27 16:26:56 +0200855 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
856 pipe_name(intel_crtc->pipe));
857 intel_audio_codec_enable(encoder);
858 }
Jani Nikulab76cf762013-07-30 12:20:31 +0300859}
Jesse Barnes89b667f2013-04-18 14:51:36 -0700860
Jani Nikulab76cf762013-07-30 12:20:31 +0300861static void vlv_enable_hdmi(struct intel_encoder *encoder)
862{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200863}
864
865static void intel_disable_hdmi(struct intel_encoder *encoder)
866{
867 struct drm_device *dev = encoder->base.dev;
868 struct drm_i915_private *dev_priv = dev->dev_private;
869 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +0200870 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200871 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800872 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200873
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200874 if (crtc->config->has_audio)
Jani Nikula495a5bb2014-10-27 16:26:55 +0200875 intel_audio_codec_disable(encoder);
876
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300877 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200878
879 /* HW workaround for IBX, we need to move the port to transcoder A
880 * before disabling it. */
881 if (HAS_PCH_IBX(dev)) {
882 struct drm_crtc *crtc = encoder->base.crtc;
883 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
884
885 if (temp & SDVO_PIPE_B_SELECT) {
886 temp &= ~SDVO_PIPE_B_SELECT;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300887 I915_WRITE(intel_hdmi->hdmi_reg, temp);
888 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200889
890 /* Again we need to write this twice. */
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300891 I915_WRITE(intel_hdmi->hdmi_reg, temp);
892 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200893
894 /* Transcoder selection bits only update
895 * effectively on vblank. */
896 if (crtc)
897 intel_wait_for_vblank(dev, pipe);
898 else
899 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200900 }
901 }
902
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000903 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
904 * we do this anyway which shows more stable in testing.
905 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800906 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300907 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
908 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800909 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000910
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200911 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000912
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300913 I915_WRITE(intel_hdmi->hdmi_reg, temp);
914 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000915
916 /* HW workaround, need to write this twice for issue that may result
917 * in first write getting masked.
918 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800919 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300920 I915_WRITE(intel_hdmi->hdmi_reg, temp);
921 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000922 }
Eric Anholt7d573822009-01-02 13:33:00 -0800923}
924
Ville Syrjälä40478452014-03-27 11:08:45 +0200925static int hdmi_portclock_limit(struct intel_hdmi *hdmi, bool respect_dvi_limit)
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200926{
927 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
928
Ville Syrjälä40478452014-03-27 11:08:45 +0200929 if ((respect_dvi_limit && !hdmi->has_hdmi_sink) || IS_G4X(dev))
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200930 return 165000;
Damien Lespiaue3c33572013-11-02 21:07:51 -0700931 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200932 return 300000;
933 else
934 return 225000;
935}
936
Damien Lespiauc19de8e2013-11-28 15:29:18 +0000937static enum drm_mode_status
938intel_hdmi_mode_valid(struct drm_connector *connector,
939 struct drm_display_mode *mode)
Eric Anholt7d573822009-01-02 13:33:00 -0800940{
Clint Taylor697c4072014-09-02 17:03:36 -0700941 int clock = mode->clock;
942
943 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
944 clock *= 2;
945
946 if (clock > hdmi_portclock_limit(intel_attached_hdmi(connector),
947 true))
Eric Anholt7d573822009-01-02 13:33:00 -0800948 return MODE_CLOCK_HIGH;
Clint Taylor697c4072014-09-02 17:03:36 -0700949 if (clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200950 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800951
952 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
953 return MODE_NO_DBLESCAN;
954
955 return MODE_OK;
956}
957
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200958static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
Ville Syrjälä71800632014-03-03 16:15:29 +0200959{
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200960 struct drm_device *dev = crtc_state->base.crtc->dev;
961 struct drm_atomic_state *state;
Ville Syrjälä71800632014-03-03 16:15:29 +0200962 struct intel_encoder *encoder;
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200963 struct drm_connector_state *connector_state;
Ville Syrjälä71800632014-03-03 16:15:29 +0200964 int count = 0, count_hdmi = 0;
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200965 int i;
Ville Syrjälä71800632014-03-03 16:15:29 +0200966
Sonika Jindalf227ae92014-07-21 15:23:45 +0530967 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä71800632014-03-03 16:15:29 +0200968 return false;
969
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200970 state = crtc_state->base.state;
971
972 for (i = 0; i < state->num_connector; i++) {
973 if (!state->connectors[i])
Ville Syrjälä71800632014-03-03 16:15:29 +0200974 continue;
975
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +0200976 connector_state = state->connector_states[i];
977 if (connector_state->crtc != crtc_state->base.crtc)
978 continue;
979
980 encoder = to_intel_encoder(connector_state->best_encoder);
981
Ville Syrjälä71800632014-03-03 16:15:29 +0200982 count_hdmi += encoder->type == INTEL_OUTPUT_HDMI;
983 count++;
984 }
985
986 /*
987 * HDMI 12bpc affects the clocks, so it's only possible
988 * when not cloning with other encoder types.
989 */
990 return count_hdmi > 0 && count_hdmi == count;
991}
992
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100993bool intel_hdmi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200994 struct intel_crtc_state *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -0800995{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100996 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
997 struct drm_device *dev = encoder->base.dev;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200998 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
999 int clock_12bpc = pipe_config->base.adjusted_mode.crtc_clock * 3 / 2;
Ville Syrjälä40478452014-03-27 11:08:45 +02001000 int portclock_limit = hdmi_portclock_limit(intel_hdmi, false);
Daniel Vettere29c22c2013-02-21 00:00:16 +01001001 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001002
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001003 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1004
Jesse Barnese43823e2014-11-05 14:26:08 -08001005 if (pipe_config->has_hdmi_sink)
1006 pipe_config->has_infoframe = true;
1007
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001008 if (intel_hdmi->color_range_auto) {
1009 /* See CEA-861-E - 5.1 Default Encoding Parameters */
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001010 if (pipe_config->has_hdmi_sink &&
Thierry Reding18316c82012-12-20 15:41:44 +01001011 drm_match_cea_mode(adjusted_mode) > 1)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -03001012 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001013 else
1014 intel_hdmi->color_range = 0;
1015 }
1016
Clint Taylor697c4072014-09-02 17:03:36 -07001017 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1018 pipe_config->pixel_multiplier = 2;
1019 }
1020
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001021 if (intel_hdmi->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +01001022 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001023
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001024 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
1025 pipe_config->has_pch_encoder = true;
1026
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001027 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1028 pipe_config->has_audio = true;
1029
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001030 /*
1031 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1032 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +02001033 * outputs. We also need to check that the higher clock still fits
1034 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001035 */
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001036 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
Ville Syrjälä71800632014-03-03 16:15:29 +02001037 clock_12bpc <= portclock_limit &&
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001038 hdmi_12bpc_possible(pipe_config)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001039 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1040 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +02001041
1042 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +02001043 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001044 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001045 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1046 desired_bpp = 8*3;
1047 }
1048
1049 if (!pipe_config->bw_constrained) {
1050 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1051 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001052 }
1053
Damien Lespiau241bfc32013-09-25 16:45:37 +01001054 if (adjusted_mode->crtc_clock > portclock_limit) {
Daniel Vetter325b9d02013-04-19 11:24:33 +02001055 DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
1056 return false;
1057 }
1058
Eric Anholt7d573822009-01-02 13:33:00 -08001059 return true;
1060}
1061
Chris Wilson953ece6972014-09-02 20:04:01 +01001062static void
1063intel_hdmi_unset_edid(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001064{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001065 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02001066
Chris Wilsonea5b2132010-08-04 13:50:23 +01001067 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +08001068 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +02001069 intel_hdmi->rgb_quant_range_selectable = false;
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +08001070
Chris Wilson953ece6972014-09-02 20:04:01 +01001071 kfree(to_intel_connector(connector)->detect_edid);
1072 to_intel_connector(connector)->detect_edid = NULL;
Ma Ling9dff6af2009-04-02 13:13:26 +08001073}
1074
Chris Wilson953ece6972014-09-02 20:04:01 +01001075static bool
1076intel_hdmi_set_edid(struct drm_connector *connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001077{
Chris Wilson953ece6972014-09-02 20:04:01 +01001078 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1079 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1080 struct intel_encoder *intel_encoder =
1081 &hdmi_to_dig_port(intel_hdmi)->base;
Imre Deak671dedd2014-03-05 16:20:53 +02001082 enum intel_display_power_domain power_domain;
Chris Wilson953ece6972014-09-02 20:04:01 +01001083 struct edid *edid;
1084 bool connected = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001085
Imre Deak671dedd2014-03-05 16:20:53 +02001086 power_domain = intel_display_port_power_domain(intel_encoder);
1087 intel_display_power_get(dev_priv, power_domain);
1088
Chris Wilson953ece6972014-09-02 20:04:01 +01001089 edid = drm_get_edid(connector,
1090 intel_gmbus_get_adapter(dev_priv,
1091 intel_hdmi->ddc_bus));
Imre Deak671dedd2014-03-05 16:20:53 +02001092
1093 intel_display_power_put(dev_priv, power_domain);
1094
Chris Wilson953ece6972014-09-02 20:04:01 +01001095 to_intel_connector(connector)->detect_edid = edid;
1096 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1097 intel_hdmi->rgb_quant_range_selectable =
1098 drm_rgb_quant_range_selectable(edid);
1099
1100 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1101 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1102 intel_hdmi->has_audio =
1103 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1104
1105 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1106 intel_hdmi->has_hdmi_sink =
1107 drm_detect_hdmi_monitor(edid);
1108
1109 connected = true;
1110 }
1111
1112 return connected;
1113}
1114
1115static enum drm_connector_status
1116intel_hdmi_detect(struct drm_connector *connector, bool force)
1117{
1118 enum drm_connector_status status;
1119
1120 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1121 connector->base.id, connector->name);
1122
1123 intel_hdmi_unset_edid(connector);
1124
1125 if (intel_hdmi_set_edid(connector)) {
1126 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1127
1128 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1129 status = connector_status_connected;
1130 } else
1131 status = connector_status_disconnected;
1132
1133 return status;
1134}
1135
1136static void
1137intel_hdmi_force(struct drm_connector *connector)
1138{
1139 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1140
1141 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1142 connector->base.id, connector->name);
1143
1144 intel_hdmi_unset_edid(connector);
1145
1146 if (connector->status != connector_status_connected)
1147 return;
1148
1149 intel_hdmi_set_edid(connector);
1150 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1151}
1152
1153static int intel_hdmi_get_modes(struct drm_connector *connector)
1154{
1155 struct edid *edid;
1156
1157 edid = to_intel_connector(connector)->detect_edid;
1158 if (edid == NULL)
1159 return 0;
1160
1161 return intel_connector_update_modes(connector, edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001162}
1163
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001164static bool
1165intel_hdmi_detect_audio(struct drm_connector *connector)
1166{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001167 bool has_audio = false;
Chris Wilson953ece6972014-09-02 20:04:01 +01001168 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001169
Chris Wilson953ece6972014-09-02 20:04:01 +01001170 edid = to_intel_connector(connector)->detect_edid;
1171 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1172 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02001173
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001174 return has_audio;
1175}
1176
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001177static int
1178intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001179 struct drm_property *property,
1180 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001181{
1182 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001183 struct intel_digital_port *intel_dig_port =
1184 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +00001185 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001186 int ret;
1187
Rob Clark662595d2012-10-11 20:36:04 -05001188 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001189 if (ret)
1190 return ret;
1191
Chris Wilson3f43c482011-05-12 22:17:24 +01001192 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001193 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001194 bool has_audio;
1195
1196 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001197 return 0;
1198
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001199 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001200
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001201 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001202 has_audio = intel_hdmi_detect_audio(connector);
1203 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001204 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001205
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001206 if (i == HDMI_AUDIO_OFF_DVI)
1207 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001208
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001209 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001210 goto done;
1211 }
1212
Chris Wilsone953fd72011-02-21 22:23:52 +00001213 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001214 bool old_auto = intel_hdmi->color_range_auto;
1215 uint32_t old_range = intel_hdmi->color_range;
1216
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001217 switch (val) {
1218 case INTEL_BROADCAST_RGB_AUTO:
1219 intel_hdmi->color_range_auto = true;
1220 break;
1221 case INTEL_BROADCAST_RGB_FULL:
1222 intel_hdmi->color_range_auto = false;
1223 intel_hdmi->color_range = 0;
1224 break;
1225 case INTEL_BROADCAST_RGB_LIMITED:
1226 intel_hdmi->color_range_auto = false;
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -03001227 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001228 break;
1229 default:
1230 return -EINVAL;
1231 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001232
1233 if (old_auto == intel_hdmi->color_range_auto &&
1234 old_range == intel_hdmi->color_range)
1235 return 0;
1236
Chris Wilsone953fd72011-02-21 22:23:52 +00001237 goto done;
1238 }
1239
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301240 if (property == connector->dev->mode_config.aspect_ratio_property) {
1241 switch (val) {
1242 case DRM_MODE_PICTURE_ASPECT_NONE:
1243 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1244 break;
1245 case DRM_MODE_PICTURE_ASPECT_4_3:
1246 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
1247 break;
1248 case DRM_MODE_PICTURE_ASPECT_16_9:
1249 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
1250 break;
1251 default:
1252 return -EINVAL;
1253 }
1254 goto done;
1255 }
1256
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001257 return -EINVAL;
1258
1259done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001260 if (intel_dig_port->base.base.crtc)
1261 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001262
1263 return 0;
1264}
1265
Jesse Barnes13732ba2014-04-05 11:51:35 -07001266static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1267{
1268 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1269 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1270 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001271 &intel_crtc->config->base.adjusted_mode;
Jesse Barnes13732ba2014-04-05 11:51:35 -07001272
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001273 intel_hdmi_prepare(encoder);
1274
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001275 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001276 intel_crtc->config->has_hdmi_sink,
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001277 adjusted_mode);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001278}
1279
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001280static void vlv_hdmi_pre_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001281{
1282 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001283 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001284 struct drm_device *dev = encoder->base.dev;
1285 struct drm_i915_private *dev_priv = dev->dev_private;
1286 struct intel_crtc *intel_crtc =
1287 to_intel_crtc(encoder->base.crtc);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001288 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001289 &intel_crtc->config->base.adjusted_mode;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001290 enum dpio_channel port = vlv_dport_to_channel(dport);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001291 int pipe = intel_crtc->pipe;
1292 u32 val;
1293
Jesse Barnes89b667f2013-04-18 14:51:36 -07001294 /* Enable clock channels for this port */
Chris Wilson0980a602013-07-26 19:57:35 +01001295 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001296 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001297 val = 0;
1298 if (pipe)
1299 val |= (1<<21);
1300 else
1301 val &= ~(1<<21);
1302 val |= 0x001000c4;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001303 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001304
1305 /* HDMI 1.0V-2dB */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001306 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0);
1307 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), 0x2b245f5f);
1308 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port), 0x5578b83a);
1309 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0c782040);
1310 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), 0x2b247878);
1311 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1312 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
1313 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001314
1315 /* Program lane clock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001316 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1317 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Chris Wilson0980a602013-07-26 19:57:35 +01001318 mutex_unlock(&dev_priv->dpio_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001319
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001320 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001321 intel_crtc->config->has_hdmi_sink,
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001322 adjusted_mode);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001323
Jani Nikulab76cf762013-07-30 12:20:31 +03001324 intel_enable_hdmi(encoder);
1325
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001326 vlv_wait_port_ready(dev_priv, dport);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001327}
1328
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001329static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001330{
1331 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1332 struct drm_device *dev = encoder->base.dev;
1333 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001334 struct intel_crtc *intel_crtc =
1335 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001336 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001337 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001338
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001339 intel_hdmi_prepare(encoder);
1340
Jesse Barnes89b667f2013-04-18 14:51:36 -07001341 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001342 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001343 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001344 DPIO_PCS_TX_LANE2_RESET |
1345 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001346 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001347 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1348 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1349 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1350 DPIO_PCS_CLK_SOFT_RESET);
1351
1352 /* Fix up inter-pair skew failure */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001353 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1354 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1355 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001356
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001357 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
1358 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
Chris Wilson0980a602013-07-26 19:57:35 +01001359 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001360}
1361
Ville Syrjälä9197c882014-04-09 13:29:05 +03001362static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1363{
1364 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1365 struct drm_device *dev = encoder->base.dev;
1366 struct drm_i915_private *dev_priv = dev->dev_private;
1367 struct intel_crtc *intel_crtc =
1368 to_intel_crtc(encoder->base.crtc);
1369 enum dpio_channel ch = vlv_dport_to_channel(dport);
1370 enum pipe pipe = intel_crtc->pipe;
1371 u32 val;
1372
Ville Syrjälä625695f2014-06-28 02:04:02 +03001373 intel_hdmi_prepare(encoder);
1374
Ville Syrjälä9197c882014-04-09 13:29:05 +03001375 mutex_lock(&dev_priv->dpio_lock);
1376
Ville Syrjäläb9e5ac32014-05-27 16:30:18 +03001377 /* program left/right clock distribution */
1378 if (pipe != PIPE_B) {
1379 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
1380 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
1381 if (ch == DPIO_CH0)
1382 val |= CHV_BUFLEFTENA1_FORCE;
1383 if (ch == DPIO_CH1)
1384 val |= CHV_BUFRIGHTENA1_FORCE;
1385 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
1386 } else {
1387 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
1388 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
1389 if (ch == DPIO_CH0)
1390 val |= CHV_BUFLEFTENA2_FORCE;
1391 if (ch == DPIO_CH1)
1392 val |= CHV_BUFRIGHTENA2_FORCE;
1393 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
1394 }
1395
Ville Syrjälä9197c882014-04-09 13:29:05 +03001396 /* program clock channel usage */
1397 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
1398 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
1399 if (pipe != PIPE_B)
1400 val &= ~CHV_PCS_USEDCLKCHANNEL;
1401 else
1402 val |= CHV_PCS_USEDCLKCHANNEL;
1403 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
1404
1405 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
1406 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
1407 if (pipe != PIPE_B)
1408 val &= ~CHV_PCS_USEDCLKCHANNEL;
1409 else
1410 val |= CHV_PCS_USEDCLKCHANNEL;
1411 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
1412
1413 /*
1414 * This a a bit weird since generally CL
1415 * matches the pipe, but here we need to
1416 * pick the CL based on the port.
1417 */
1418 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
1419 if (pipe != PIPE_B)
1420 val &= ~CHV_CMN_USEDCLKCHANNEL;
1421 else
1422 val |= CHV_CMN_USEDCLKCHANNEL;
1423 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
1424
1425 mutex_unlock(&dev_priv->dpio_lock);
1426}
1427
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001428static void vlv_hdmi_post_disable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001429{
1430 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1431 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001432 struct intel_crtc *intel_crtc =
1433 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001434 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001435 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001436
1437 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1438 mutex_lock(&dev_priv->dpio_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001439 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1440 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001441 mutex_unlock(&dev_priv->dpio_lock);
1442}
1443
Ville Syrjälä580d3812014-04-09 13:29:00 +03001444static void chv_hdmi_post_disable(struct intel_encoder *encoder)
1445{
1446 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1447 struct drm_device *dev = encoder->base.dev;
1448 struct drm_i915_private *dev_priv = dev->dev_private;
1449 struct intel_crtc *intel_crtc =
1450 to_intel_crtc(encoder->base.crtc);
1451 enum dpio_channel ch = vlv_dport_to_channel(dport);
1452 enum pipe pipe = intel_crtc->pipe;
1453 u32 val;
1454
1455 mutex_lock(&dev_priv->dpio_lock);
1456
1457 /* Propagate soft reset to data lane reset */
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001458 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
Ville Syrjäläd2152b22014-04-28 14:15:24 +03001459 val |= CHV_PCS_REQ_SOFTRESET_EN;
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001460 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
Ville Syrjäläd2152b22014-04-28 14:15:24 +03001461
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001462 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
1463 val |= CHV_PCS_REQ_SOFTRESET_EN;
1464 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
1465
1466 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
Ville Syrjälä580d3812014-04-09 13:29:00 +03001467 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001468 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
1469
1470 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
1471 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
1472 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001473
1474 mutex_unlock(&dev_priv->dpio_lock);
1475}
1476
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001477static void chv_hdmi_pre_enable(struct intel_encoder *encoder)
1478{
1479 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001480 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001481 struct drm_device *dev = encoder->base.dev;
1482 struct drm_i915_private *dev_priv = dev->dev_private;
1483 struct intel_crtc *intel_crtc =
1484 to_intel_crtc(encoder->base.crtc);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001485 struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001486 &intel_crtc->config->base.adjusted_mode;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001487 enum dpio_channel ch = vlv_dport_to_channel(dport);
1488 int pipe = intel_crtc->pipe;
1489 int data, i;
1490 u32 val;
1491
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001492 mutex_lock(&dev_priv->dpio_lock);
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001493
Ville Syrjälä570e2a72014-08-18 14:42:46 +03001494 /* allow hardware to manage TX FIFO reset source */
1495 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
1496 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
1497 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
1498
1499 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
1500 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
1501 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
1502
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001503 /* Deassert soft data lane reset*/
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001504 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
Ville Syrjäläd2152b22014-04-28 14:15:24 +03001505 val |= CHV_PCS_REQ_SOFTRESET_EN;
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001506 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
Ville Syrjäläd2152b22014-04-28 14:15:24 +03001507
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001508 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
1509 val |= CHV_PCS_REQ_SOFTRESET_EN;
1510 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
1511
1512 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001513 val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Ville Syrjälä97fd4d52014-04-09 13:29:02 +03001514 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
1515
1516 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
1517 val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
1518 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001519
1520 /* Program Tx latency optimal setting */
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001521 for (i = 0; i < 4; i++) {
1522 /* Set the latency optimal bit */
1523 data = (i == 1) ? 0x0 : 0x6;
1524 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW11(ch, i),
1525 data << DPIO_FRC_LATENCY_SHFIT);
1526
1527 /* Set the upar bit */
1528 data = (i == 1) ? 0x0 : 0x1;
1529 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
1530 data << DPIO_UPAR_SHIFT);
1531 }
1532
1533 /* Data lane stagger programming */
1534 /* FIXME: Fix up value only after power analysis */
1535
1536 /* Clear calc init */
Ville Syrjälä1966e592014-04-09 13:29:04 +03001537 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
1538 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001539 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
1540 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03001541 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
1542
1543 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
1544 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001545 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
1546 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03001547 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001548
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001549 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
1550 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
1551 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
1552 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
1553
1554 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
1555 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
1556 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
1557 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
1558
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001559 /* FIXME: Program the support xxx V-dB */
1560 /* Use 800mV-0dB */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001561 for (i = 0; i < 4; i++) {
1562 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
1563 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
1564 val |= 128 << DPIO_SWING_DEEMPH9P5_SHIFT;
1565 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
1566 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001567
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001568 for (i = 0; i < 4; i++) {
1569 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
Ville Syrjälä1fb44502014-06-28 02:04:03 +03001570 val &= ~DPIO_SWING_MARGIN000_MASK;
1571 val |= 102 << DPIO_SWING_MARGIN000_SHIFT;
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001572 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
1573 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001574
1575 /* Disable unique transition scale */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001576 for (i = 0; i < 4; i++) {
1577 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
1578 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
1579 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
1580 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001581
1582 /* Additional steps for 1200mV-0dB */
1583#if 0
1584 val = vlv_dpio_read(dev_priv, pipe, VLV_TX_DW3(ch));
1585 if (ch)
1586 val |= DPIO_TX_UNIQ_TRANS_SCALE_CH1;
1587 else
1588 val |= DPIO_TX_UNIQ_TRANS_SCALE_CH0;
1589 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(ch), val);
1590
1591 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(ch),
1592 vlv_dpio_read(dev_priv, pipe, VLV_TX_DW2(ch)) |
1593 (0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT));
1594#endif
1595 /* Start swing calculation */
Ville Syrjälä1966e592014-04-09 13:29:04 +03001596 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
1597 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
1598 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
1599
1600 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
1601 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
1602 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001603
1604 /* LRC Bypass */
1605 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
1606 val |= DPIO_LRC_BYPASS;
1607 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, val);
1608
1609 mutex_unlock(&dev_priv->dpio_lock);
1610
Clint Taylorb4eb1562014-11-21 11:13:02 -08001611 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001612 intel_crtc->config->has_hdmi_sink,
Clint Taylorb4eb1562014-11-21 11:13:02 -08001613 adjusted_mode);
1614
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001615 intel_enable_hdmi(encoder);
1616
1617 vlv_wait_port_ready(dev_priv, dport);
1618}
1619
Eric Anholt7d573822009-01-02 13:33:00 -08001620static void intel_hdmi_destroy(struct drm_connector *connector)
1621{
Chris Wilson10e972d2014-09-04 21:43:45 +01001622 kfree(to_intel_connector(connector)->detect_edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001623 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001624 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001625}
1626
Eric Anholt7d573822009-01-02 13:33:00 -08001627static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001628 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001629 .detect = intel_hdmi_detect,
Chris Wilson953ece6972014-09-02 20:04:01 +01001630 .force = intel_hdmi_force,
Eric Anholt7d573822009-01-02 13:33:00 -08001631 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001632 .set_property = intel_hdmi_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08001633 .atomic_get_property = intel_connector_atomic_get_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001634 .destroy = intel_hdmi_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08001635 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001636 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Eric Anholt7d573822009-01-02 13:33:00 -08001637};
1638
1639static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1640 .get_modes = intel_hdmi_get_modes,
1641 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001642 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001643};
1644
Eric Anholt7d573822009-01-02 13:33:00 -08001645static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001646 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001647};
1648
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001649static void
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301650intel_attach_aspect_ratio_property(struct drm_connector *connector)
1651{
1652 if (!drm_mode_create_aspect_ratio_property(connector->dev))
1653 drm_object_attach_property(&connector->base,
1654 connector->dev->mode_config.aspect_ratio_property,
1655 DRM_MODE_PICTURE_ASPECT_NONE);
1656}
1657
1658static void
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001659intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1660{
Chris Wilson3f43c482011-05-12 22:17:24 +01001661 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001662 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001663 intel_hdmi->color_range_auto = true;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301664 intel_attach_aspect_ratio_property(connector);
1665 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001666}
1667
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001668void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1669 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001670{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001671 struct drm_connector *connector = &intel_connector->base;
1672 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1673 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1674 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08001675 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001676 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001677
Eric Anholt7d573822009-01-02 13:33:00 -08001678 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001679 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001680 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1681
Peter Rossc3febcc2012-01-28 14:49:26 +01001682 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001683 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01001684 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001685
Daniel Vetter08d644a2012-07-12 20:19:59 +02001686 switch (port) {
1687 case PORT_B:
Jani Nikula4c272832015-04-01 10:58:05 +03001688 if (IS_BROXTON(dev_priv))
1689 intel_hdmi->ddc_bus = GMBUS_PIN_1_BXT;
1690 else
1691 intel_hdmi->ddc_bus = GMBUS_PIN_DPB;
Egbert Eich1d843f92013-02-25 12:06:49 -05001692 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001693 break;
1694 case PORT_C:
Jani Nikula4c272832015-04-01 10:58:05 +03001695 if (IS_BROXTON(dev_priv))
1696 intel_hdmi->ddc_bus = GMBUS_PIN_2_BXT;
1697 else
1698 intel_hdmi->ddc_bus = GMBUS_PIN_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05001699 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001700 break;
1701 case PORT_D:
Jani Nikula4c272832015-04-01 10:58:05 +03001702 if (WARN_ON(IS_BROXTON(dev_priv)))
1703 intel_hdmi->ddc_bus = GMBUS_PIN_DISABLED;
1704 else if (IS_CHERRYVIEW(dev_priv))
Jani Nikula988c7012015-03-27 00:20:19 +02001705 intel_hdmi->ddc_bus = GMBUS_PIN_DPD_CHV;
Ville Syrjäläc0c35322014-04-09 13:28:52 +03001706 else
Jani Nikula988c7012015-03-27 00:20:19 +02001707 intel_hdmi->ddc_bus = GMBUS_PIN_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05001708 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001709 break;
1710 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05001711 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001712 /* Internal port only for eDP. */
1713 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001714 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001715 }
Eric Anholt7d573822009-01-02 13:33:00 -08001716
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001717 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001718 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001719 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001720 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
Sonika Jindalb98856a2014-07-22 11:13:46 +05301721 } else if (IS_G4X(dev)) {
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001722 intel_hdmi->write_infoframe = g4x_write_infoframe;
1723 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001724 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001725 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001726 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001727 intel_hdmi->set_infoframes = hsw_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001728 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001729 } else if (HAS_PCH_IBX(dev)) {
1730 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001731 intel_hdmi->set_infoframes = ibx_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001732 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001733 } else {
1734 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001735 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001736 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301737 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001738
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001739 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001740 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1741 else
1742 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +02001743 intel_connector->unregister = intel_connector_unregister;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001744
1745 intel_hdmi_add_properties(intel_hdmi, connector);
1746
1747 intel_connector_attach_encoder(intel_connector, intel_encoder);
Thomas Wood34ea3d32014-05-29 16:57:41 +01001748 drm_connector_register(connector);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001749
1750 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1751 * 0xd. Failure to do so will result in spurious interrupts being
1752 * generated on the port when a cable is not attached.
1753 */
1754 if (IS_G4X(dev) && !IS_GM45(dev)) {
1755 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1756 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1757 }
1758}
1759
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001760void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001761{
1762 struct intel_digital_port *intel_dig_port;
1763 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001764 struct intel_connector *intel_connector;
1765
Daniel Vetterb14c5672013-09-19 12:18:32 +02001766 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001767 if (!intel_dig_port)
1768 return;
1769
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03001770 intel_connector = intel_connector_alloc();
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001771 if (!intel_connector) {
1772 kfree(intel_dig_port);
1773 return;
1774 }
1775
1776 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001777
1778 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1779 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001780
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001781 intel_encoder->compute_config = intel_hdmi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001782 intel_encoder->disable = intel_disable_hdmi;
1783 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001784 intel_encoder->get_config = intel_hdmi_get_config;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001785 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03001786 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001787 intel_encoder->pre_enable = chv_hdmi_pre_enable;
1788 intel_encoder->enable = vlv_enable_hdmi;
Ville Syrjälä580d3812014-04-09 13:29:00 +03001789 intel_encoder->post_disable = chv_hdmi_post_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001790 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001791 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
1792 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001793 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001794 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001795 } else {
Jesse Barnes13732ba2014-04-05 11:51:35 -07001796 intel_encoder->pre_enable = intel_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001797 intel_encoder->enable = intel_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001798 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001799
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001800 intel_encoder->type = INTEL_OUTPUT_HDMI;
Ville Syrjälä882ec382014-04-28 14:07:43 +03001801 if (IS_CHERRYVIEW(dev)) {
1802 if (port == PORT_D)
1803 intel_encoder->crtc_mask = 1 << 2;
1804 else
1805 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1806 } else {
1807 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1808 }
Ville Syrjälä301ea742014-03-03 16:15:30 +02001809 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
Ville Syrjäläc6f14952014-03-03 16:15:31 +02001810 /*
1811 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
1812 * to work on real hardware. And since g4x can send infoframes to
1813 * only one port anyway, nothing is lost by allowing it.
1814 */
1815 if (IS_G4X(dev))
1816 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -08001817
Paulo Zanoni174edf12012-10-26 19:05:50 -02001818 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001819 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001820 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001821
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001822 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001823}