blob: 9eafa191cee2e33c34942006ece7b0b8374cbc8f [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
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300116static u32 hsw_dip_data_reg(struct drm_i915_private *dev_priv,
117 enum transcoder cpu_transcoder,
118 enum hdmi_infoframe_type type,
119 int i)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300120{
Damien Lespiau178f7362013-08-06 20:32:18 +0100121 switch (type) {
122 case HDMI_INFOFRAME_TYPE_AVI:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300123 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
Damien Lespiau178f7362013-08-06 20:32:18 +0100124 case HDMI_INFOFRAME_TYPE_SPD:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300125 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100126 case HDMI_INFOFRAME_TYPE_VENDOR:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300127 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300128 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100129 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300130 return 0;
131 }
132}
133
Daniel Vettera3da1df2012-05-08 15:19:06 +0200134static void g4x_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100135 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200136 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700137{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200138 const uint32_t *data = frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200139 struct drm_device *dev = encoder->dev;
140 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300141 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100142 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200143
Paulo Zanoni822974a2012-05-28 16:42:51 -0300144 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
145
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300146 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100147 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700148
Damien Lespiau178f7362013-08-06 20:32:18 +0100149 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300150
151 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300153 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700154 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200155 I915_WRITE(VIDEO_DIP_DATA, *data);
156 data++;
157 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300158 /* Write every possible data byte to force correct ECC calculation. */
159 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
160 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300161 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200162
Damien Lespiau178f7362013-08-06 20:32:18 +0100163 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300164 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200165 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700166
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300167 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300168 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200169}
170
Jesse Barnese43823e2014-11-05 14:26:08 -0800171static bool g4x_infoframe_enabled(struct drm_encoder *encoder)
172{
173 struct drm_device *dev = encoder->dev;
174 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800175 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800176 u32 val = I915_READ(VIDEO_DIP_CTL);
177
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300178 if ((val & VIDEO_DIP_ENABLE) == 0)
179 return false;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800180
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300181 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
182 return false;
183
184 return val & (VIDEO_DIP_ENABLE_AVI |
185 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Jesse Barnese43823e2014-11-05 14:26:08 -0800186}
187
Paulo Zanonifdf12502012-05-04 17:18:24 -0300188static void ibx_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100189 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200190 const void *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300191{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200192 const uint32_t *data = frame;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300193 struct drm_device *dev = encoder->dev;
194 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300195 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100196 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300197 u32 val = I915_READ(reg);
198
Paulo Zanoni822974a2012-05-28 16:42:51 -0300199 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
200
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100202 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300203
Damien Lespiau178f7362013-08-06 20:32:18 +0100204 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300205
206 I915_WRITE(reg, val);
207
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300208 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300209 for (i = 0; i < len; i += 4) {
210 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
211 data++;
212 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300213 /* Write every possible data byte to force correct ECC calculation. */
214 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
215 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300216 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300217
Damien Lespiau178f7362013-08-06 20:32:18 +0100218 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300219 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200220 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300221
222 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300223 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300224}
225
Jesse Barnese43823e2014-11-05 14:26:08 -0800226static bool ibx_infoframe_enabled(struct drm_encoder *encoder)
227{
228 struct drm_device *dev = encoder->dev;
229 struct drm_i915_private *dev_priv = dev->dev_private;
230 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jani Nikula052f62f2015-04-29 15:30:07 +0300231 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800232 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
233 u32 val = I915_READ(reg);
234
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300235 if ((val & VIDEO_DIP_ENABLE) == 0)
236 return false;
Jani Nikula052f62f2015-04-29 15:30:07 +0300237
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300238 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
239 return false;
240
241 return val & (VIDEO_DIP_ENABLE_AVI |
242 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
243 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800244}
245
Paulo Zanonifdf12502012-05-04 17:18:24 -0300246static void cpt_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100247 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200248 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700249{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200250 const uint32_t *data = frame;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700251 struct drm_device *dev = encoder->dev;
252 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300253 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100254 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300255 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700256
Paulo Zanoni822974a2012-05-28 16:42:51 -0300257 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
258
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530259 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100260 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700261
Paulo Zanoniecb97852012-05-04 17:18:21 -0300262 /* The DIP control register spec says that we need to update the AVI
263 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100264 if (type != HDMI_INFOFRAME_TYPE_AVI)
265 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300266
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300267 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700268
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300269 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700270 for (i = 0; i < len; i += 4) {
271 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
272 data++;
273 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300274 /* Write every possible data byte to force correct ECC calculation. */
275 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
276 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300277 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700278
Damien Lespiau178f7362013-08-06 20:32:18 +0100279 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300280 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200281 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700282
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300283 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300284 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700285}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700286
Jesse Barnese43823e2014-11-05 14:26:08 -0800287static bool cpt_infoframe_enabled(struct drm_encoder *encoder)
288{
289 struct drm_device *dev = encoder->dev;
290 struct drm_i915_private *dev_priv = dev->dev_private;
291 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
292 int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
293 u32 val = I915_READ(reg);
294
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300295 if ((val & VIDEO_DIP_ENABLE) == 0)
296 return false;
297
298 return val & (VIDEO_DIP_ENABLE_AVI |
299 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
300 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800301}
302
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700303static void vlv_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100304 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200305 const void *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700306{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200307 const uint32_t *data = frame;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700308 struct drm_device *dev = encoder->dev;
309 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300310 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100311 int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300312 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700313
Paulo Zanoni822974a2012-05-28 16:42:51 -0300314 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
315
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700316 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100317 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700318
Damien Lespiau178f7362013-08-06 20:32:18 +0100319 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300320
321 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700322
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300323 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700324 for (i = 0; i < len; i += 4) {
325 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
326 data++;
327 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300328 /* Write every possible data byte to force correct ECC calculation. */
329 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
330 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300331 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700332
Damien Lespiau178f7362013-08-06 20:32:18 +0100333 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300334 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200335 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700336
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300337 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300338 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700339}
340
Jesse Barnese43823e2014-11-05 14:26:08 -0800341static bool vlv_infoframe_enabled(struct drm_encoder *encoder)
342{
343 struct drm_device *dev = encoder->dev;
344 struct drm_i915_private *dev_priv = dev->dev_private;
345 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnes535afa22015-04-15 16:52:29 -0700346 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800347 int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
348 u32 val = I915_READ(reg);
349
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300350 if ((val & VIDEO_DIP_ENABLE) == 0)
351 return false;
Jesse Barnes535afa22015-04-15 16:52:29 -0700352
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300353 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
354 return false;
355
356 return val & (VIDEO_DIP_ENABLE_AVI |
357 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
358 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800359}
360
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300361static void hsw_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100362 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200363 const void *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300364{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200365 const uint32_t *data = frame;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300366 struct drm_device *dev = encoder->dev;
367 struct drm_i915_private *dev_priv = dev->dev_private;
368 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300369 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
370 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100371 u32 data_reg;
372 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300373 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300374
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300375 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300376 if (data_reg == 0)
377 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300378
Damien Lespiau178f7362013-08-06 20:32:18 +0100379 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300380 I915_WRITE(ctl_reg, val);
381
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300382 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300383 for (i = 0; i < len; i += 4) {
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300384 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
385 type, i >> 2), *data);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300386 data++;
387 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300388 /* Write every possible data byte to force correct ECC calculation. */
389 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300390 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
391 type, i >> 2), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300392 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300393
Damien Lespiau178f7362013-08-06 20:32:18 +0100394 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300395 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300396 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300397}
398
Jesse Barnese43823e2014-11-05 14:26:08 -0800399static bool hsw_infoframe_enabled(struct drm_encoder *encoder)
400{
401 struct drm_device *dev = encoder->dev;
402 struct drm_i915_private *dev_priv = dev->dev_private;
403 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200404 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800405 u32 val = I915_READ(ctl_reg);
406
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300407 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
408 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
409 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
Jesse Barnese43823e2014-11-05 14:26:08 -0800410}
411
Damien Lespiau5adaea72013-08-06 20:32:19 +0100412/*
413 * The data we write to the DIP data buffer registers is 1 byte bigger than the
414 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
415 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
416 * used for both technologies.
417 *
418 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
419 * DW1: DB3 | DB2 | DB1 | DB0
420 * DW2: DB7 | DB6 | DB5 | DB4
421 * DW3: ...
422 *
423 * (HB is Header Byte, DB is Data Byte)
424 *
425 * The hdmi pack() functions don't know about that hardware specific hole so we
426 * trick them by giving an offset into the buffer and moving back the header
427 * bytes by one.
428 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100429static void intel_write_infoframe(struct drm_encoder *encoder,
430 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700431{
432 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100433 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
434 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700435
Damien Lespiau5adaea72013-08-06 20:32:19 +0100436 /* see comment above for the reason for this offset */
437 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
438 if (len < 0)
439 return;
440
441 /* Insert the 'hole' (see big comment above) at position 3 */
442 buffer[0] = buffer[1];
443 buffer[1] = buffer[2];
444 buffer[2] = buffer[3];
445 buffer[3] = 0;
446 len++;
447
448 intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700449}
450
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300451static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300452 const struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700453{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200454 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter50f3b012013-03-27 00:44:56 +0100455 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100456 union hdmi_infoframe frame;
457 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700458
Damien Lespiau5adaea72013-08-06 20:32:19 +0100459 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
460 adjusted_mode);
461 if (ret < 0) {
462 DRM_ERROR("couldn't fill AVI infoframe\n");
463 return;
464 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300465
Ville Syrjäläabedc072013-01-17 16:31:31 +0200466 if (intel_hdmi->rgb_quant_range_selectable) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200467 if (intel_crtc->config->limited_color_range)
Damien Lespiau5adaea72013-08-06 20:32:19 +0100468 frame.avi.quantization_range =
469 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200470 else
Damien Lespiau5adaea72013-08-06 20:32:19 +0100471 frame.avi.quantization_range =
472 HDMI_QUANTIZATION_RANGE_FULL;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200473 }
474
Damien Lespiau9198ee52013-08-06 20:32:24 +0100475 intel_write_infoframe(encoder, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700476}
477
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300478static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700479{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100480 union hdmi_infoframe frame;
481 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700482
Damien Lespiau5adaea72013-08-06 20:32:19 +0100483 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
484 if (ret < 0) {
485 DRM_ERROR("couldn't fill SPD infoframe\n");
486 return;
487 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700488
Damien Lespiau5adaea72013-08-06 20:32:19 +0100489 frame.spd.sdi = HDMI_SPD_SDI_PC;
490
Damien Lespiau9198ee52013-08-06 20:32:24 +0100491 intel_write_infoframe(encoder, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700492}
493
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100494static void
495intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300496 const struct drm_display_mode *adjusted_mode)
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100497{
498 union hdmi_infoframe frame;
499 int ret;
500
501 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
502 adjusted_mode);
503 if (ret < 0)
504 return;
505
506 intel_write_infoframe(encoder, &frame);
507}
508
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300509static void g4x_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200510 bool enable,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300511 const struct drm_display_mode *adjusted_mode)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300512{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300513 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200514 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
515 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300516 u32 reg = VIDEO_DIP_CTL;
517 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200518 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300519
Daniel Vetterafba0182012-06-12 16:36:45 +0200520 assert_hdmi_port_disabled(intel_hdmi);
521
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300522 /* If the registers were not initialized yet, they might be zeroes,
523 * which means we're selecting the AVI DIP and we're setting its
524 * frequency to once. This seems to really confuse the HW and make
525 * things stop working (the register spec says the AVI always needs to
526 * be sent every VSync). So here we avoid writing to the register more
527 * than we need and also explicitly select the AVI DIP and explicitly
528 * set its frequency to every VSync. Avoiding to write it twice seems to
529 * be enough to solve the problem, but being defensive shouldn't hurt us
530 * either. */
531 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
532
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200533 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300534 if (!(val & VIDEO_DIP_ENABLE))
535 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300536 if (port != (val & VIDEO_DIP_PORT_MASK)) {
537 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
538 (val & VIDEO_DIP_PORT_MASK) >> 29);
539 return;
540 }
541 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
542 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300543 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300544 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300545 return;
546 }
547
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300548 if (port != (val & VIDEO_DIP_PORT_MASK)) {
549 if (val & VIDEO_DIP_ENABLE) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300550 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
551 (val & VIDEO_DIP_PORT_MASK) >> 29);
552 return;
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300553 }
554 val &= ~VIDEO_DIP_PORT_MASK;
555 val |= port;
556 }
557
Paulo Zanoni822974a2012-05-28 16:42:51 -0300558 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300559 val &= ~(VIDEO_DIP_ENABLE_AVI |
560 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300561
Paulo Zanonif278d972012-05-28 16:42:50 -0300562 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300563 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300564
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300565 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
566 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100567 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300568}
569
Ville Syrjälä6d674152015-05-05 17:06:20 +0300570static bool hdmi_sink_is_deep_color(struct drm_encoder *encoder)
571{
572 struct drm_device *dev = encoder->dev;
573 struct drm_connector *connector;
574
575 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
576
577 /*
578 * HDMI cloning is only supported on g4x which doesn't
579 * support deep color or GCP infoframes anyway so no
580 * need to worry about multiple HDMI sinks here.
581 */
582 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
583 if (connector->encoder == encoder)
584 return connector->display_info.bpc > 8;
585
586 return false;
587}
588
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300589/*
590 * Determine if default_phase=1 can be indicated in the GCP infoframe.
591 *
592 * From HDMI specification 1.4a:
593 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
594 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
595 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
596 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
597 * phase of 0
598 */
599static bool gcp_default_phase_possible(int pipe_bpp,
600 const struct drm_display_mode *mode)
601{
602 unsigned int pixels_per_group;
603
604 switch (pipe_bpp) {
605 case 30:
606 /* 4 pixels in 5 clocks */
607 pixels_per_group = 4;
608 break;
609 case 36:
610 /* 2 pixels in 3 clocks */
611 pixels_per_group = 2;
612 break;
613 case 48:
614 /* 1 pixel in 2 clocks */
615 pixels_per_group = 1;
616 break;
617 default:
618 /* phase information not relevant for 8bpc */
619 return false;
620 }
621
622 return mode->crtc_hdisplay % pixels_per_group == 0 &&
623 mode->crtc_htotal % pixels_per_group == 0 &&
624 mode->crtc_hblank_start % pixels_per_group == 0 &&
625 mode->crtc_hblank_end % pixels_per_group == 0 &&
626 mode->crtc_hsync_start % pixels_per_group == 0 &&
627 mode->crtc_hsync_end % pixels_per_group == 0 &&
628 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
629 mode->crtc_htotal/2 % pixels_per_group == 0);
630}
631
Ville Syrjälä6d674152015-05-05 17:06:20 +0300632static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder)
633{
634 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
635 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
636 u32 reg, val = 0;
637
638 if (HAS_DDI(dev_priv))
639 reg = HSW_TVIDEO_DIP_GCP(crtc->config->cpu_transcoder);
640 else if (IS_VALLEYVIEW(dev_priv))
641 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
642 else if (HAS_PCH_SPLIT(dev_priv->dev))
643 reg = TVIDEO_DIP_GCP(crtc->pipe);
644 else
645 return false;
646
647 /* Indicate color depth whenever the sink supports deep color */
648 if (hdmi_sink_is_deep_color(encoder))
649 val |= GCP_COLOR_INDICATION;
650
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300651 /* Enable default_phase whenever the display mode is suitably aligned */
652 if (gcp_default_phase_possible(crtc->config->pipe_bpp,
653 &crtc->config->base.adjusted_mode))
654 val |= GCP_DEFAULT_PHASE_ENABLE;
655
Ville Syrjälä6d674152015-05-05 17:06:20 +0300656 I915_WRITE(reg, val);
657
658 return val != 0;
659}
660
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300661static void ibx_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200662 bool enable,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300663 const struct drm_display_mode *adjusted_mode)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300664{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300665 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
666 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200667 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
668 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300669 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
670 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200671 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300672
Daniel Vetterafba0182012-06-12 16:36:45 +0200673 assert_hdmi_port_disabled(intel_hdmi);
674
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300675 /* See the big comment in g4x_set_infoframes() */
676 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
677
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200678 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300679 if (!(val & VIDEO_DIP_ENABLE))
680 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300681 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
682 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
683 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300684 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300685 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300686 return;
687 }
688
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300689 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300690 WARN(val & VIDEO_DIP_ENABLE,
691 "DIP already enabled on port %c\n",
692 (val & VIDEO_DIP_PORT_MASK) >> 29);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300693 val &= ~VIDEO_DIP_PORT_MASK;
694 val |= port;
695 }
696
Paulo Zanoni822974a2012-05-28 16:42:51 -0300697 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300698 val &= ~(VIDEO_DIP_ENABLE_AVI |
699 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
700 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300701
Ville Syrjälä6d674152015-05-05 17:06:20 +0300702 if (intel_hdmi_set_gcp_infoframe(encoder))
703 val |= VIDEO_DIP_ENABLE_GCP;
704
Paulo Zanonif278d972012-05-28 16:42:50 -0300705 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300706 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300707
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300708 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
709 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100710 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300711}
712
713static void cpt_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200714 bool enable,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300715 const struct drm_display_mode *adjusted_mode)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300716{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300717 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
718 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
719 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
720 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
721 u32 val = I915_READ(reg);
722
Daniel Vetterafba0182012-06-12 16:36:45 +0200723 assert_hdmi_port_disabled(intel_hdmi);
724
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300725 /* See the big comment in g4x_set_infoframes() */
726 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
727
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200728 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300729 if (!(val & VIDEO_DIP_ENABLE))
730 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300731 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
732 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
733 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300734 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300735 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300736 return;
737 }
738
Paulo Zanoni822974a2012-05-28 16:42:51 -0300739 /* Set both together, unset both together: see the spec. */
740 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300741 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300742 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300743
Ville Syrjälä6d674152015-05-05 17:06:20 +0300744 if (intel_hdmi_set_gcp_infoframe(encoder))
745 val |= VIDEO_DIP_ENABLE_GCP;
746
Paulo Zanoni822974a2012-05-28 16:42:51 -0300747 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300748 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300749
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300750 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
751 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100752 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300753}
754
755static void vlv_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200756 bool enable,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300757 const struct drm_display_mode *adjusted_mode)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300758{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300759 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700760 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300761 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
762 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
763 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
764 u32 val = I915_READ(reg);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700765 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300766
Daniel Vetterafba0182012-06-12 16:36:45 +0200767 assert_hdmi_port_disabled(intel_hdmi);
768
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300769 /* See the big comment in g4x_set_infoframes() */
770 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
771
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200772 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300773 if (!(val & VIDEO_DIP_ENABLE))
774 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300775 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
776 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
777 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300778 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300779 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300780 return;
781 }
782
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700783 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300784 WARN(val & VIDEO_DIP_ENABLE,
785 "DIP already enabled on port %c\n",
786 (val & VIDEO_DIP_PORT_MASK) >> 29);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700787 val &= ~VIDEO_DIP_PORT_MASK;
788 val |= port;
789 }
790
Paulo Zanoni822974a2012-05-28 16:42:51 -0300791 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300792 val &= ~(VIDEO_DIP_ENABLE_AVI |
793 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
794 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300795
Ville Syrjälä6d674152015-05-05 17:06:20 +0300796 if (intel_hdmi_set_gcp_infoframe(encoder))
797 val |= VIDEO_DIP_ENABLE_GCP;
798
Paulo Zanoni822974a2012-05-28 16:42:51 -0300799 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300800 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300801
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300802 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
803 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100804 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300805}
806
807static void hsw_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200808 bool enable,
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300809 const struct drm_display_mode *adjusted_mode)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300810{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300811 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
812 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
813 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200814 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300815 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300816
Daniel Vetterafba0182012-06-12 16:36:45 +0200817 assert_hdmi_port_disabled(intel_hdmi);
818
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300819 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
820 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
821 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
822
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200823 if (!enable) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300824 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300825 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300826 return;
827 }
828
Ville Syrjälä6d674152015-05-05 17:06:20 +0300829 if (intel_hdmi_set_gcp_infoframe(encoder))
830 val |= VIDEO_DIP_ENABLE_GCP_HSW;
831
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300832 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300833 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300834
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300835 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
836 intel_hdmi_set_spd_infoframe(encoder);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100837 intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300838}
839
Daniel Vetter4cde8a22014-04-24 23:54:56 +0200840static void intel_hdmi_prepare(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800841{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200842 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800843 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200844 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
845 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300846 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300847 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800848
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300849 hdmi_val = SDVO_ENCODING_HDMI;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +0300850 if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
851 hdmi_val |= HDMI_COLOR_RANGE_16_235;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400852 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300853 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400854 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300855 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800856
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200857 if (crtc->config->pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300858 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700859 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300860 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700861
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200862 if (crtc->config->has_hdmi_sink)
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300863 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800864
Jesse Barnes75770562011-10-12 09:01:58 -0700865 if (HAS_PCH_CPT(dev))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200866 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Chon Ming Lee44f37d12014-04-09 13:28:21 +0300867 else if (IS_CHERRYVIEW(dev))
868 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300869 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200870 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800871
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300872 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
873 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800874}
875
Daniel Vetter85234cd2012-07-02 13:27:29 +0200876static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
877 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800878{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200879 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800880 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200881 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Imre Deak6d129be2014-03-05 16:20:54 +0200882 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200883 u32 tmp;
884
Imre Deak6d129be2014-03-05 16:20:54 +0200885 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200886 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200887 return false;
888
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300889 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200890
891 if (!(tmp & SDVO_ENABLE))
892 return false;
893
894 if (HAS_PCH_CPT(dev))
895 *pipe = PORT_TO_PIPE_CPT(tmp);
Ville Syrjälä71485e02014-04-09 13:28:55 +0300896 else if (IS_CHERRYVIEW(dev))
897 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200898 else
899 *pipe = PORT_TO_PIPE(tmp);
900
901 return true;
902}
903
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700904static void intel_hdmi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200905 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700906{
907 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300908 struct drm_device *dev = encoder->base.dev;
909 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700910 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300911 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700912
913 tmp = I915_READ(intel_hdmi->hdmi_reg);
914
915 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
916 flags |= DRM_MODE_FLAG_PHSYNC;
917 else
918 flags |= DRM_MODE_FLAG_NHSYNC;
919
920 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
921 flags |= DRM_MODE_FLAG_PVSYNC;
922 else
923 flags |= DRM_MODE_FLAG_NVSYNC;
924
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200925 if (tmp & HDMI_MODE_SELECT_HDMI)
926 pipe_config->has_hdmi_sink = true;
927
Jesse Barnese43823e2014-11-05 14:26:08 -0800928 if (intel_hdmi->infoframe_enabled(&encoder->base))
929 pipe_config->has_infoframe = true;
930
Jani Nikulac84db772014-09-17 15:34:58 +0300931 if (tmp & SDVO_AUDIO_ENABLE)
Daniel Vetter9ed109a2014-04-24 23:54:52 +0200932 pipe_config->has_audio = true;
933
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300934 if (!HAS_PCH_SPLIT(dev) &&
935 tmp & HDMI_COLOR_RANGE_16_235)
936 pipe_config->limited_color_range = true;
937
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200938 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300939
940 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
941 dotclock = pipe_config->port_clock * 2 / 3;
942 else
943 dotclock = pipe_config->port_clock;
944
Ville Syrjäläbe69a132015-05-05 17:06:26 +0300945 if (pipe_config->pixel_multiplier)
946 dotclock /= pipe_config->pixel_multiplier;
947
Ville Syrjälä18442d02013-09-13 16:00:08 +0300948 if (HAS_PCH_SPLIT(dev_priv->dev))
949 ironlake_check_encoder_dotclock(pipe_config, dotclock);
950
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200951 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700952}
953
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300954static void intel_enable_hdmi_audio(struct intel_encoder *encoder)
955{
956 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
957
958 WARN_ON(!crtc->config->has_hdmi_sink);
959 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
960 pipe_name(crtc->pipe));
961 intel_audio_codec_enable(encoder);
962}
963
Ville Syrjäläbf868c72015-05-05 17:06:23 +0300964static void g4x_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800965{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200966 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800967 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläbf868c72015-05-05 17:06:23 +0300968 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200969 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800970 u32 temp;
971
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300972 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000973
Ville Syrjäläbf868c72015-05-05 17:06:23 +0300974 temp |= SDVO_ENABLE;
975 if (crtc->config->has_audio)
976 temp |= SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200977
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300978 I915_WRITE(intel_hdmi->hdmi_reg, temp);
979 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200980
Ville Syrjäläbf868c72015-05-05 17:06:23 +0300981 if (crtc->config->has_audio)
982 intel_enable_hdmi_audio(encoder);
983}
984
985static void ibx_enable_hdmi(struct intel_encoder *encoder)
986{
987 struct drm_device *dev = encoder->base.dev;
988 struct drm_i915_private *dev_priv = dev->dev_private;
989 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
990 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
991 u32 temp;
992
993 temp = I915_READ(intel_hdmi->hdmi_reg);
994
995 temp |= SDVO_ENABLE;
996 if (crtc->config->has_audio)
997 temp |= SDVO_AUDIO_ENABLE;
998
999 /*
1000 * HW workaround, need to write this twice for issue
1001 * that may result in first write getting masked.
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001002 */
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001003 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1004 POSTING_READ(intel_hdmi->hdmi_reg);
1005 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1006 POSTING_READ(intel_hdmi->hdmi_reg);
1007
1008 /*
1009 * HW workaround, need to toggle enable bit off and on
1010 * for 12bpc with pixel repeat.
1011 *
1012 * FIXME: BSpec says this should be done at the end of
1013 * of the modeset sequence, so not sure if this isn't too soon.
1014 */
1015 if (crtc->config->pipe_bpp > 24 &&
1016 crtc->config->pixel_multiplier > 1) {
1017 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1018 POSTING_READ(intel_hdmi->hdmi_reg);
1019
1020 /*
1021 * HW workaround, need to write this twice for issue
1022 * that may result in first write getting masked.
1023 */
1024 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1025 POSTING_READ(intel_hdmi->hdmi_reg);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001026 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1027 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001028 }
Jani Nikulac1dec792014-10-27 16:26:56 +02001029
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001030 if (crtc->config->has_audio)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001031 intel_enable_hdmi_audio(encoder);
1032}
1033
1034static void cpt_enable_hdmi(struct intel_encoder *encoder)
1035{
1036 struct drm_device *dev = encoder->base.dev;
1037 struct drm_i915_private *dev_priv = dev->dev_private;
1038 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1039 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1040 enum pipe pipe = crtc->pipe;
1041 u32 temp;
1042
1043 temp = I915_READ(intel_hdmi->hdmi_reg);
1044
1045 temp |= SDVO_ENABLE;
1046 if (crtc->config->has_audio)
1047 temp |= SDVO_AUDIO_ENABLE;
1048
1049 /*
1050 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1051 *
1052 * The procedure for 12bpc is as follows:
1053 * 1. disable HDMI clock gating
1054 * 2. enable HDMI with 8bpc
1055 * 3. enable HDMI with 12bpc
1056 * 4. enable HDMI clock gating
1057 */
1058
1059 if (crtc->config->pipe_bpp > 24) {
1060 I915_WRITE(TRANS_CHICKEN1(pipe),
1061 I915_READ(TRANS_CHICKEN1(pipe)) |
1062 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1063
1064 temp &= ~SDVO_COLOR_FORMAT_MASK;
1065 temp |= SDVO_COLOR_FORMAT_8bpc;
Jani Nikulac1dec792014-10-27 16:26:56 +02001066 }
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001067
1068 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1069 POSTING_READ(intel_hdmi->hdmi_reg);
1070
1071 if (crtc->config->pipe_bpp > 24) {
1072 temp &= ~SDVO_COLOR_FORMAT_MASK;
1073 temp |= HDMI_COLOR_FORMAT_12bpc;
1074
1075 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1076 POSTING_READ(intel_hdmi->hdmi_reg);
1077
1078 I915_WRITE(TRANS_CHICKEN1(pipe),
1079 I915_READ(TRANS_CHICKEN1(pipe)) &
1080 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1081 }
1082
1083 if (crtc->config->has_audio)
1084 intel_enable_hdmi_audio(encoder);
Jani Nikulab76cf762013-07-30 12:20:31 +03001085}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001086
Jani Nikulab76cf762013-07-30 12:20:31 +03001087static void vlv_enable_hdmi(struct intel_encoder *encoder)
1088{
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001089}
1090
1091static void intel_disable_hdmi(struct intel_encoder *encoder)
1092{
1093 struct drm_device *dev = encoder->base.dev;
1094 struct drm_i915_private *dev_priv = dev->dev_private;
1095 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Jani Nikula495a5bb2014-10-27 16:26:55 +02001096 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001097 u32 temp;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001098
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001099 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001100
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001101 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001102 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1103 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001104
1105 /*
1106 * HW workaround for IBX, we need to move the port
1107 * to transcoder A after disabling it to allow the
1108 * matching DP port to be enabled on transcoder A.
1109 */
1110 if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B) {
1111 temp &= ~SDVO_PIPE_B_SELECT;
1112 temp |= SDVO_ENABLE;
1113 /*
1114 * HW workaround, need to write this twice for issue
1115 * that may result in first write getting masked.
1116 */
1117 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1118 POSTING_READ(intel_hdmi->hdmi_reg);
1119 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1120 POSTING_READ(intel_hdmi->hdmi_reg);
1121
1122 temp &= ~SDVO_ENABLE;
1123 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1124 POSTING_READ(intel_hdmi->hdmi_reg);
1125 }
Ville Syrjälä6d674152015-05-05 17:06:20 +03001126
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +03001127 intel_hdmi->set_infoframes(&encoder->base, false, NULL);
Eric Anholt7d573822009-01-02 13:33:00 -08001128}
1129
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001130static void g4x_disable_hdmi(struct intel_encoder *encoder)
1131{
1132 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1133
1134 if (crtc->config->has_audio)
1135 intel_audio_codec_disable(encoder);
1136
1137 intel_disable_hdmi(encoder);
1138}
1139
1140static void pch_disable_hdmi(struct intel_encoder *encoder)
1141{
1142 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1143
1144 if (crtc->config->has_audio)
1145 intel_audio_codec_disable(encoder);
1146}
1147
1148static void pch_post_disable_hdmi(struct intel_encoder *encoder)
1149{
1150 intel_disable_hdmi(encoder);
1151}
1152
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001153static int hdmi_port_clock_limit(struct intel_hdmi *hdmi, bool respect_dvi_limit)
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001154{
1155 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1156
Ville Syrjälä40478452014-03-27 11:08:45 +02001157 if ((respect_dvi_limit && !hdmi->has_hdmi_sink) || IS_G4X(dev))
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001158 return 165000;
Damien Lespiaue3c33572013-11-02 21:07:51 -07001159 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001160 return 300000;
1161 else
1162 return 225000;
1163}
1164
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001165static enum drm_mode_status
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001166hdmi_port_clock_valid(struct intel_hdmi *hdmi,
1167 int clock, bool respect_dvi_limit)
1168{
1169 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1170
1171 if (clock < 25000)
1172 return MODE_CLOCK_LOW;
1173 if (clock > hdmi_port_clock_limit(hdmi, respect_dvi_limit))
1174 return MODE_CLOCK_HIGH;
1175
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001176 /* BXT DPLL can't generate 223-240 MHz */
1177 if (IS_BROXTON(dev) && clock > 223333 && clock < 240000)
1178 return MODE_CLOCK_RANGE;
1179
1180 /* CHV DPLL can't generate 216-240 MHz */
1181 if (IS_CHERRYVIEW(dev) && clock > 216000 && clock < 240000)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001182 return MODE_CLOCK_RANGE;
1183
1184 return MODE_OK;
1185}
1186
1187static enum drm_mode_status
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001188intel_hdmi_mode_valid(struct drm_connector *connector,
1189 struct drm_display_mode *mode)
Eric Anholt7d573822009-01-02 13:33:00 -08001190{
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001191 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1192 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1193 enum drm_mode_status status;
1194 int clock;
Eric Anholt7d573822009-01-02 13:33:00 -08001195
1196 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1197 return MODE_NO_DBLESCAN;
1198
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001199 clock = mode->clock;
1200 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1201 clock *= 2;
1202
1203 /* check if we can do 8bpc */
1204 status = hdmi_port_clock_valid(hdmi, clock, true);
1205
1206 /* if we can't do 8bpc we may still be able to do 12bpc */
1207 if (!HAS_GMCH_DISPLAY(dev) && status != MODE_OK)
1208 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
1209
1210 return status;
Eric Anholt7d573822009-01-02 13:33:00 -08001211}
1212
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001213static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
Ville Syrjälä71800632014-03-03 16:15:29 +02001214{
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001215 struct drm_device *dev = crtc_state->base.crtc->dev;
1216 struct drm_atomic_state *state;
Ville Syrjälä71800632014-03-03 16:15:29 +02001217 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001218 struct drm_connector *connector;
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001219 struct drm_connector_state *connector_state;
Ville Syrjälä71800632014-03-03 16:15:29 +02001220 int count = 0, count_hdmi = 0;
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001221 int i;
Ville Syrjälä71800632014-03-03 16:15:29 +02001222
Sonika Jindalf227ae92014-07-21 15:23:45 +05301223 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä71800632014-03-03 16:15:29 +02001224 return false;
1225
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001226 state = crtc_state->base.state;
1227
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +03001228 for_each_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001229 if (connector_state->crtc != crtc_state->base.crtc)
1230 continue;
1231
1232 encoder = to_intel_encoder(connector_state->best_encoder);
1233
Ville Syrjälä71800632014-03-03 16:15:29 +02001234 count_hdmi += encoder->type == INTEL_OUTPUT_HDMI;
1235 count++;
1236 }
1237
1238 /*
1239 * HDMI 12bpc affects the clocks, so it's only possible
1240 * when not cloning with other encoder types.
1241 */
1242 return count_hdmi > 0 && count_hdmi == count;
1243}
1244
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001245bool intel_hdmi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001246 struct intel_crtc_state *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -08001247{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001248 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1249 struct drm_device *dev = encoder->base.dev;
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001250 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001251 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1252 int clock_12bpc = clock_8bpc * 3 / 2;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001253 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001254
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001255 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1256
Jesse Barnese43823e2014-11-05 14:26:08 -08001257 if (pipe_config->has_hdmi_sink)
1258 pipe_config->has_infoframe = true;
1259
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001260 if (intel_hdmi->color_range_auto) {
1261 /* See CEA-861-E - 5.1 Default Encoding Parameters */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001262 pipe_config->limited_color_range =
1263 pipe_config->has_hdmi_sink &&
1264 drm_match_cea_mode(adjusted_mode) > 1;
1265 } else {
1266 pipe_config->limited_color_range =
1267 intel_hdmi->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001268 }
1269
Clint Taylor697c4072014-09-02 17:03:36 -07001270 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1271 pipe_config->pixel_multiplier = 2;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001272 clock_8bpc *= 2;
Ville Syrjälä3320e372015-05-05 17:06:27 +03001273 clock_12bpc *= 2;
Clint Taylor697c4072014-09-02 17:03:36 -07001274 }
1275
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001276 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
1277 pipe_config->has_pch_encoder = true;
1278
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001279 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1280 pipe_config->has_audio = true;
1281
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001282 /*
1283 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1284 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +02001285 * outputs. We also need to check that the higher clock still fits
1286 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001287 */
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001288 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001289 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, false) == MODE_OK &&
Ville Syrjälä7a0baa62015-06-30 15:33:54 +03001290 hdmi_12bpc_possible(pipe_config)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001291 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1292 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +02001293
1294 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +02001295 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001296 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001297 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1298 desired_bpp = 8*3;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001299
1300 pipe_config->port_clock = clock_8bpc;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001301 }
1302
1303 if (!pipe_config->bw_constrained) {
1304 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1305 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001306 }
1307
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001308 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1309 false) != MODE_OK) {
1310 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
Daniel Vetter325b9d02013-04-19 11:24:33 +02001311 return false;
1312 }
1313
Ville Syrjälä28b468a2015-09-08 13:40:48 +03001314 /* Set user selected PAR to incoming mode's member */
1315 adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
1316
Eric Anholt7d573822009-01-02 13:33:00 -08001317 return true;
1318}
1319
Chris Wilson953ece6972014-09-02 20:04:01 +01001320static void
1321intel_hdmi_unset_edid(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001322{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001323 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02001324
Chris Wilsonea5b2132010-08-04 13:50:23 +01001325 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +08001326 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +02001327 intel_hdmi->rgb_quant_range_selectable = false;
ling.ma@intel.com2ded9e2742009-07-16 17:23:09 +08001328
Chris Wilson953ece6972014-09-02 20:04:01 +01001329 kfree(to_intel_connector(connector)->detect_edid);
1330 to_intel_connector(connector)->detect_edid = NULL;
Ma Ling9dff6af2009-04-02 13:13:26 +08001331}
1332
Chris Wilson953ece6972014-09-02 20:04:01 +01001333static bool
Sonika Jindal237ed862015-09-15 09:44:20 +05301334intel_hdmi_set_edid(struct drm_connector *connector, bool force)
Eric Anholt7d573822009-01-02 13:33:00 -08001335{
Chris Wilson953ece6972014-09-02 20:04:01 +01001336 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1337 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1338 struct intel_encoder *intel_encoder =
1339 &hdmi_to_dig_port(intel_hdmi)->base;
Imre Deak671dedd2014-03-05 16:20:53 +02001340 enum intel_display_power_domain power_domain;
Sonika Jindal237ed862015-09-15 09:44:20 +05301341 struct edid *edid = NULL;
Chris Wilson953ece6972014-09-02 20:04:01 +01001342 bool connected = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001343
Imre Deak671dedd2014-03-05 16:20:53 +02001344 power_domain = intel_display_port_power_domain(intel_encoder);
1345 intel_display_power_get(dev_priv, power_domain);
1346
Sonika Jindal237ed862015-09-15 09:44:20 +05301347 if (force)
1348 edid = drm_get_edid(connector,
1349 intel_gmbus_get_adapter(dev_priv,
1350 intel_hdmi->ddc_bus));
Imre Deak671dedd2014-03-05 16:20:53 +02001351
1352 intel_display_power_put(dev_priv, power_domain);
1353
Chris Wilson953ece6972014-09-02 20:04:01 +01001354 to_intel_connector(connector)->detect_edid = edid;
1355 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1356 intel_hdmi->rgb_quant_range_selectable =
1357 drm_rgb_quant_range_selectable(edid);
1358
1359 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1360 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1361 intel_hdmi->has_audio =
1362 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1363
1364 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1365 intel_hdmi->has_hdmi_sink =
1366 drm_detect_hdmi_monitor(edid);
1367
1368 connected = true;
1369 }
1370
1371 return connected;
1372}
1373
Daniel Vetter8166fce2015-10-08 21:50:57 +02001374static enum drm_connector_status
1375intel_hdmi_detect(struct drm_connector *connector, bool force)
Chris Wilson953ece6972014-09-02 20:04:01 +01001376{
Daniel Vetter8166fce2015-10-08 21:50:57 +02001377 enum drm_connector_status status;
1378 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1379 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Sonika Jindal237ed862015-09-15 09:44:20 +05301380 bool live_status = false;
1381 unsigned int retry = 3;
Chris Wilson953ece6972014-09-02 20:04:01 +01001382
Daniel Vetter8166fce2015-10-08 21:50:57 +02001383 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1384 connector->base.id, connector->name);
1385
Sonika Jindal237ed862015-09-15 09:44:20 +05301386 while (!live_status && --retry) {
1387 live_status = intel_digital_port_connected(dev_priv,
1388 hdmi_to_dig_port(intel_hdmi));
1389 mdelay(10);
1390 }
1391
1392 if (!live_status)
1393 DRM_DEBUG_KMS("Live status not up!");
1394
Daniel Vetter8166fce2015-10-08 21:50:57 +02001395 intel_hdmi_unset_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001396
Daniel Vetter8166fce2015-10-08 21:50:57 +02001397 if (intel_hdmi_set_edid(connector, live_status)) {
Chris Wilson953ece6972014-09-02 20:04:01 +01001398 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1399
1400 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1401 status = connector_status_connected;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001402 } else
Chris Wilson953ece6972014-09-02 20:04:01 +01001403 status = connector_status_disconnected;
1404
1405 return status;
1406}
1407
1408static void
1409intel_hdmi_force(struct drm_connector *connector)
1410{
1411 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1412
1413 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1414 connector->base.id, connector->name);
1415
1416 intel_hdmi_unset_edid(connector);
1417
1418 if (connector->status != connector_status_connected)
1419 return;
1420
Sonika Jindal237ed862015-09-15 09:44:20 +05301421 intel_hdmi_set_edid(connector, true);
Chris Wilson953ece6972014-09-02 20:04:01 +01001422 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1423}
1424
1425static int intel_hdmi_get_modes(struct drm_connector *connector)
1426{
1427 struct edid *edid;
1428
1429 edid = to_intel_connector(connector)->detect_edid;
1430 if (edid == NULL)
1431 return 0;
1432
1433 return intel_connector_update_modes(connector, edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001434}
1435
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001436static bool
1437intel_hdmi_detect_audio(struct drm_connector *connector)
1438{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001439 bool has_audio = false;
Chris Wilson953ece6972014-09-02 20:04:01 +01001440 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001441
Chris Wilson953ece6972014-09-02 20:04:01 +01001442 edid = to_intel_connector(connector)->detect_edid;
1443 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1444 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02001445
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001446 return has_audio;
1447}
1448
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001449static int
1450intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001451 struct drm_property *property,
1452 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001453{
1454 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001455 struct intel_digital_port *intel_dig_port =
1456 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +00001457 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001458 int ret;
1459
Rob Clark662595d2012-10-11 20:36:04 -05001460 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001461 if (ret)
1462 return ret;
1463
Chris Wilson3f43c482011-05-12 22:17:24 +01001464 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001465 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001466 bool has_audio;
1467
1468 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001469 return 0;
1470
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001471 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001472
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001473 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001474 has_audio = intel_hdmi_detect_audio(connector);
1475 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001476 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001477
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001478 if (i == HDMI_AUDIO_OFF_DVI)
1479 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001480
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001481 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001482 goto done;
1483 }
1484
Chris Wilsone953fd72011-02-21 22:23:52 +00001485 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001486 bool old_auto = intel_hdmi->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001487 bool old_range = intel_hdmi->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02001488
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001489 switch (val) {
1490 case INTEL_BROADCAST_RGB_AUTO:
1491 intel_hdmi->color_range_auto = true;
1492 break;
1493 case INTEL_BROADCAST_RGB_FULL:
1494 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001495 intel_hdmi->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001496 break;
1497 case INTEL_BROADCAST_RGB_LIMITED:
1498 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001499 intel_hdmi->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001500 break;
1501 default:
1502 return -EINVAL;
1503 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001504
1505 if (old_auto == intel_hdmi->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001506 old_range == intel_hdmi->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02001507 return 0;
1508
Chris Wilsone953fd72011-02-21 22:23:52 +00001509 goto done;
1510 }
1511
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301512 if (property == connector->dev->mode_config.aspect_ratio_property) {
1513 switch (val) {
1514 case DRM_MODE_PICTURE_ASPECT_NONE:
1515 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1516 break;
1517 case DRM_MODE_PICTURE_ASPECT_4_3:
1518 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
1519 break;
1520 case DRM_MODE_PICTURE_ASPECT_16_9:
1521 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
1522 break;
1523 default:
1524 return -EINVAL;
1525 }
1526 goto done;
1527 }
1528
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001529 return -EINVAL;
1530
1531done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001532 if (intel_dig_port->base.base.crtc)
1533 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001534
1535 return 0;
1536}
1537
Jesse Barnes13732ba2014-04-05 11:51:35 -07001538static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1539{
1540 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1541 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03001542 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Jesse Barnes13732ba2014-04-05 11:51:35 -07001543
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001544 intel_hdmi_prepare(encoder);
1545
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001546 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001547 intel_crtc->config->has_hdmi_sink,
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001548 adjusted_mode);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001549}
1550
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001551static void vlv_hdmi_pre_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001552{
1553 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001554 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001555 struct drm_device *dev = encoder->base.dev;
1556 struct drm_i915_private *dev_priv = dev->dev_private;
1557 struct intel_crtc *intel_crtc =
1558 to_intel_crtc(encoder->base.crtc);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03001559 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001560 enum dpio_channel port = vlv_dport_to_channel(dport);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001561 int pipe = intel_crtc->pipe;
1562 u32 val;
1563
Jesse Barnes89b667f2013-04-18 14:51:36 -07001564 /* Enable clock channels for this port */
Ville Syrjäläa5805162015-05-26 20:42:30 +03001565 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001566 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001567 val = 0;
1568 if (pipe)
1569 val |= (1<<21);
1570 else
1571 val &= ~(1<<21);
1572 val |= 0x001000c4;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001573 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001574
1575 /* HDMI 1.0V-2dB */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001576 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0);
1577 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), 0x2b245f5f);
1578 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port), 0x5578b83a);
1579 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0c782040);
1580 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), 0x2b247878);
1581 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1582 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
1583 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001584
1585 /* Program lane clock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001586 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1587 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001588 mutex_unlock(&dev_priv->sb_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001589
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001590 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001591 intel_crtc->config->has_hdmi_sink,
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001592 adjusted_mode);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001593
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001594 g4x_enable_hdmi(encoder);
Jani Nikulab76cf762013-07-30 12:20:31 +03001595
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001596 vlv_wait_port_ready(dev_priv, dport, 0x0);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001597}
1598
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001599static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001600{
1601 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1602 struct drm_device *dev = encoder->base.dev;
1603 struct drm_i915_private *dev_priv = dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001604 struct intel_crtc *intel_crtc =
1605 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001606 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001607 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001608
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001609 intel_hdmi_prepare(encoder);
1610
Jesse Barnes89b667f2013-04-18 14:51:36 -07001611 /* Program Tx lane resets to default */
Ville Syrjäläa5805162015-05-26 20:42:30 +03001612 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001613 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001614 DPIO_PCS_TX_LANE2_RESET |
1615 DPIO_PCS_TX_LANE1_RESET);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001616 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001617 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1618 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1619 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1620 DPIO_PCS_CLK_SOFT_RESET);
1621
1622 /* Fix up inter-pair skew failure */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001623 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1624 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1625 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001626
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001627 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
1628 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001629 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001630}
1631
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001632static void chv_data_lane_soft_reset(struct intel_encoder *encoder,
1633 bool reset)
1634{
1635 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1636 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
1637 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1638 enum pipe pipe = crtc->pipe;
1639 uint32_t val;
1640
1641 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
1642 if (reset)
1643 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
1644 else
1645 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
1646 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
1647
1648 if (crtc->config->lane_count > 2) {
1649 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
1650 if (reset)
1651 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
1652 else
1653 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
1654 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
1655 }
1656
1657 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
1658 val |= CHV_PCS_REQ_SOFTRESET_EN;
1659 if (reset)
1660 val &= ~DPIO_PCS_CLK_SOFT_RESET;
1661 else
1662 val |= DPIO_PCS_CLK_SOFT_RESET;
1663 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
1664
1665 if (crtc->config->lane_count > 2) {
1666 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
1667 val |= CHV_PCS_REQ_SOFTRESET_EN;
1668 if (reset)
1669 val &= ~DPIO_PCS_CLK_SOFT_RESET;
1670 else
1671 val |= DPIO_PCS_CLK_SOFT_RESET;
1672 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
1673 }
1674}
1675
Ville Syrjälä9197c882014-04-09 13:29:05 +03001676static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1677{
1678 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1679 struct drm_device *dev = encoder->base.dev;
1680 struct drm_i915_private *dev_priv = dev->dev_private;
1681 struct intel_crtc *intel_crtc =
1682 to_intel_crtc(encoder->base.crtc);
1683 enum dpio_channel ch = vlv_dport_to_channel(dport);
1684 enum pipe pipe = intel_crtc->pipe;
1685 u32 val;
1686
Ville Syrjälä625695f2014-06-28 02:04:02 +03001687 intel_hdmi_prepare(encoder);
1688
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001689 /*
1690 * Must trick the second common lane into life.
1691 * Otherwise we can't even access the PLL.
1692 */
1693 if (ch == DPIO_CH0 && pipe == PIPE_B)
1694 dport->release_cl2_override =
1695 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
1696
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001697 chv_phy_powergate_lanes(encoder, true, 0x0);
1698
Ville Syrjäläa5805162015-05-26 20:42:30 +03001699 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä9197c882014-04-09 13:29:05 +03001700
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001701 /* Assert data lane reset */
1702 chv_data_lane_soft_reset(encoder, true);
1703
Ville Syrjäläb9e5ac32014-05-27 16:30:18 +03001704 /* program left/right clock distribution */
1705 if (pipe != PIPE_B) {
1706 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
1707 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
1708 if (ch == DPIO_CH0)
1709 val |= CHV_BUFLEFTENA1_FORCE;
1710 if (ch == DPIO_CH1)
1711 val |= CHV_BUFRIGHTENA1_FORCE;
1712 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
1713 } else {
1714 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
1715 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
1716 if (ch == DPIO_CH0)
1717 val |= CHV_BUFLEFTENA2_FORCE;
1718 if (ch == DPIO_CH1)
1719 val |= CHV_BUFRIGHTENA2_FORCE;
1720 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
1721 }
1722
Ville Syrjälä9197c882014-04-09 13:29:05 +03001723 /* program clock channel usage */
1724 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
1725 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
1726 if (pipe != PIPE_B)
1727 val &= ~CHV_PCS_USEDCLKCHANNEL;
1728 else
1729 val |= CHV_PCS_USEDCLKCHANNEL;
1730 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
1731
1732 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
1733 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
1734 if (pipe != PIPE_B)
1735 val &= ~CHV_PCS_USEDCLKCHANNEL;
1736 else
1737 val |= CHV_PCS_USEDCLKCHANNEL;
1738 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
1739
1740 /*
1741 * This a a bit weird since generally CL
1742 * matches the pipe, but here we need to
1743 * pick the CL based on the port.
1744 */
1745 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
1746 if (pipe != PIPE_B)
1747 val &= ~CHV_CMN_USEDCLKCHANNEL;
1748 else
1749 val |= CHV_CMN_USEDCLKCHANNEL;
1750 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
1751
Ville Syrjäläa5805162015-05-26 20:42:30 +03001752 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä9197c882014-04-09 13:29:05 +03001753}
1754
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001755static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder)
1756{
1757 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1758 enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
1759 u32 val;
1760
1761 mutex_lock(&dev_priv->sb_lock);
1762
1763 /* disable left/right clock distribution */
1764 if (pipe != PIPE_B) {
1765 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
1766 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
1767 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
1768 } else {
1769 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
1770 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
1771 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
1772 }
1773
1774 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001775
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001776 /*
1777 * Leave the power down bit cleared for at least one
1778 * lane so that chv_powergate_phy_ch() will power
1779 * on something when the channel is otherwise unused.
1780 * When the port is off and the override is removed
1781 * the lanes power down anyway, so otherwise it doesn't
1782 * really matter what the state of power down bits is
1783 * after this.
1784 */
Ville Syrjäläe0fce782015-07-08 23:45:54 +03001785 chv_phy_powergate_lanes(encoder, false, 0x0);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001786}
1787
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001788static void vlv_hdmi_post_disable(struct intel_encoder *encoder)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001789{
1790 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1791 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001792 struct intel_crtc *intel_crtc =
1793 to_intel_crtc(encoder->base.crtc);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001794 enum dpio_channel port = vlv_dport_to_channel(dport);
Chon Ming Lee5e69f972013-09-05 20:41:49 +08001795 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001796
1797 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
Ville Syrjäläa5805162015-05-26 20:42:30 +03001798 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08001799 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1800 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001801 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001802}
1803
Ville Syrjälä580d3812014-04-09 13:29:00 +03001804static void chv_hdmi_post_disable(struct intel_encoder *encoder)
1805{
Ville Syrjälä580d3812014-04-09 13:29:00 +03001806 struct drm_device *dev = encoder->base.dev;
1807 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä580d3812014-04-09 13:29:00 +03001808
Ville Syrjäläa5805162015-05-26 20:42:30 +03001809 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001810
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001811 /* Assert data lane reset */
1812 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001813
Ville Syrjäläa5805162015-05-26 20:42:30 +03001814 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001815}
1816
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001817static void chv_hdmi_pre_enable(struct intel_encoder *encoder)
1818{
1819 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001820 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001821 struct drm_device *dev = encoder->base.dev;
1822 struct drm_i915_private *dev_priv = dev->dev_private;
1823 struct intel_crtc *intel_crtc =
1824 to_intel_crtc(encoder->base.crtc);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03001825 const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001826 enum dpio_channel ch = vlv_dport_to_channel(dport);
1827 int pipe = intel_crtc->pipe;
Ville Syrjälä2e523e92015-04-10 18:21:27 +03001828 int data, i, stagger;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001829 u32 val;
1830
Ville Syrjäläa5805162015-05-26 20:42:30 +03001831 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001832
Ville Syrjälä570e2a72014-08-18 14:42:46 +03001833 /* allow hardware to manage TX FIFO reset source */
1834 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
1835 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
1836 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
1837
1838 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
1839 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
1840 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
1841
Ville Syrjälä949c1d42014-04-09 13:28:58 +03001842 /* Program Tx latency optimal setting */
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001843 for (i = 0; i < 4; i++) {
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001844 /* Set the upar bit */
1845 data = (i == 1) ? 0x0 : 0x1;
1846 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
1847 data << DPIO_UPAR_SHIFT);
1848 }
1849
1850 /* Data lane stagger programming */
Ville Syrjälä2e523e92015-04-10 18:21:27 +03001851 if (intel_crtc->config->port_clock > 270000)
1852 stagger = 0x18;
1853 else if (intel_crtc->config->port_clock > 135000)
1854 stagger = 0xd;
1855 else if (intel_crtc->config->port_clock > 67500)
1856 stagger = 0x7;
1857 else if (intel_crtc->config->port_clock > 33750)
1858 stagger = 0x4;
1859 else
1860 stagger = 0x2;
1861
1862 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
1863 val |= DPIO_TX2_STAGGER_MASK(0x1f);
1864 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
1865
1866 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
1867 val |= DPIO_TX2_STAGGER_MASK(0x1f);
1868 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
1869
1870 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
1871 DPIO_LANESTAGGER_STRAP(stagger) |
1872 DPIO_LANESTAGGER_STRAP_OVRD |
1873 DPIO_TX1_STAGGER_MASK(0x1f) |
1874 DPIO_TX1_STAGGER_MULT(6) |
1875 DPIO_TX2_STAGGER_MULT(0));
1876
1877 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
1878 DPIO_LANESTAGGER_STRAP(stagger) |
1879 DPIO_LANESTAGGER_STRAP_OVRD |
1880 DPIO_TX1_STAGGER_MASK(0x1f) |
1881 DPIO_TX1_STAGGER_MULT(7) |
1882 DPIO_TX2_STAGGER_MULT(5));
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001883
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001884 /* Deassert data lane reset */
1885 chv_data_lane_soft_reset(encoder, false);
1886
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001887 /* Clear calc init */
Ville Syrjälä1966e592014-04-09 13:29:04 +03001888 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
1889 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001890 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
1891 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03001892 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
1893
1894 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
1895 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001896 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
1897 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
Ville Syrjälä1966e592014-04-09 13:29:04 +03001898 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001899
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001900 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
1901 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
1902 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
1903 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
1904
1905 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
1906 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
1907 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
1908 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
1909
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001910 /* FIXME: Program the support xxx V-dB */
1911 /* Use 800mV-0dB */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001912 for (i = 0; i < 4; i++) {
1913 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
1914 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
1915 val |= 128 << DPIO_SWING_DEEMPH9P5_SHIFT;
1916 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
1917 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001918
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001919 for (i = 0; i < 4; i++) {
1920 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03001921
Ville Syrjälä1fb44502014-06-28 02:04:03 +03001922 val &= ~DPIO_SWING_MARGIN000_MASK;
1923 val |= 102 << DPIO_SWING_MARGIN000_SHIFT;
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03001924
1925 /*
1926 * Supposedly this value shouldn't matter when unique transition
1927 * scale is disabled, but in fact it does matter. Let's just
1928 * always program the same value and hope it's OK.
1929 */
1930 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
1931 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
1932
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001933 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
1934 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001935
Ville Syrjälä67fa24b2015-07-08 23:45:48 +03001936 /*
1937 * The document said it needs to set bit 27 for ch0 and bit 26
1938 * for ch1. Might be a typo in the doc.
1939 * For now, for this unique transition scale selection, set bit
1940 * 27 for ch0 and ch1.
1941 */
Ville Syrjäläf72df8d2014-04-09 13:29:03 +03001942 for (i = 0; i < 4; i++) {
1943 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
1944 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
1945 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
1946 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001947
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001948 /* Start swing calculation */
Ville Syrjälä1966e592014-04-09 13:29:04 +03001949 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
1950 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
1951 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
1952
1953 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
1954 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
1955 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001956
Ville Syrjäläa5805162015-05-26 20:42:30 +03001957 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001958
Clint Taylorb4eb1562014-11-21 11:13:02 -08001959 intel_hdmi->set_infoframes(&encoder->base,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001960 intel_crtc->config->has_hdmi_sink,
Clint Taylorb4eb1562014-11-21 11:13:02 -08001961 adjusted_mode);
1962
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001963 g4x_enable_hdmi(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001964
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001965 vlv_wait_port_ready(dev_priv, dport, 0x0);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001966
1967 /* Second common lane will stay alive on its own now */
1968 if (dport->release_cl2_override) {
1969 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
1970 dport->release_cl2_override = false;
1971 }
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001972}
1973
Eric Anholt7d573822009-01-02 13:33:00 -08001974static void intel_hdmi_destroy(struct drm_connector *connector)
1975{
Chris Wilson10e972d2014-09-04 21:43:45 +01001976 kfree(to_intel_connector(connector)->detect_edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001977 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001978 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001979}
1980
Eric Anholt7d573822009-01-02 13:33:00 -08001981static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001982 .dpms = drm_atomic_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001983 .detect = intel_hdmi_detect,
Chris Wilson953ece6972014-09-02 20:04:01 +01001984 .force = intel_hdmi_force,
Eric Anholt7d573822009-01-02 13:33:00 -08001985 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001986 .set_property = intel_hdmi_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08001987 .atomic_get_property = intel_connector_atomic_get_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001988 .destroy = intel_hdmi_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08001989 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001990 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Eric Anholt7d573822009-01-02 13:33:00 -08001991};
1992
1993static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1994 .get_modes = intel_hdmi_get_modes,
1995 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001996 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001997};
1998
Eric Anholt7d573822009-01-02 13:33:00 -08001999static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01002000 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08002001};
2002
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002003static void
2004intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
2005{
Chris Wilson3f43c482011-05-12 22:17:24 +01002006 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00002007 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02002008 intel_hdmi->color_range_auto = true;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05302009 intel_attach_aspect_ratio_property(connector);
2010 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002011}
2012
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002013void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
2014 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08002015{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002016 struct drm_connector *connector = &intel_connector->base;
2017 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
2018 struct intel_encoder *intel_encoder = &intel_dig_port->base;
2019 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08002020 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002021 enum port port = intel_dig_port->port;
Xiong Zhang11c1b652015-08-17 16:04:04 +08002022 uint8_t alternate_ddc_pin;
Eric Anholt7d573822009-01-02 13:33:00 -08002023
Eric Anholt7d573822009-01-02 13:33:00 -08002024 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04002025 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08002026 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
2027
Peter Rossc3febcc2012-01-28 14:49:26 +01002028 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08002029 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01002030 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08002031
Daniel Vetter08d644a2012-07-12 20:19:59 +02002032 switch (port) {
2033 case PORT_B:
Jani Nikula4c272832015-04-01 10:58:05 +03002034 if (IS_BROXTON(dev_priv))
2035 intel_hdmi->ddc_bus = GMBUS_PIN_1_BXT;
2036 else
2037 intel_hdmi->ddc_bus = GMBUS_PIN_DPB;
Sonika Jindalcf1d5882015-08-10 10:35:36 +05302038 /*
2039 * On BXT A0/A1, sw needs to activate DDIA HPD logic and
2040 * interrupts to check the external panel connection.
2041 */
2042 if (IS_BROXTON(dev_priv) && (INTEL_REVID(dev) < BXT_REVID_B0))
2043 intel_encoder->hpd_pin = HPD_PORT_A;
2044 else
2045 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02002046 break;
2047 case PORT_C:
Jani Nikula4c272832015-04-01 10:58:05 +03002048 if (IS_BROXTON(dev_priv))
2049 intel_hdmi->ddc_bus = GMBUS_PIN_2_BXT;
2050 else
2051 intel_hdmi->ddc_bus = GMBUS_PIN_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05002052 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02002053 break;
2054 case PORT_D:
Jani Nikula4c272832015-04-01 10:58:05 +03002055 if (WARN_ON(IS_BROXTON(dev_priv)))
2056 intel_hdmi->ddc_bus = GMBUS_PIN_DISABLED;
2057 else if (IS_CHERRYVIEW(dev_priv))
Jani Nikula988c7012015-03-27 00:20:19 +02002058 intel_hdmi->ddc_bus = GMBUS_PIN_DPD_CHV;
Ville Syrjäläc0c35322014-04-09 13:28:52 +03002059 else
Jani Nikula988c7012015-03-27 00:20:19 +02002060 intel_hdmi->ddc_bus = GMBUS_PIN_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05002061 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02002062 break;
Xiong Zhang11c1b652015-08-17 16:04:04 +08002063 case PORT_E:
2064 /* On SKL PORT E doesn't have seperate GMBUS pin
2065 * We rely on VBT to set a proper alternate GMBUS pin. */
2066 alternate_ddc_pin =
2067 dev_priv->vbt.ddi_port_info[PORT_E].alternate_ddc_pin;
2068 switch (alternate_ddc_pin) {
2069 case DDC_PIN_B:
2070 intel_hdmi->ddc_bus = GMBUS_PIN_DPB;
2071 break;
2072 case DDC_PIN_C:
2073 intel_hdmi->ddc_bus = GMBUS_PIN_DPC;
2074 break;
2075 case DDC_PIN_D:
2076 intel_hdmi->ddc_bus = GMBUS_PIN_DPD;
2077 break;
2078 default:
2079 MISSING_CASE(alternate_ddc_pin);
2080 }
2081 intel_encoder->hpd_pin = HPD_PORT_E;
2082 break;
Daniel Vetter08d644a2012-07-12 20:19:59 +02002083 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05002084 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02002085 /* Internal port only for eDP. */
2086 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03002087 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08002088 }
Eric Anholt7d573822009-01-02 13:33:00 -08002089
Jesse Barnes7637bfd2013-03-08 10:46:01 -08002090 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07002091 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03002092 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08002093 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
Sonika Jindalb98856a2014-07-22 11:13:46 +05302094 } else if (IS_G4X(dev)) {
Jesse Barnes7637bfd2013-03-08 10:46:01 -08002095 intel_hdmi->write_infoframe = g4x_write_infoframe;
2096 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08002097 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03002098 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03002099 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03002100 intel_hdmi->set_infoframes = hsw_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08002101 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03002102 } else if (HAS_PCH_IBX(dev)) {
2103 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03002104 intel_hdmi->set_infoframes = ibx_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08002105 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03002106 } else {
2107 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03002108 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08002109 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05302110 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07002111
Paulo Zanoniaffa9352012-11-23 15:30:39 -02002112 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02002113 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
2114 else
2115 intel_connector->get_hw_state = intel_connector_get_hw_state;
Imre Deak4932e2c2014-02-11 17:12:48 +02002116 intel_connector->unregister = intel_connector_unregister;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002117
2118 intel_hdmi_add_properties(intel_hdmi, connector);
2119
2120 intel_connector_attach_encoder(intel_connector, intel_encoder);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002121 drm_connector_register(connector);
Shashank Sharmad8b4c432015-09-04 18:56:11 +05302122 intel_hdmi->attached_connector = intel_connector;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002123
2124 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
2125 * 0xd. Failure to do so will result in spurious interrupts being
2126 * generated on the port when a cable is not attached.
2127 */
2128 if (IS_G4X(dev) && !IS_GM45(dev)) {
2129 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2130 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2131 }
2132}
2133
Paulo Zanonib242b7f2013-02-18 19:00:26 -03002134void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002135{
2136 struct intel_digital_port *intel_dig_port;
2137 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002138 struct intel_connector *intel_connector;
2139
Daniel Vetterb14c5672013-09-19 12:18:32 +02002140 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002141 if (!intel_dig_port)
2142 return;
2143
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03002144 intel_connector = intel_connector_alloc();
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002145 if (!intel_connector) {
2146 kfree(intel_dig_port);
2147 return;
2148 }
2149
2150 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002151
2152 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
2153 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002154
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002155 intel_encoder->compute_config = intel_hdmi_compute_config;
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03002156 if (HAS_PCH_SPLIT(dev)) {
2157 intel_encoder->disable = pch_disable_hdmi;
2158 intel_encoder->post_disable = pch_post_disable_hdmi;
2159 } else {
2160 intel_encoder->disable = g4x_disable_hdmi;
2161 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002162 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002163 intel_encoder->get_config = intel_hdmi_get_config;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002164 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03002165 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002166 intel_encoder->pre_enable = chv_hdmi_pre_enable;
2167 intel_encoder->enable = vlv_enable_hdmi;
Ville Syrjälä580d3812014-04-09 13:29:00 +03002168 intel_encoder->post_disable = chv_hdmi_post_disable;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002169 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002170 } else if (IS_VALLEYVIEW(dev)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08002171 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
2172 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03002173 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08002174 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03002175 } else {
Jesse Barnes13732ba2014-04-05 11:51:35 -07002176 intel_encoder->pre_enable = intel_hdmi_pre_enable;
Ville Syrjäläd1b15892015-05-05 17:06:19 +03002177 if (HAS_PCH_CPT(dev))
2178 intel_encoder->enable = cpt_enable_hdmi;
Ville Syrjäläbf868c72015-05-05 17:06:23 +03002179 else if (HAS_PCH_IBX(dev))
2180 intel_encoder->enable = ibx_enable_hdmi;
Ville Syrjäläd1b15892015-05-05 17:06:19 +03002181 else
Ville Syrjäläbf868c72015-05-05 17:06:23 +03002182 intel_encoder->enable = g4x_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002183 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002184
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002185 intel_encoder->type = INTEL_OUTPUT_HDMI;
Ville Syrjälä882ec382014-04-28 14:07:43 +03002186 if (IS_CHERRYVIEW(dev)) {
2187 if (port == PORT_D)
2188 intel_encoder->crtc_mask = 1 << 2;
2189 else
2190 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2191 } else {
2192 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2193 }
Ville Syrjälä301ea742014-03-03 16:15:30 +02002194 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
Ville Syrjäläc6f14952014-03-03 16:15:31 +02002195 /*
2196 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
2197 * to work on real hardware. And since g4x can send infoframes to
2198 * only one port anyway, nothing is lost by allowing it.
2199 */
2200 if (IS_G4X(dev))
2201 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -08002202
Paulo Zanoni174edf12012-10-26 19:05:50 -02002203 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03002204 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002205 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002206
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002207 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08002208}