blob: 3eec74ca5116eaff0ee24f0084f77ffa56c238ad [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>
Jerome Anand46d196e2017-01-25 04:27:50 +053039#include <drm/intel_lpe_audio.h>
Eric Anholt7d573822009-01-02 13:33:00 -080040#include "i915_drv.h"
41
Paulo Zanoni30add222012-10-26 19:05:45 -020042static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
43{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020044 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020045}
46
Daniel Vetterafba0182012-06-12 16:36:45 +020047static void
48assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
49{
Paulo Zanoni30add222012-10-26 19:05:45 -020050 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +010051 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterafba0182012-06-12 16:36:45 +020052 uint32_t enabled_bits;
53
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010054 enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020055
Paulo Zanonib242b7f2013-02-18 19:00:26 -030056 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020057 "HDMI port enabled, expecting disabled\n");
58}
59
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030060struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010061{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020062 struct intel_digital_port *intel_dig_port =
63 container_of(encoder, struct intel_digital_port, base.base);
64 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010065}
66
Chris Wilsondf0e9242010-09-09 16:20:55 +010067static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
68{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020069 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010070}
71
Damien Lespiau178f7362013-08-06 20:32:18 +010072static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020073{
Damien Lespiau178f7362013-08-06 20:32:18 +010074 switch (type) {
75 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030076 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010077 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030078 return VIDEO_DIP_SELECT_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010079 case HDMI_INFOFRAME_TYPE_VENDOR:
80 return VIDEO_DIP_SELECT_VENDOR;
Jesse Barnes45187ac2011-08-03 09:22:55 -070081 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020082 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030083 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070084 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070085}
86
Damien Lespiau178f7362013-08-06 20:32:18 +010087static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070088{
Damien Lespiau178f7362013-08-06 20:32:18 +010089 switch (type) {
90 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030091 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010092 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030093 return VIDEO_DIP_ENABLE_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010094 case HDMI_INFOFRAME_TYPE_VENDOR:
95 return VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030096 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020097 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030098 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030099 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300100}
101
Damien Lespiau178f7362013-08-06 20:32:18 +0100102static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300103{
Damien Lespiau178f7362013-08-06 20:32:18 +0100104 switch (type) {
105 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300106 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100107 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300108 return VIDEO_DIP_ENABLE_SPD_HSW;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100109 case HDMI_INFOFRAME_TYPE_VENDOR:
110 return VIDEO_DIP_ENABLE_VS_HSW;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300111 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200112 MISSING_CASE(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300113 return 0;
114 }
115}
116
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200117static i915_reg_t
118hsw_dip_data_reg(struct drm_i915_private *dev_priv,
119 enum transcoder cpu_transcoder,
120 enum hdmi_infoframe_type type,
121 int i)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300122{
Damien Lespiau178f7362013-08-06 20:32:18 +0100123 switch (type) {
124 case HDMI_INFOFRAME_TYPE_AVI:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300125 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
Damien Lespiau178f7362013-08-06 20:32:18 +0100126 case HDMI_INFOFRAME_TYPE_SPD:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300127 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100128 case HDMI_INFOFRAME_TYPE_VENDOR:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300129 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300130 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200131 MISSING_CASE(type);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200132 return INVALID_MMIO_REG;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300133 }
134}
135
Daniel Vettera3da1df2012-05-08 15:19:06 +0200136static void g4x_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100137 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100138 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200139 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700140{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200141 const uint32_t *data = frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200142 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100143 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300144 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100145 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200146
Paulo Zanoni822974a2012-05-28 16:42:51 -0300147 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
148
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300149 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100150 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700151
Damien Lespiau178f7362013-08-06 20:32:18 +0100152 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300153
154 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700155
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300156 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700157 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200158 I915_WRITE(VIDEO_DIP_DATA, *data);
159 data++;
160 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300161 /* Write every possible data byte to force correct ECC calculation. */
162 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
163 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300164 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200165
Damien Lespiau178f7362013-08-06 20:32:18 +0100166 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300167 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200168 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700169
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300170 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300171 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200172}
173
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200174static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
175 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800176{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200177 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800178 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800179 u32 val = I915_READ(VIDEO_DIP_CTL);
180
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300181 if ((val & VIDEO_DIP_ENABLE) == 0)
182 return false;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800183
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300184 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
185 return false;
186
187 return val & (VIDEO_DIP_ENABLE_AVI |
188 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Jesse Barnese43823e2014-11-05 14:26:08 -0800189}
190
Paulo Zanonifdf12502012-05-04 17:18:24 -0300191static void ibx_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100192 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100193 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200194 const void *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300195{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200196 const uint32_t *data = frame;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300197 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100198 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100199 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200200 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300201 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200202 int i;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300203
Paulo Zanoni822974a2012-05-28 16:42:51 -0300204 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
205
Paulo Zanonifdf12502012-05-04 17:18:24 -0300206 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100207 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300208
Damien Lespiau178f7362013-08-06 20:32:18 +0100209 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300210
211 I915_WRITE(reg, val);
212
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300213 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300214 for (i = 0; i < len; i += 4) {
215 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
216 data++;
217 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300218 /* Write every possible data byte to force correct ECC calculation. */
219 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
220 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300221 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300222
Damien Lespiau178f7362013-08-06 20:32:18 +0100223 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300224 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200225 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300226
227 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300228 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300229}
230
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200231static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
232 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800233{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200234 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jani Nikula052f62f2015-04-29 15:30:07 +0300235 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200236 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
237 i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
Jesse Barnese43823e2014-11-05 14:26:08 -0800238 u32 val = I915_READ(reg);
239
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300240 if ((val & VIDEO_DIP_ENABLE) == 0)
241 return false;
Jani Nikula052f62f2015-04-29 15:30:07 +0300242
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300243 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
244 return false;
245
246 return val & (VIDEO_DIP_ENABLE_AVI |
247 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
248 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800249}
250
Paulo Zanonifdf12502012-05-04 17:18:24 -0300251static void cpt_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100252 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100253 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200254 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700255{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200256 const uint32_t *data = frame;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700257 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100258 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100259 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200260 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300261 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200262 int i;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700263
Paulo Zanoni822974a2012-05-28 16:42:51 -0300264 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
265
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530266 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100267 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700268
Paulo Zanoniecb97852012-05-04 17:18:21 -0300269 /* The DIP control register spec says that we need to update the AVI
270 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100271 if (type != HDMI_INFOFRAME_TYPE_AVI)
272 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300273
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300274 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700275
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300276 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700277 for (i = 0; i < len; i += 4) {
278 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
279 data++;
280 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300281 /* Write every possible data byte to force correct ECC calculation. */
282 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
283 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300284 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700285
Damien Lespiau178f7362013-08-06 20:32:18 +0100286 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300287 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200288 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700289
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300290 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300291 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700292}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700293
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200294static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
295 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800296{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200297 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
298 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
299 u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800300
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300301 if ((val & VIDEO_DIP_ENABLE) == 0)
302 return false;
303
304 return val & (VIDEO_DIP_ENABLE_AVI |
305 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
306 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800307}
308
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700309static void vlv_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100310 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100311 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200312 const void *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700313{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200314 const uint32_t *data = frame;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700315 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100316 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100317 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200318 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300319 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200320 int i;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700321
Paulo Zanoni822974a2012-05-28 16:42:51 -0300322 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
323
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700324 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100325 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700326
Damien Lespiau178f7362013-08-06 20:32:18 +0100327 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300328
329 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700330
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300331 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700332 for (i = 0; i < len; i += 4) {
333 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
334 data++;
335 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300336 /* Write every possible data byte to force correct ECC calculation. */
337 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
338 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300339 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700340
Damien Lespiau178f7362013-08-06 20:32:18 +0100341 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300342 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200343 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700344
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300345 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300346 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700347}
348
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200349static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
350 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800351{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200352 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes535afa22015-04-15 16:52:29 -0700353 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200354 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
355 u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800356
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300357 if ((val & VIDEO_DIP_ENABLE) == 0)
358 return false;
Jesse Barnes535afa22015-04-15 16:52:29 -0700359
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300360 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
361 return false;
362
363 return val & (VIDEO_DIP_ENABLE_AVI |
364 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
365 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800366}
367
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300368static void hsw_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100369 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100370 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200371 const void *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300372{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200373 const uint32_t *data = frame;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300374 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100375 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100376 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200377 i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
378 i915_reg_t data_reg;
Damien Lespiau178f7362013-08-06 20:32:18 +0100379 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300380 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300381
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300382 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300383
Damien Lespiau178f7362013-08-06 20:32:18 +0100384 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300385 I915_WRITE(ctl_reg, val);
386
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300387 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300388 for (i = 0; i < len; i += 4) {
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300389 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
390 type, i >> 2), *data);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300391 data++;
392 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300393 /* Write every possible data byte to force correct ECC calculation. */
394 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300395 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
396 type, i >> 2), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300397 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300398
Damien Lespiau178f7362013-08-06 20:32:18 +0100399 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300400 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300401 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300402}
403
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200404static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
405 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800406{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200407 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
408 u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
Jesse Barnese43823e2014-11-05 14:26:08 -0800409
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300410 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
411 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
412 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
Jesse Barnese43823e2014-11-05 14:26:08 -0800413}
414
Damien Lespiau5adaea72013-08-06 20:32:19 +0100415/*
416 * The data we write to the DIP data buffer registers is 1 byte bigger than the
417 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
418 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
419 * used for both technologies.
420 *
421 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
422 * DW1: DB3 | DB2 | DB1 | DB0
423 * DW2: DB7 | DB6 | DB5 | DB4
424 * DW3: ...
425 *
426 * (HB is Header Byte, DB is Data Byte)
427 *
428 * The hdmi pack() functions don't know about that hardware specific hole so we
429 * trick them by giving an offset into the buffer and moving back the header
430 * bytes by one.
431 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100432static void intel_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100433 const struct intel_crtc_state *crtc_state,
Damien Lespiau9198ee52013-08-06 20:32:24 +0100434 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700435{
436 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100437 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
438 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700439
Damien Lespiau5adaea72013-08-06 20:32:19 +0100440 /* see comment above for the reason for this offset */
441 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
442 if (len < 0)
443 return;
444
445 /* Insert the 'hole' (see big comment above) at position 3 */
446 buffer[0] = buffer[1];
447 buffer[1] = buffer[2];
448 buffer[2] = buffer[3];
449 buffer[3] = 0;
450 len++;
451
Maarten Lankhorstac240282016-11-23 15:57:00 +0100452 intel_hdmi->write_infoframe(encoder, crtc_state, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700453}
454
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300455static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100456 const struct intel_crtc_state *crtc_state)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700457{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200458 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200459 const struct drm_display_mode *adjusted_mode =
460 &crtc_state->base.adjusted_mode;
Damien Lespiau5adaea72013-08-06 20:32:19 +0100461 union hdmi_infoframe frame;
462 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700463
Damien Lespiau5adaea72013-08-06 20:32:19 +0100464 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
465 adjusted_mode);
466 if (ret < 0) {
467 DRM_ERROR("couldn't fill AVI infoframe\n");
468 return;
469 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300470
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200471 drm_hdmi_avi_infoframe_quant_range(&frame.avi, adjusted_mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +0200472 crtc_state->limited_color_range ?
473 HDMI_QUANTIZATION_RANGE_LIMITED :
474 HDMI_QUANTIZATION_RANGE_FULL,
475 intel_hdmi->rgb_quant_range_selectable);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200476
Maarten Lankhorstac240282016-11-23 15:57:00 +0100477 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700478}
479
Maarten Lankhorstac240282016-11-23 15:57:00 +0100480static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
481 const struct intel_crtc_state *crtc_state)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700482{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100483 union hdmi_infoframe frame;
484 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700485
Damien Lespiau5adaea72013-08-06 20:32:19 +0100486 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
487 if (ret < 0) {
488 DRM_ERROR("couldn't fill SPD infoframe\n");
489 return;
490 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700491
Damien Lespiau5adaea72013-08-06 20:32:19 +0100492 frame.spd.sdi = HDMI_SPD_SDI_PC;
493
Maarten Lankhorstac240282016-11-23 15:57:00 +0100494 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700495}
496
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100497static void
498intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100499 const struct intel_crtc_state *crtc_state)
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100500{
501 union hdmi_infoframe frame;
502 int ret;
503
504 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100505 &crtc_state->base.adjusted_mode);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100506 if (ret < 0)
507 return;
508
Maarten Lankhorstac240282016-11-23 15:57:00 +0100509 intel_write_infoframe(encoder, crtc_state, &frame);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100510}
511
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300512static void g4x_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200513 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100514 const struct intel_crtc_state *crtc_state,
515 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300516{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100517 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200518 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
519 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200520 i915_reg_t reg = VIDEO_DIP_CTL;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300521 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200522 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300523
Daniel Vetterafba0182012-06-12 16:36:45 +0200524 assert_hdmi_port_disabled(intel_hdmi);
525
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300526 /* If the registers were not initialized yet, they might be zeroes,
527 * which means we're selecting the AVI DIP and we're setting its
528 * frequency to once. This seems to really confuse the HW and make
529 * things stop working (the register spec says the AVI always needs to
530 * be sent every VSync). So here we avoid writing to the register more
531 * than we need and also explicitly select the AVI DIP and explicitly
532 * set its frequency to every VSync. Avoiding to write it twice seems to
533 * be enough to solve the problem, but being defensive shouldn't hurt us
534 * either. */
535 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
536
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200537 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300538 if (!(val & VIDEO_DIP_ENABLE))
539 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300540 if (port != (val & VIDEO_DIP_PORT_MASK)) {
541 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
542 (val & VIDEO_DIP_PORT_MASK) >> 29);
543 return;
544 }
545 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
546 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300547 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300548 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300549 return;
550 }
551
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300552 if (port != (val & VIDEO_DIP_PORT_MASK)) {
553 if (val & VIDEO_DIP_ENABLE) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300554 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
555 (val & VIDEO_DIP_PORT_MASK) >> 29);
556 return;
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300557 }
558 val &= ~VIDEO_DIP_PORT_MASK;
559 val |= port;
560 }
561
Paulo Zanoni822974a2012-05-28 16:42:51 -0300562 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300563 val &= ~(VIDEO_DIP_ENABLE_AVI |
564 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300565
Paulo Zanonif278d972012-05-28 16:42:50 -0300566 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300567 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300568
Maarten Lankhorstac240282016-11-23 15:57:00 +0100569 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
570 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
571 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300572}
573
Maarten Lankhorstac240282016-11-23 15:57:00 +0100574static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300575{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100576 struct drm_connector *connector = conn_state->connector;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300577
578 /*
579 * HDMI cloning is only supported on g4x which doesn't
580 * support deep color or GCP infoframes anyway so no
581 * need to worry about multiple HDMI sinks here.
582 */
Ville Syrjälä6d674152015-05-05 17:06:20 +0300583
Maarten Lankhorstac240282016-11-23 15:57:00 +0100584 return connector->display_info.bpc > 8;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300585}
586
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300587/*
588 * Determine if default_phase=1 can be indicated in the GCP infoframe.
589 *
590 * From HDMI specification 1.4a:
591 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
592 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
593 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
594 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
595 * phase of 0
596 */
597static bool gcp_default_phase_possible(int pipe_bpp,
598 const struct drm_display_mode *mode)
599{
600 unsigned int pixels_per_group;
601
602 switch (pipe_bpp) {
603 case 30:
604 /* 4 pixels in 5 clocks */
605 pixels_per_group = 4;
606 break;
607 case 36:
608 /* 2 pixels in 3 clocks */
609 pixels_per_group = 2;
610 break;
611 case 48:
612 /* 1 pixel in 2 clocks */
613 pixels_per_group = 1;
614 break;
615 default:
616 /* phase information not relevant for 8bpc */
617 return false;
618 }
619
620 return mode->crtc_hdisplay % pixels_per_group == 0 &&
621 mode->crtc_htotal % pixels_per_group == 0 &&
622 mode->crtc_hblank_start % pixels_per_group == 0 &&
623 mode->crtc_hblank_end % pixels_per_group == 0 &&
624 mode->crtc_hsync_start % pixels_per_group == 0 &&
625 mode->crtc_hsync_end % pixels_per_group == 0 &&
626 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
627 mode->crtc_htotal/2 % pixels_per_group == 0);
628}
629
Maarten Lankhorstac240282016-11-23 15:57:00 +0100630static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder,
631 const struct intel_crtc_state *crtc_state,
632 const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300633{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100634 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100635 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200636 i915_reg_t reg;
637 u32 val = 0;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300638
639 if (HAS_DDI(dev_priv))
Maarten Lankhorstac240282016-11-23 15:57:00 +0100640 reg = HSW_TVIDEO_DIP_GCP(crtc_state->cpu_transcoder);
Wayne Boyer666a4532015-12-09 12:29:35 -0800641 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300642 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +0300643 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300644 reg = TVIDEO_DIP_GCP(crtc->pipe);
645 else
646 return false;
647
648 /* Indicate color depth whenever the sink supports deep color */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100649 if (hdmi_sink_is_deep_color(conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300650 val |= GCP_COLOR_INDICATION;
651
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300652 /* Enable default_phase whenever the display mode is suitably aligned */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100653 if (gcp_default_phase_possible(crtc_state->pipe_bpp,
654 &crtc_state->base.adjusted_mode))
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300655 val |= GCP_DEFAULT_PHASE_ENABLE;
656
Ville Syrjälä6d674152015-05-05 17:06:20 +0300657 I915_WRITE(reg, val);
658
659 return val != 0;
660}
661
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300662static void ibx_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200663 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100664 const struct intel_crtc_state *crtc_state,
665 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300666{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100667 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100668 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200669 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
670 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200671 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300672 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200673 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300674
Daniel Vetterafba0182012-06-12 16:36:45 +0200675 assert_hdmi_port_disabled(intel_hdmi);
676
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300677 /* See the big comment in g4x_set_infoframes() */
678 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
679
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200680 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300681 if (!(val & VIDEO_DIP_ENABLE))
682 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300683 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
684 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
685 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300686 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300687 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300688 return;
689 }
690
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300691 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300692 WARN(val & VIDEO_DIP_ENABLE,
693 "DIP already enabled on port %c\n",
694 (val & VIDEO_DIP_PORT_MASK) >> 29);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300695 val &= ~VIDEO_DIP_PORT_MASK;
696 val |= port;
697 }
698
Paulo Zanoni822974a2012-05-28 16:42:51 -0300699 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300700 val &= ~(VIDEO_DIP_ENABLE_AVI |
701 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
702 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300703
Maarten Lankhorstac240282016-11-23 15:57:00 +0100704 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300705 val |= VIDEO_DIP_ENABLE_GCP;
706
Paulo Zanonif278d972012-05-28 16:42:50 -0300707 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300708 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300709
Maarten Lankhorstac240282016-11-23 15:57:00 +0100710 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
711 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
712 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300713}
714
715static void cpt_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200716 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100717 const struct intel_crtc_state *crtc_state,
718 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300719{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100720 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100721 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300722 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200723 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300724 u32 val = I915_READ(reg);
725
Daniel Vetterafba0182012-06-12 16:36:45 +0200726 assert_hdmi_port_disabled(intel_hdmi);
727
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300728 /* See the big comment in g4x_set_infoframes() */
729 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
730
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200731 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300732 if (!(val & VIDEO_DIP_ENABLE))
733 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300734 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
735 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
736 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300737 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300738 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300739 return;
740 }
741
Paulo Zanoni822974a2012-05-28 16:42:51 -0300742 /* Set both together, unset both together: see the spec. */
743 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300744 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300745 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300746
Maarten Lankhorstac240282016-11-23 15:57:00 +0100747 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300748 val |= VIDEO_DIP_ENABLE_GCP;
749
Paulo Zanoni822974a2012-05-28 16:42:51 -0300750 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300751 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300752
Maarten Lankhorstac240282016-11-23 15:57:00 +0100753 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
754 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
755 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300756}
757
758static void vlv_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200759 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100760 const struct intel_crtc_state *crtc_state,
761 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300762{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100763 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700764 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100765 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300766 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200767 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300768 u32 val = I915_READ(reg);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700769 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300770
Daniel Vetterafba0182012-06-12 16:36:45 +0200771 assert_hdmi_port_disabled(intel_hdmi);
772
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300773 /* See the big comment in g4x_set_infoframes() */
774 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
775
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200776 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300777 if (!(val & VIDEO_DIP_ENABLE))
778 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300779 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
780 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
781 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300782 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300783 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300784 return;
785 }
786
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700787 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300788 WARN(val & VIDEO_DIP_ENABLE,
789 "DIP already enabled on port %c\n",
790 (val & VIDEO_DIP_PORT_MASK) >> 29);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700791 val &= ~VIDEO_DIP_PORT_MASK;
792 val |= port;
793 }
794
Paulo Zanoni822974a2012-05-28 16:42:51 -0300795 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300796 val &= ~(VIDEO_DIP_ENABLE_AVI |
797 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
798 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300799
Maarten Lankhorstac240282016-11-23 15:57:00 +0100800 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300801 val |= VIDEO_DIP_ENABLE_GCP;
802
Paulo Zanoni822974a2012-05-28 16:42:51 -0300803 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300804 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300805
Maarten Lankhorstac240282016-11-23 15:57:00 +0100806 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
807 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
808 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300809}
810
811static void hsw_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200812 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100813 const struct intel_crtc_state *crtc_state,
814 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300815{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100816 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300817 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100818 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300819 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300820
Daniel Vetterafba0182012-06-12 16:36:45 +0200821 assert_hdmi_port_disabled(intel_hdmi);
822
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300823 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
824 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
825 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
826
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200827 if (!enable) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300828 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300829 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300830 return;
831 }
832
Maarten Lankhorstac240282016-11-23 15:57:00 +0100833 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300834 val |= VIDEO_DIP_ENABLE_GCP_HSW;
835
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300836 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300837 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300838
Maarten Lankhorstac240282016-11-23 15:57:00 +0100839 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
840 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
841 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300842}
843
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300844void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
845{
846 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
847 struct i2c_adapter *adapter =
848 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
849
850 if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
851 return;
852
853 DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
854 enable ? "Enabling" : "Disabling");
855
856 drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
857 adapter, enable);
858}
859
Maarten Lankhorstac240282016-11-23 15:57:00 +0100860static void intel_hdmi_prepare(struct intel_encoder *encoder,
861 const struct intel_crtc_state *crtc_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800862{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200863 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100864 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100865 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Daniel Vetterc59423a2013-07-21 21:37:04 +0200866 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100867 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300868 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800869
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300870 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
871
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300872 hdmi_val = SDVO_ENCODING_HDMI;
Maarten Lankhorstac240282016-11-23 15:57:00 +0100873 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +0300874 hdmi_val |= HDMI_COLOR_RANGE_16_235;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400875 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300876 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400877 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300878 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800879
Maarten Lankhorstac240282016-11-23 15:57:00 +0100880 if (crtc_state->pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300881 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700882 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300883 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700884
Maarten Lankhorstac240282016-11-23 15:57:00 +0100885 if (crtc_state->has_hdmi_sink)
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300886 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800887
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100888 if (HAS_PCH_CPT(dev_priv))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200889 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100890 else if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +0300891 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300892 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200893 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800894
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300895 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
896 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800897}
898
Daniel Vetter85234cd2012-07-02 13:27:29 +0200899static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
900 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800901{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200902 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100903 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200904 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
905 u32 tmp;
Imre Deak5b092172016-02-12 18:55:20 +0200906 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200907
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200908 if (!intel_display_power_get_if_enabled(dev_priv,
909 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200910 return false;
911
Imre Deak5b092172016-02-12 18:55:20 +0200912 ret = false;
913
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300914 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200915
916 if (!(tmp & SDVO_ENABLE))
Imre Deak5b092172016-02-12 18:55:20 +0200917 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200918
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100919 if (HAS_PCH_CPT(dev_priv))
Daniel Vetter85234cd2012-07-02 13:27:29 +0200920 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100921 else if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä71485e02014-04-09 13:28:55 +0300922 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200923 else
924 *pipe = PORT_TO_PIPE(tmp);
925
Imre Deak5b092172016-02-12 18:55:20 +0200926 ret = true;
927
928out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200929 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak5b092172016-02-12 18:55:20 +0200930
931 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200932}
933
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700934static void intel_hdmi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200935 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700936{
937 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300938 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100939 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700940 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300941 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700942
943 tmp = I915_READ(intel_hdmi->hdmi_reg);
944
945 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
946 flags |= DRM_MODE_FLAG_PHSYNC;
947 else
948 flags |= DRM_MODE_FLAG_NHSYNC;
949
950 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
951 flags |= DRM_MODE_FLAG_PVSYNC;
952 else
953 flags |= DRM_MODE_FLAG_NVSYNC;
954
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200955 if (tmp & HDMI_MODE_SELECT_HDMI)
956 pipe_config->has_hdmi_sink = true;
957
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200958 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Jesse Barnese43823e2014-11-05 14:26:08 -0800959 pipe_config->has_infoframe = true;
960
Jani Nikulac84db772014-09-17 15:34:58 +0300961 if (tmp & SDVO_AUDIO_ENABLE)
Daniel Vetter9ed109a2014-04-24 23:54:52 +0200962 pipe_config->has_audio = true;
963
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100964 if (!HAS_PCH_SPLIT(dev_priv) &&
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300965 tmp & HDMI_COLOR_RANGE_16_235)
966 pipe_config->limited_color_range = true;
967
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200968 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300969
970 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
971 dotclock = pipe_config->port_clock * 2 / 3;
972 else
973 dotclock = pipe_config->port_clock;
974
Ville Syrjäläbe69a132015-05-05 17:06:26 +0300975 if (pipe_config->pixel_multiplier)
976 dotclock /= pipe_config->pixel_multiplier;
977
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200978 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +0300979
980 pipe_config->lane_count = 4;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700981}
982
Maarten Lankhorstdf18e722016-11-08 13:55:37 +0100983static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
984 struct intel_crtc_state *pipe_config,
985 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300986{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100987 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300988
Maarten Lankhorstac240282016-11-23 15:57:00 +0100989 WARN_ON(!pipe_config->has_hdmi_sink);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300990 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
991 pipe_name(crtc->pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +0100992 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300993}
994
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200995static void g4x_enable_hdmi(struct intel_encoder *encoder,
996 struct intel_crtc_state *pipe_config,
997 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800998{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200999 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001000 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001001 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -08001002 u32 temp;
1003
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001004 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +00001005
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001006 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001007 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001008 temp |= SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001009
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001010 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1011 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001012
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001013 if (pipe_config->has_audio)
1014 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001015}
1016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001017static void ibx_enable_hdmi(struct intel_encoder *encoder,
1018 struct intel_crtc_state *pipe_config,
1019 struct drm_connector_state *conn_state)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001020{
1021 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001022 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001023 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1024 u32 temp;
1025
1026 temp = I915_READ(intel_hdmi->hdmi_reg);
1027
1028 temp |= SDVO_ENABLE;
Maarten Lankhorstac240282016-11-23 15:57:00 +01001029 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001030 temp |= SDVO_AUDIO_ENABLE;
1031
1032 /*
1033 * HW workaround, need to write this twice for issue
1034 * that may result in first write getting masked.
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001035 */
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001036 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1037 POSTING_READ(intel_hdmi->hdmi_reg);
1038 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1039 POSTING_READ(intel_hdmi->hdmi_reg);
1040
1041 /*
1042 * HW workaround, need to toggle enable bit off and on
1043 * for 12bpc with pixel repeat.
1044 *
1045 * FIXME: BSpec says this should be done at the end of
1046 * of the modeset sequence, so not sure if this isn't too soon.
1047 */
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001048 if (pipe_config->pipe_bpp > 24 &&
1049 pipe_config->pixel_multiplier > 1) {
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001050 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1051 POSTING_READ(intel_hdmi->hdmi_reg);
1052
1053 /*
1054 * HW workaround, need to write this twice for issue
1055 * that may result in first write getting masked.
1056 */
1057 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1058 POSTING_READ(intel_hdmi->hdmi_reg);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001059 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1060 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001061 }
Jani Nikulac1dec792014-10-27 16:26:56 +02001062
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001063 if (pipe_config->has_audio)
1064 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001065}
1066
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001067static void cpt_enable_hdmi(struct intel_encoder *encoder,
1068 struct intel_crtc_state *pipe_config,
1069 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001070{
1071 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001072 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001073 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001074 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1075 enum pipe pipe = crtc->pipe;
1076 u32 temp;
1077
1078 temp = I915_READ(intel_hdmi->hdmi_reg);
1079
1080 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001081 if (pipe_config->has_audio)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001082 temp |= SDVO_AUDIO_ENABLE;
1083
1084 /*
1085 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1086 *
1087 * The procedure for 12bpc is as follows:
1088 * 1. disable HDMI clock gating
1089 * 2. enable HDMI with 8bpc
1090 * 3. enable HDMI with 12bpc
1091 * 4. enable HDMI clock gating
1092 */
1093
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001094 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001095 I915_WRITE(TRANS_CHICKEN1(pipe),
1096 I915_READ(TRANS_CHICKEN1(pipe)) |
1097 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1098
1099 temp &= ~SDVO_COLOR_FORMAT_MASK;
1100 temp |= SDVO_COLOR_FORMAT_8bpc;
Jani Nikulac1dec792014-10-27 16:26:56 +02001101 }
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001102
1103 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1104 POSTING_READ(intel_hdmi->hdmi_reg);
1105
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001106 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001107 temp &= ~SDVO_COLOR_FORMAT_MASK;
1108 temp |= HDMI_COLOR_FORMAT_12bpc;
1109
1110 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1111 POSTING_READ(intel_hdmi->hdmi_reg);
1112
1113 I915_WRITE(TRANS_CHICKEN1(pipe),
1114 I915_READ(TRANS_CHICKEN1(pipe)) &
1115 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1116 }
1117
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001118 if (pipe_config->has_audio)
1119 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001120}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001121
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001122static void vlv_enable_hdmi(struct intel_encoder *encoder,
1123 struct intel_crtc_state *pipe_config,
1124 struct drm_connector_state *conn_state)
Jani Nikulab76cf762013-07-30 12:20:31 +03001125{
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001126}
1127
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001128static void intel_disable_hdmi(struct intel_encoder *encoder,
1129 struct intel_crtc_state *old_crtc_state,
1130 struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001131{
1132 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001133 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001134 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001135 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001136 u32 temp;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001137
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001138 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001139
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001140 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001141 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1142 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001143
1144 /*
1145 * HW workaround for IBX, we need to move the port
1146 * to transcoder A after disabling it to allow the
1147 * matching DP port to be enabled on transcoder A.
1148 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001149 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001150 /*
1151 * We get CPU/PCH FIFO underruns on the other pipe when
1152 * doing the workaround. Sweep them under the rug.
1153 */
1154 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1155 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1156
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001157 temp &= ~SDVO_PIPE_B_SELECT;
1158 temp |= SDVO_ENABLE;
1159 /*
1160 * HW workaround, need to write this twice for issue
1161 * that may result in first write getting masked.
1162 */
1163 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1164 POSTING_READ(intel_hdmi->hdmi_reg);
1165 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1166 POSTING_READ(intel_hdmi->hdmi_reg);
1167
1168 temp &= ~SDVO_ENABLE;
1169 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1170 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001171
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02001172 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001173 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1174 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001175 }
Ville Syrjälä6d674152015-05-05 17:06:20 +03001176
Maarten Lankhorstac240282016-11-23 15:57:00 +01001177 intel_hdmi->set_infoframes(&encoder->base, false, old_crtc_state, old_conn_state);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03001178
1179 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
Eric Anholt7d573822009-01-02 13:33:00 -08001180}
1181
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001182static void g4x_disable_hdmi(struct intel_encoder *encoder,
1183 struct intel_crtc_state *old_crtc_state,
1184 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001185{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001186 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001187 intel_audio_codec_disable(encoder);
1188
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001189 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001190}
1191
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001192static void pch_disable_hdmi(struct intel_encoder *encoder,
1193 struct intel_crtc_state *old_crtc_state,
1194 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001195{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001196 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001197 intel_audio_codec_disable(encoder);
1198}
1199
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001200static void pch_post_disable_hdmi(struct intel_encoder *encoder,
1201 struct intel_crtc_state *old_crtc_state,
1202 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001203{
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001204 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001205}
1206
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001207static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001208{
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001209 if (IS_G4X(dev_priv))
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001210 return 165000;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001211 else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001212 return 300000;
1213 else
1214 return 225000;
1215}
1216
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001217static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
1218 bool respect_downstream_limits)
1219{
1220 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1221 int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
1222
1223 if (respect_downstream_limits) {
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001224 struct intel_connector *connector = hdmi->attached_connector;
1225 const struct drm_display_info *info = &connector->base.display_info;
1226
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001227 if (hdmi->dp_dual_mode.max_tmds_clock)
1228 max_tmds_clock = min(max_tmds_clock,
1229 hdmi->dp_dual_mode.max_tmds_clock);
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001230
1231 if (info->max_tmds_clock)
1232 max_tmds_clock = min(max_tmds_clock,
1233 info->max_tmds_clock);
1234 else if (!hdmi->has_hdmi_sink)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001235 max_tmds_clock = min(max_tmds_clock, 165000);
1236 }
1237
1238 return max_tmds_clock;
1239}
1240
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001241static enum drm_mode_status
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001242hdmi_port_clock_valid(struct intel_hdmi *hdmi,
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001243 int clock, bool respect_downstream_limits)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001244{
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001245 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001246
1247 if (clock < 25000)
1248 return MODE_CLOCK_LOW;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001249 if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001250 return MODE_CLOCK_HIGH;
1251
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001252 /* BXT DPLL can't generate 223-240 MHz */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001253 if (IS_GEN9_LP(dev_priv) && clock > 223333 && clock < 240000)
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001254 return MODE_CLOCK_RANGE;
1255
1256 /* CHV DPLL can't generate 216-240 MHz */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001257 if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001258 return MODE_CLOCK_RANGE;
1259
1260 return MODE_OK;
1261}
1262
1263static enum drm_mode_status
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001264intel_hdmi_mode_valid(struct drm_connector *connector,
1265 struct drm_display_mode *mode)
Eric Anholt7d573822009-01-02 13:33:00 -08001266{
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001267 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1268 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001269 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001270 enum drm_mode_status status;
1271 int clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001272 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Eric Anholt7d573822009-01-02 13:33:00 -08001273
1274 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1275 return MODE_NO_DBLESCAN;
1276
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001277 clock = mode->clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001278
1279 if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
1280 clock *= 2;
1281
1282 if (clock > max_dotclk)
1283 return MODE_CLOCK_HIGH;
1284
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001285 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1286 clock *= 2;
1287
1288 /* check if we can do 8bpc */
1289 status = hdmi_port_clock_valid(hdmi, clock, true);
1290
1291 /* if we can't do 8bpc we may still be able to do 12bpc */
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001292 if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001293 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
1294
1295 return status;
Eric Anholt7d573822009-01-02 13:33:00 -08001296}
1297
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001298static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
Ville Syrjälä71800632014-03-03 16:15:29 +02001299{
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001300 struct drm_i915_private *dev_priv =
1301 to_i915(crtc_state->base.crtc->dev);
1302 struct drm_atomic_state *state = crtc_state->base.state;
1303 struct drm_connector_state *connector_state;
1304 struct drm_connector *connector;
1305 int i;
Ville Syrjälä71800632014-03-03 16:15:29 +02001306
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001307 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä71800632014-03-03 16:15:29 +02001308 return false;
1309
Ville Syrjälä71800632014-03-03 16:15:29 +02001310 /*
1311 * HDMI 12bpc affects the clocks, so it's only possible
1312 * when not cloning with other encoder types.
1313 */
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001314 if (crtc_state->output_types != 1 << INTEL_OUTPUT_HDMI)
1315 return false;
1316
1317 for_each_connector_in_state(state, connector, connector_state, i) {
1318 const struct drm_display_info *info = &connector->display_info;
1319
1320 if (connector_state->crtc != crtc_state->base.crtc)
1321 continue;
1322
1323 if ((info->edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_36) == 0)
1324 return false;
1325 }
1326
1327 return true;
Ville Syrjälä71800632014-03-03 16:15:29 +02001328}
1329
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001330bool intel_hdmi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001331 struct intel_crtc_state *pipe_config,
1332 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -08001333{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001334 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001335 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001336 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001337 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1338 int clock_12bpc = clock_8bpc * 3 / 2;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001339 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001340
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001341 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1342
Jesse Barnese43823e2014-11-05 14:26:08 -08001343 if (pipe_config->has_hdmi_sink)
1344 pipe_config->has_infoframe = true;
1345
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001346 if (intel_hdmi->color_range_auto) {
1347 /* See CEA-861-E - 5.1 Default Encoding Parameters */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001348 pipe_config->limited_color_range =
1349 pipe_config->has_hdmi_sink &&
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001350 drm_default_rgb_quant_range(adjusted_mode) ==
1351 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001352 } else {
1353 pipe_config->limited_color_range =
1354 intel_hdmi->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001355 }
1356
Clint Taylor697c4072014-09-02 17:03:36 -07001357 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1358 pipe_config->pixel_multiplier = 2;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001359 clock_8bpc *= 2;
Ville Syrjälä3320e372015-05-05 17:06:27 +03001360 clock_12bpc *= 2;
Clint Taylor697c4072014-09-02 17:03:36 -07001361 }
1362
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001363 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001364 pipe_config->has_pch_encoder = true;
1365
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001366 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1367 pipe_config->has_audio = true;
1368
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001369 /*
1370 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1371 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +02001372 * outputs. We also need to check that the higher clock still fits
1373 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001374 */
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001375 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001376 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
Ville Syrjälä7a0baa62015-06-30 15:33:54 +03001377 hdmi_12bpc_possible(pipe_config)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001378 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1379 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +02001380
1381 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +02001382 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001383 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001384 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1385 desired_bpp = 8*3;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001386
1387 pipe_config->port_clock = clock_8bpc;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001388 }
1389
1390 if (!pipe_config->bw_constrained) {
1391 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1392 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001393 }
1394
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001395 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1396 false) != MODE_OK) {
1397 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
Daniel Vetter325b9d02013-04-19 11:24:33 +02001398 return false;
1399 }
1400
Ville Syrjälä28b468a2015-09-08 13:40:48 +03001401 /* Set user selected PAR to incoming mode's member */
1402 adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
1403
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03001404 pipe_config->lane_count = 4;
1405
Eric Anholt7d573822009-01-02 13:33:00 -08001406 return true;
1407}
1408
Chris Wilson953ece6972014-09-02 20:04:01 +01001409static void
1410intel_hdmi_unset_edid(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001411{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001412 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02001413
Chris Wilsonea5b2132010-08-04 13:50:23 +01001414 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +08001415 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +02001416 intel_hdmi->rgb_quant_range_selectable = false;
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +08001417
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001418 intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
1419 intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
1420
Chris Wilson953ece6972014-09-02 20:04:01 +01001421 kfree(to_intel_connector(connector)->detect_edid);
1422 to_intel_connector(connector)->detect_edid = NULL;
Ma Ling9dff6af2009-04-02 13:13:26 +08001423}
1424
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001425static void
Ville Syrjäläd6199252016-05-04 14:45:22 +03001426intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001427{
1428 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1429 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
Ville Syrjäläd6199252016-05-04 14:45:22 +03001430 enum port port = hdmi_to_dig_port(hdmi)->port;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001431 struct i2c_adapter *adapter =
1432 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
1433 enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
1434
Ville Syrjäläd6199252016-05-04 14:45:22 +03001435 /*
1436 * Type 1 DVI adaptors are not required to implement any
1437 * registers, so we can't always detect their presence.
1438 * Ideally we should be able to check the state of the
1439 * CONFIG1 pin, but no such luck on our hardware.
1440 *
1441 * The only method left to us is to check the VBT to see
1442 * if the port is a dual mode capable DP port. But let's
1443 * only do that when we sucesfully read the EDID, to avoid
1444 * confusing log messages about DP dual mode adaptors when
1445 * there's nothing connected to the port.
1446 */
1447 if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
1448 if (has_edid &&
1449 intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
1450 DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
1451 type = DRM_DP_DUAL_MODE_TYPE1_DVI;
1452 } else {
1453 type = DRM_DP_DUAL_MODE_NONE;
1454 }
1455 }
1456
1457 if (type == DRM_DP_DUAL_MODE_NONE)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001458 return;
1459
1460 hdmi->dp_dual_mode.type = type;
1461 hdmi->dp_dual_mode.max_tmds_clock =
1462 drm_dp_dual_mode_max_tmds_clock(type, adapter);
1463
1464 DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
1465 drm_dp_get_dual_mode_type_name(type),
1466 hdmi->dp_dual_mode.max_tmds_clock);
1467}
1468
Chris Wilson953ece6972014-09-02 20:04:01 +01001469static bool
David Weinehall23f889b2016-08-17 15:47:48 +03001470intel_hdmi_set_edid(struct drm_connector *connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001471{
Chris Wilson953ece6972014-09-02 20:04:01 +01001472 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1473 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
David Weinehall23f889b2016-08-17 15:47:48 +03001474 struct edid *edid;
Chris Wilson953ece6972014-09-02 20:04:01 +01001475 bool connected = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001476
David Weinehall23f889b2016-08-17 15:47:48 +03001477 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001478
David Weinehall23f889b2016-08-17 15:47:48 +03001479 edid = drm_get_edid(connector,
1480 intel_gmbus_get_adapter(dev_priv,
1481 intel_hdmi->ddc_bus));
Imre Deak671dedd2014-03-05 16:20:53 +02001482
David Weinehall23f889b2016-08-17 15:47:48 +03001483 intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001484
David Weinehall23f889b2016-08-17 15:47:48 +03001485 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001486
Chris Wilson953ece6972014-09-02 20:04:01 +01001487 to_intel_connector(connector)->detect_edid = edid;
1488 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1489 intel_hdmi->rgb_quant_range_selectable =
1490 drm_rgb_quant_range_selectable(edid);
1491
1492 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1493 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1494 intel_hdmi->has_audio =
1495 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1496
1497 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1498 intel_hdmi->has_hdmi_sink =
1499 drm_detect_hdmi_monitor(edid);
1500
1501 connected = true;
1502 }
1503
1504 return connected;
1505}
1506
Daniel Vetter8166fce2015-10-08 21:50:57 +02001507static enum drm_connector_status
1508intel_hdmi_detect(struct drm_connector *connector, bool force)
Chris Wilson953ece6972014-09-02 20:04:01 +01001509{
Daniel Vetter8166fce2015-10-08 21:50:57 +02001510 enum drm_connector_status status;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001511 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson953ece6972014-09-02 20:04:01 +01001512
Daniel Vetter8166fce2015-10-08 21:50:57 +02001513 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1514 connector->base.id, connector->name);
1515
Imre Deak29bb94b2015-11-19 20:55:01 +02001516 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1517
Daniel Vetter8166fce2015-10-08 21:50:57 +02001518 intel_hdmi_unset_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001519
David Weinehall23f889b2016-08-17 15:47:48 +03001520 if (intel_hdmi_set_edid(connector)) {
Chris Wilson953ece6972014-09-02 20:04:01 +01001521 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1522
1523 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1524 status = connector_status_connected;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001525 } else
Chris Wilson953ece6972014-09-02 20:04:01 +01001526 status = connector_status_disconnected;
1527
Imre Deak29bb94b2015-11-19 20:55:01 +02001528 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1529
Chris Wilson953ece6972014-09-02 20:04:01 +01001530 return status;
1531}
1532
1533static void
1534intel_hdmi_force(struct drm_connector *connector)
1535{
1536 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1537
1538 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1539 connector->base.id, connector->name);
1540
1541 intel_hdmi_unset_edid(connector);
1542
1543 if (connector->status != connector_status_connected)
1544 return;
1545
David Weinehall23f889b2016-08-17 15:47:48 +03001546 intel_hdmi_set_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001547 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1548}
1549
1550static int intel_hdmi_get_modes(struct drm_connector *connector)
1551{
1552 struct edid *edid;
1553
1554 edid = to_intel_connector(connector)->detect_edid;
1555 if (edid == NULL)
1556 return 0;
1557
1558 return intel_connector_update_modes(connector, edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001559}
1560
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001561static bool
1562intel_hdmi_detect_audio(struct drm_connector *connector)
1563{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001564 bool has_audio = false;
Chris Wilson953ece6972014-09-02 20:04:01 +01001565 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001566
Chris Wilson953ece6972014-09-02 20:04:01 +01001567 edid = to_intel_connector(connector)->detect_edid;
1568 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1569 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02001570
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001571 return has_audio;
1572}
1573
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001574static int
1575intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001576 struct drm_property *property,
1577 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001578{
1579 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001580 struct intel_digital_port *intel_dig_port =
1581 hdmi_to_dig_port(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001582 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001583 int ret;
1584
Rob Clark662595d2012-10-11 20:36:04 -05001585 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001586 if (ret)
1587 return ret;
1588
Chris Wilson3f43c482011-05-12 22:17:24 +01001589 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001590 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001591 bool has_audio;
1592
1593 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001594 return 0;
1595
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001596 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001597
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001598 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001599 has_audio = intel_hdmi_detect_audio(connector);
1600 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001601 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001602
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001603 if (i == HDMI_AUDIO_OFF_DVI)
1604 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001605
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001606 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001607 goto done;
1608 }
1609
Chris Wilsone953fd72011-02-21 22:23:52 +00001610 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001611 bool old_auto = intel_hdmi->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001612 bool old_range = intel_hdmi->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02001613
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001614 switch (val) {
1615 case INTEL_BROADCAST_RGB_AUTO:
1616 intel_hdmi->color_range_auto = true;
1617 break;
1618 case INTEL_BROADCAST_RGB_FULL:
1619 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001620 intel_hdmi->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001621 break;
1622 case INTEL_BROADCAST_RGB_LIMITED:
1623 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001624 intel_hdmi->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001625 break;
1626 default:
1627 return -EINVAL;
1628 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001629
1630 if (old_auto == intel_hdmi->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001631 old_range == intel_hdmi->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02001632 return 0;
1633
Chris Wilsone953fd72011-02-21 22:23:52 +00001634 goto done;
1635 }
1636
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301637 if (property == connector->dev->mode_config.aspect_ratio_property) {
1638 switch (val) {
1639 case DRM_MODE_PICTURE_ASPECT_NONE:
1640 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1641 break;
1642 case DRM_MODE_PICTURE_ASPECT_4_3:
1643 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
1644 break;
1645 case DRM_MODE_PICTURE_ASPECT_16_9:
1646 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
1647 break;
1648 default:
1649 return -EINVAL;
1650 }
1651 goto done;
1652 }
1653
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001654 return -EINVAL;
1655
1656done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001657 if (intel_dig_port->base.base.crtc)
1658 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001659
1660 return 0;
1661}
1662
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001663static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
1664 struct intel_crtc_state *pipe_config,
1665 struct drm_connector_state *conn_state)
Jesse Barnes13732ba2014-04-05 11:51:35 -07001666{
1667 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001668
Maarten Lankhorstac240282016-11-23 15:57:00 +01001669 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001670
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001671 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001672 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001673 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001674}
1675
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001676static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
1677 struct intel_crtc_state *pipe_config,
1678 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001679{
1680 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001681 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001682 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001683 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001684
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03001685 vlv_phy_pre_encoder_enable(encoder);
Jani Nikulab76cf762013-07-30 12:20:31 +03001686
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03001687 /* HDMI 1.0V-2dB */
1688 vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
1689 0x2b247878);
1690
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001691 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001692 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001693 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001694
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001695 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001696
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001697 vlv_wait_port_ready(dev_priv, dport, 0x0);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001698}
1699
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001700static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1701 struct intel_crtc_state *pipe_config,
1702 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001703{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001704 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001705
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03001706 vlv_phy_pre_pll_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001707}
1708
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001709static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1710 struct intel_crtc_state *pipe_config,
1711 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03001712{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001713 intel_hdmi_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03001714
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03001715 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03001716}
1717
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001718static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
1719 struct intel_crtc_state *old_crtc_state,
1720 struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001721{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03001722 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001723}
1724
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001725static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
1726 struct intel_crtc_state *old_crtc_state,
1727 struct drm_connector_state *old_conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001728{
Jesse Barnes89b667f2013-04-18 14:51:36 -07001729 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
Ander Conselvan de Oliveira0f572eb2016-04-27 15:44:25 +03001730 vlv_phy_reset_lanes(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001731}
1732
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001733static void chv_hdmi_post_disable(struct intel_encoder *encoder,
1734 struct intel_crtc_state *old_crtc_state,
1735 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03001736{
Ville Syrjälä580d3812014-04-09 13:29:00 +03001737 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001738 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001739
Ville Syrjäläa5805162015-05-26 20:42:30 +03001740 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001741
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001742 /* Assert data lane reset */
1743 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001744
Ville Syrjäläa5805162015-05-26 20:42:30 +03001745 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001746}
1747
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001748static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
1749 struct intel_crtc_state *pipe_config,
1750 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001751{
1752 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001753 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001754 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001755 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001756
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001757 chv_phy_pre_encoder_enable(encoder);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001758
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001759 /* FIXME: Program the support xxx V-dB */
1760 /* Use 800mV-0dB */
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03001761 chv_set_phy_signal_level(encoder, 128, 102, false);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001762
Clint Taylorb4eb1562014-11-21 11:13:02 -08001763 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001764 pipe_config->has_hdmi_sink,
1765 pipe_config, conn_state);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001766
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001767 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001768
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001769 vlv_wait_port_ready(dev_priv, dport, 0x0);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001770
1771 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001772 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001773}
1774
Eric Anholt7d573822009-01-02 13:33:00 -08001775static void intel_hdmi_destroy(struct drm_connector *connector)
1776{
Chris Wilson10e972d2014-09-04 21:43:45 +01001777 kfree(to_intel_connector(connector)->detect_edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001778 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001779 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001780}
1781
Eric Anholt7d573822009-01-02 13:33:00 -08001782static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001783 .dpms = drm_atomic_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001784 .detect = intel_hdmi_detect,
Chris Wilson953ece6972014-09-02 20:04:01 +01001785 .force = intel_hdmi_force,
Eric Anholt7d573822009-01-02 13:33:00 -08001786 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001787 .set_property = intel_hdmi_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08001788 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01001789 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01001790 .early_unregister = intel_connector_unregister,
Eric Anholt7d573822009-01-02 13:33:00 -08001791 .destroy = intel_hdmi_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08001792 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001793 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Eric Anholt7d573822009-01-02 13:33:00 -08001794};
1795
1796static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1797 .get_modes = intel_hdmi_get_modes,
1798 .mode_valid = intel_hdmi_mode_valid,
Eric Anholt7d573822009-01-02 13:33:00 -08001799};
1800
Eric Anholt7d573822009-01-02 13:33:00 -08001801static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001802 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001803};
1804
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001805static void
1806intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1807{
Chris Wilson3f43c482011-05-12 22:17:24 +01001808 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001809 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001810 intel_hdmi->color_range_auto = true;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301811 intel_attach_aspect_ratio_property(connector);
1812 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001813}
1814
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001815static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1816 enum port port)
1817{
1818 const struct ddi_vbt_port_info *info =
1819 &dev_priv->vbt.ddi_port_info[port];
1820 u8 ddc_pin;
1821
1822 if (info->alternate_ddc_pin) {
1823 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1824 info->alternate_ddc_pin, port_name(port));
1825 return info->alternate_ddc_pin;
1826 }
1827
1828 switch (port) {
1829 case PORT_B:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001830 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001831 ddc_pin = GMBUS_PIN_1_BXT;
1832 else
1833 ddc_pin = GMBUS_PIN_DPB;
1834 break;
1835 case PORT_C:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001836 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001837 ddc_pin = GMBUS_PIN_2_BXT;
1838 else
1839 ddc_pin = GMBUS_PIN_DPC;
1840 break;
1841 case PORT_D:
1842 if (IS_CHERRYVIEW(dev_priv))
1843 ddc_pin = GMBUS_PIN_DPD_CHV;
1844 else
1845 ddc_pin = GMBUS_PIN_DPD;
1846 break;
1847 default:
1848 MISSING_CASE(port);
1849 ddc_pin = GMBUS_PIN_DPB;
1850 break;
1851 }
1852
1853 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1854 ddc_pin, port_name(port));
1855
1856 return ddc_pin;
1857}
1858
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001859void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1860 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001861{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001862 struct drm_connector *connector = &intel_connector->base;
1863 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1864 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1865 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001866 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02001867 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001868
Ville Syrjälä22f350422016-06-03 12:17:43 +03001869 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
1870 port_name(port));
1871
Ville Syrjäläccb1a832015-12-08 19:59:38 +02001872 if (WARN(intel_dig_port->max_lanes < 4,
1873 "Not enough lanes (%d) for HDMI on port %c\n",
1874 intel_dig_port->max_lanes, port_name(port)))
1875 return;
1876
Eric Anholt7d573822009-01-02 13:33:00 -08001877 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001878 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001879 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1880
Peter Rossc3febcc2012-01-28 14:49:26 +01001881 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001882 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01001883 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001884
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001885 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
1886
Daniel Vetter08d644a2012-07-12 20:19:59 +02001887 switch (port) {
1888 case PORT_B:
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02001889 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001890 break;
1891 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05001892 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001893 break;
1894 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05001895 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001896 break;
Xiong Zhang11c1b652015-08-17 16:04:04 +08001897 case PORT_E:
Xiong Zhang11c1b652015-08-17 16:04:04 +08001898 intel_encoder->hpd_pin = HPD_PORT_E;
1899 break;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001900 default:
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001901 MISSING_CASE(port);
1902 return;
Ma Lingf8aed702009-08-24 13:50:24 +08001903 }
Eric Anholt7d573822009-01-02 13:33:00 -08001904
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001905 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001906 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001907 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001908 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001909 } else if (IS_G4X(dev_priv)) {
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001910 intel_hdmi->write_infoframe = g4x_write_infoframe;
1911 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001912 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001913 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001914 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001915 intel_hdmi->set_infoframes = hsw_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001916 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001917 } else if (HAS_PCH_IBX(dev_priv)) {
Paulo Zanonifdf12502012-05-04 17:18:24 -03001918 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001919 intel_hdmi->set_infoframes = ibx_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001920 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001921 } else {
1922 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001923 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001924 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301925 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001926
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001927 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001928 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1929 else
1930 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001931
1932 intel_hdmi_add_properties(intel_hdmi, connector);
1933
1934 intel_connector_attach_encoder(intel_connector, intel_encoder);
Shashank Sharmad8b4c432015-09-04 18:56:11 +05301935 intel_hdmi->attached_connector = intel_connector;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001936
1937 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1938 * 0xd. Failure to do so will result in spurious interrupts being
1939 * generated on the port when a cable is not attached.
1940 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001941 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001942 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1943 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1944 }
1945}
1946
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001947void intel_hdmi_init(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001948 i915_reg_t hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001949{
1950 struct intel_digital_port *intel_dig_port;
1951 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001952 struct intel_connector *intel_connector;
1953
Daniel Vetterb14c5672013-09-19 12:18:32 +02001954 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001955 if (!intel_dig_port)
1956 return;
1957
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03001958 intel_connector = intel_connector_alloc();
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001959 if (!intel_connector) {
1960 kfree(intel_dig_port);
1961 return;
1962 }
1963
1964 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001965
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001966 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
1967 &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS,
1968 "HDMI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001969
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001970 intel_encoder->compute_config = intel_hdmi_compute_config;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001971 if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001972 intel_encoder->disable = pch_disable_hdmi;
1973 intel_encoder->post_disable = pch_post_disable_hdmi;
1974 } else {
1975 intel_encoder->disable = g4x_disable_hdmi;
1976 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001977 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001978 intel_encoder->get_config = intel_hdmi_get_config;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001979 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03001980 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001981 intel_encoder->pre_enable = chv_hdmi_pre_enable;
1982 intel_encoder->enable = vlv_enable_hdmi;
Ville Syrjälä580d3812014-04-09 13:29:00 +03001983 intel_encoder->post_disable = chv_hdmi_post_disable;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001984 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001985 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001986 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
1987 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001988 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001989 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001990 } else {
Jesse Barnes13732ba2014-04-05 11:51:35 -07001991 intel_encoder->pre_enable = intel_hdmi_pre_enable;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001992 if (HAS_PCH_CPT(dev_priv))
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001993 intel_encoder->enable = cpt_enable_hdmi;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001994 else if (HAS_PCH_IBX(dev_priv))
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001995 intel_encoder->enable = ibx_enable_hdmi;
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001996 else
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001997 intel_encoder->enable = g4x_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001998 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001999
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002000 intel_encoder->type = INTEL_OUTPUT_HDMI;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002001 intel_encoder->power_domain = intel_port_to_power_domain(port);
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002002 intel_encoder->port = port;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002003 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03002004 if (port == PORT_D)
2005 intel_encoder->crtc_mask = 1 << 2;
2006 else
2007 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2008 } else {
2009 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2010 }
Ville Syrjälä301ea742014-03-03 16:15:30 +02002011 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
Ville Syrjäläc6f14952014-03-03 16:15:31 +02002012 /*
2013 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
2014 * to work on real hardware. And since g4x can send infoframes to
2015 * only one port anyway, nothing is lost by allowing it.
2016 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01002017 if (IS_G4X(dev_priv))
Ville Syrjäläc6f14952014-03-03 16:15:31 +02002018 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -08002019
Paulo Zanoni174edf12012-10-26 19:05:50 -02002020 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03002021 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002022 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02002023 intel_dig_port->max_lanes = 4;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002024
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002025 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08002026}